@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
@@ -1 +1 @@
1
- {"version":3,"file":"richText.cjs","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\"\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\"\nimport type { EmbedField } from \"./embed\"\nimport type { FilledLinkToWebField } from \"./link\"\nimport type { FilledLinkToMediaField } from \"./linkToMedia\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes =\n\t(typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/**\n * Base to be extended by other rich text nodes.\n */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/**\n * Rich text `heading1` node\n */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/**\n * Rich text `heading2` node\n */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/**\n * Rich text `heading3` node\n */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/**\n * Rich text `heading4` node\n */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/**\n * Rich text `heading5` node\n */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/**\n * Rich text `heading6` node\n */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/**\n * Rich text `paragraph` node\n */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/**\n * Rich text `preformatted` node\n */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/**\n * Rich text `list-item` node\n */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n}\n\n/**\n * Rich text `o-list-item` node for ordered lists\n */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n}\n\n// Span nodes\n\n/**\n * @internal Span Node base to be extended for other Span nodes\n */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/**\n * Rich text `strong` node\n */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/**\n * Rich text `embed` node\n */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/**\n * Rich text `label` node\n */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/**\n * Rich text `image` nodes. They could link to other documents, external web\n * links and media fields\n */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField\n}\n\n/**\n * Rich text `embed` node\n */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField\n}\n\n// Serialization related nodes\n\n/**\n * Rich text `list` node\n */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/**\n * Rich text o-lost node\n */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/**\n * Rich text `span` node\n */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/**\n * Nodes from a rich text field\n */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Rich text nodes with text\n */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/**\n * Rich text block nodes\n */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Inline rich text nodes\n */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/**\n * All rich text nodes\n */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> =\n\tState extends \"empty\" ? [] : [RTNode, ...RTNode[]]\n"],"names":[],"mappings":";;AAYO,MAAM,mBAAmB;AAAA,EAC/B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,WAAW;AAAA,EACX,OAAO;AAAA,EACP,MAAM;;;"}
1
+ {"version":3,"file":"richText.cjs","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\"\n\nimport type { EmbedField } from \"./embed\"\nimport type { FilledLinkField } from \"./link\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes =\n\t(typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/**\n * Base to be extended by other rich text nodes.\n */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/**\n * Rich text `heading1` node\n */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/**\n * Rich text `heading2` node\n */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/**\n * Rich text `heading3` node\n */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/**\n * Rich text `heading4` node\n */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/**\n * Rich text `heading5` node\n */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/**\n * Rich text `heading6` node\n */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/**\n * Rich text `paragraph` node\n */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/**\n * Rich text `preformatted` node\n */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/**\n * Rich text `list-item` node\n */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n}\n\n/**\n * Rich text `o-list-item` node for ordered lists\n */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n}\n\n// Span nodes\n\n/**\n * @internal Span Node base to be extended for other Span nodes\n */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/**\n * Rich text `strong` node\n */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/**\n * Rich text `embed` node\n */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/**\n * Rich text `label` node\n */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/**\n * Rich text `image` nodes. They could link to other documents, external web\n * links and media fields\n */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?: FilledLinkField\n}\n\n/**\n * Rich text `embed` node\n */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata: FilledLinkField\n}\n\n// Serialization related nodes\n\n/**\n * Rich text `list` node\n */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/**\n * Rich text o-lost node\n */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/**\n * Rich text `span` node\n */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/**\n * Nodes from a rich text field\n */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Rich text nodes with text\n */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/**\n * Rich text block nodes\n */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Inline rich text nodes\n */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/**\n * All rich text nodes\n */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> =\n\tState extends \"empty\" ? [] : [RTNode, ...RTNode[]]\n"],"names":[],"mappings":";;AAUO,MAAM,mBAAmB;AAAA,EAC/B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,WAAW;AAAA,EACX,OAAO;AAAA,EACP,MAAM;;;"}
@@ -1,8 +1,6 @@
1
1
  import type { FieldState } from "./types";
2
- import type { FilledContentRelationshipField } from "./contentRelationship";
3
2
  import type { EmbedField } from "./embed";
4
- import type { FilledLinkToWebField } from "./link";
5
- import type { FilledLinkToMediaField } from "./linkToMedia";
3
+ import type { FilledLinkField } from "./link";
6
4
  /**
7
5
  * Types enum for RichTextNodes
8
6
  *
@@ -151,7 +149,7 @@ export type RTImageNode = {
151
149
  zoom: number;
152
150
  background: string;
153
151
  };
154
- linkTo?: FilledContentRelationshipField | FilledLinkToWebField | FilledLinkToMediaField;
152
+ linkTo?: FilledLinkField;
155
153
  };
156
154
  /**
157
155
  * Rich text `embed` node
@@ -167,7 +165,7 @@ export type RTEmbedNode = {
167
165
  */
168
166
  export interface RTLinkNode extends RTSpanNodeBase {
169
167
  type: typeof RichTextNodeType.hyperlink;
170
- data: FilledContentRelationshipField | FilledLinkToWebField | FilledLinkToMediaField;
168
+ data: FilledLinkField;
171
169
  }
172
170
  /**
173
171
  * Rich text `list` node
@@ -1 +1 @@
1
- {"version":3,"file":"richText.js","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\"\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\"\nimport type { EmbedField } from \"./embed\"\nimport type { FilledLinkToWebField } from \"./link\"\nimport type { FilledLinkToMediaField } from \"./linkToMedia\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes =\n\t(typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/**\n * Base to be extended by other rich text nodes.\n */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/**\n * Rich text `heading1` node\n */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/**\n * Rich text `heading2` node\n */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/**\n * Rich text `heading3` node\n */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/**\n * Rich text `heading4` node\n */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/**\n * Rich text `heading5` node\n */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/**\n * Rich text `heading6` node\n */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/**\n * Rich text `paragraph` node\n */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/**\n * Rich text `preformatted` node\n */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/**\n * Rich text `list-item` node\n */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n}\n\n/**\n * Rich text `o-list-item` node for ordered lists\n */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n}\n\n// Span nodes\n\n/**\n * @internal Span Node base to be extended for other Span nodes\n */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/**\n * Rich text `strong` node\n */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/**\n * Rich text `embed` node\n */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/**\n * Rich text `label` node\n */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/**\n * Rich text `image` nodes. They could link to other documents, external web\n * links and media fields\n */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField\n}\n\n/**\n * Rich text `embed` node\n */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField\n}\n\n// Serialization related nodes\n\n/**\n * Rich text `list` node\n */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/**\n * Rich text o-lost node\n */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/**\n * Rich text `span` node\n */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/**\n * Nodes from a rich text field\n */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Rich text nodes with text\n */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/**\n * Rich text block nodes\n */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Inline rich text nodes\n */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/**\n * All rich text nodes\n */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> =\n\tState extends \"empty\" ? [] : [RTNode, ...RTNode[]]\n"],"names":[],"mappings":"AAYO,MAAM,mBAAmB;AAAA,EAC/B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,WAAW;AAAA,EACX,OAAO;AAAA,EACP,MAAM;;"}
1
+ {"version":3,"file":"richText.js","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\"\n\nimport type { EmbedField } from \"./embed\"\nimport type { FilledLinkField } from \"./link\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes =\n\t(typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/**\n * Base to be extended by other rich text nodes.\n */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/**\n * Rich text `heading1` node\n */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/**\n * Rich text `heading2` node\n */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/**\n * Rich text `heading3` node\n */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/**\n * Rich text `heading4` node\n */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/**\n * Rich text `heading5` node\n */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/**\n * Rich text `heading6` node\n */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/**\n * Rich text `paragraph` node\n */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/**\n * Rich text `preformatted` node\n */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/**\n * Rich text `list-item` node\n */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n}\n\n/**\n * Rich text `o-list-item` node for ordered lists\n */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n}\n\n// Span nodes\n\n/**\n * @internal Span Node base to be extended for other Span nodes\n */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/**\n * Rich text `strong` node\n */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/**\n * Rich text `embed` node\n */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/**\n * Rich text `label` node\n */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/**\n * Rich text `image` nodes. They could link to other documents, external web\n * links and media fields\n */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?: FilledLinkField\n}\n\n/**\n * Rich text `embed` node\n */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata: FilledLinkField\n}\n\n// Serialization related nodes\n\n/**\n * Rich text `list` node\n */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/**\n * Rich text o-lost node\n */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/**\n * Rich text `span` node\n */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/**\n * Nodes from a rich text field\n */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Rich text nodes with text\n */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/**\n * Rich text block nodes\n */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Inline rich text nodes\n */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/**\n * All rich text nodes\n */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> =\n\tState extends \"empty\" ? [] : [RTNode, ...RTNode[]]\n"],"names":[],"mappings":"AAUO,MAAM,mBAAmB;AAAA,EAC/B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,WAAW;AAAA,EACX,OAAO;AAAA,EACP,MAAM;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/client",
3
- "version": "7.14.0-alpha.1",
3
+ "version": "7.14.0-alpha.2",
4
4
  "description": "The official JavaScript + TypeScript client library for Prismic",
5
5
  "keywords": [
6
6
  "typescript",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@prismicio/mock": "^0.3.9",
86
- "@prismicio/types-internal": "3.3.0-alpha.2",
86
+ "@prismicio/types-internal": "3.1.0",
87
87
  "@size-limit/preset-small-lib": "^11.1.6",
88
88
  "@trivago/prettier-plugin-sort-imports": "^4.3.0",
89
89
  "@typescript-eslint/eslint-plugin": "^6.21.0",
package/src/Migration.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as is from "./lib/isValue"
2
+ import { getOptionalLinkProperties } from "./lib/getOptionalLinkProperties"
2
3
  import { validateAssetMetadata } from "./lib/validateAssetMetadata"
3
4
 
4
5
  import type { Asset } from "./types/api/asset/asset"
@@ -404,28 +405,32 @@ export class Migration<TDocuments extends PrismicDocument = PrismicDocument> {
404
405
  */
405
406
  #migratePrismicDocumentData(input: unknown): unknown {
406
407
  if (is.filledContentRelationship(input)) {
408
+ const optionalLinkProperties = getOptionalLinkProperties(input)
409
+
407
410
  if (input.isBroken) {
408
411
  return {
412
+ ...optionalLinkProperties,
409
413
  link_type: LinkType.Document,
410
414
  // ID needs to be 16 characters long to be considered valid by the API
411
415
  id: "_____broken_____",
412
416
  isBroken: true,
413
- text: input.text,
414
417
  }
415
418
  }
416
419
 
417
420
  return {
421
+ ...optionalLinkProperties,
418
422
  link_type: LinkType.Document,
419
423
  id: () => this._getByOriginalID(input.id),
420
- text: input.text,
421
424
  }
422
425
  }
423
426
 
424
427
  if (is.filledLinkToMedia(input)) {
428
+ const optionalLinkProperties = getOptionalLinkProperties(input)
429
+
425
430
  return {
431
+ ...optionalLinkProperties,
426
432
  link_type: LinkType.Media,
427
433
  id: this.createAsset(input),
428
- text: input.text,
429
434
  }
430
435
  }
431
436
 
@@ -0,0 +1,27 @@
1
+ import type { OptionalLinkProperties } from "../types/value/link"
2
+
3
+ /**
4
+ * Returns optional properties only available to link fields. Link fields can
5
+ * have the same shape as content relationship and link to media fields,
6
+ * requiring special treatment to extract link-specific properties.
7
+ *
8
+ * @param input - The content relationship or link to media field from which the
9
+ * link properties will be extracted.
10
+ *
11
+ * @returns Optional link properties that `input` might have.
12
+ */
13
+ export const getOptionalLinkProperties = (
14
+ input: OptionalLinkProperties,
15
+ ): OptionalLinkProperties => {
16
+ const res: OptionalLinkProperties = {}
17
+
18
+ if ("text" in input) {
19
+ res.text = input.text
20
+ }
21
+
22
+ if ("variant" in input) {
23
+ res.variant = input.variant
24
+ }
25
+
26
+ return res
27
+ }
@@ -12,6 +12,7 @@ import {
12
12
  import type { PrismicDocument } from "../types/value/document"
13
13
  import type { GroupField } from "../types/value/group"
14
14
  import { LinkType } from "../types/value/link"
15
+ import type { OptionalLinkProperties } from "../types/value/link"
15
16
  import { RichTextNodeType } from "../types/value/richText"
16
17
  import type { SliceZone } from "../types/value/sliceZone"
17
18
  import type { AnyRegularField } from "../types/value/types"
@@ -32,6 +33,10 @@ type UnknownValue =
32
33
  /**
33
34
  * Checks if a value is a migration content relationship field.
34
35
  *
36
+ * @remarks
37
+ * `OptionalLinkProperties` is included because `MigrationContentRelationship`
38
+ * may be a link field, not strictly a content relationship field.
39
+ *
35
40
  * @param value - Value to check.
36
41
  *
37
42
  * @returns `true` if `value` is a migration content relationship field, `false`
@@ -42,7 +47,7 @@ type UnknownValue =
42
47
  */
43
48
  export const contentRelationship = (
44
49
  value: UnknownValue,
45
- ): value is MigrationContentRelationship => {
50
+ ): value is MigrationContentRelationship & OptionalLinkProperties => {
46
51
  return (
47
52
  value instanceof PrismicMigrationDocument ||
48
53
  is.prismicDocument(value) ||
@@ -80,6 +85,10 @@ export const image = (value: UnknownValue): value is MigrationImage => {
80
85
  /**
81
86
  * Checks if a value is a migration link to media field.
82
87
  *
88
+ * - @remarks `OptionalLinkProperties` is included because
89
+ * `MigrationContentRelationship` may be a link field, not strictly a content
90
+ * relationship field.
91
+ *
83
92
  * @param value - Value to check.
84
93
  *
85
94
  * @returns `true` if `value` is a migration link to media field, `false`
@@ -90,7 +99,7 @@ export const image = (value: UnknownValue): value is MigrationImage => {
90
99
  */
91
100
  export const linkToMedia = (
92
101
  value: UnknownValue,
93
- ): value is MigrationLinkToMedia => {
102
+ ): value is MigrationLinkToMedia & OptionalLinkProperties => {
94
103
  return (
95
104
  typeof value === "object" &&
96
105
  value !== null &&
@@ -4,6 +4,7 @@ import type { PrismicDocument } from "../types/value/document"
4
4
  import type { GroupField } from "../types/value/group"
5
5
  import type { ImageField } from "../types/value/image"
6
6
  import { LinkType } from "../types/value/link"
7
+ import type { OptionalLinkProperties } from "../types/value/link"
7
8
  import type { FilledLinkToMediaField } from "../types/value/linkToMedia"
8
9
  import { type RTImageNode, RichTextNodeType } from "../types/value/richText"
9
10
  import type { SliceZone } from "../types/value/sliceZone"
@@ -138,6 +139,11 @@ export const rtImageNode = (value: UnknownValue): value is RTImageNode => {
138
139
  /**
139
140
  * Checks if a value is a content relationship field.
140
141
  *
142
+ * @remarks
143
+ * The return value includes `OptionalLinkProperties` because
144
+ * `FilledContentRelationshipField` may be a link field, not strictly a content
145
+ * relationship field.
146
+ *
141
147
  * @param value - Value to check.
142
148
  *
143
149
  * @returns `true` if `value` is a content relationship, `false` otherwise.
@@ -147,7 +153,7 @@ export const rtImageNode = (value: UnknownValue): value is RTImageNode => {
147
153
  */
148
154
  export const filledContentRelationship = (
149
155
  value: UnknownValue,
150
- ): value is FilledContentRelationshipField => {
156
+ ): value is FilledContentRelationshipField & OptionalLinkProperties => {
151
157
  if (value && typeof value === "object" && !("version" in value)) {
152
158
  if (
153
159
  "link_type" in value &&
@@ -10,8 +10,9 @@ import type {
10
10
  MigrationContentRelationshipField,
11
11
  } from "../types/migration/ContentRelationship"
12
12
  import { PrismicMigrationDocument } from "../types/migration/Document"
13
+ import type { MaybeLink } from "../types/migration/Link"
13
14
  import type { FilledImageFieldImage } from "../types/value/image"
14
- import type { LinkField } from "../types/value/link"
15
+ import type { LinkField, OptionalLinkProperties } from "../types/value/link"
15
16
  import { LinkType } from "../types/value/link"
16
17
  import type { RTImageNode } from "../types/value/richText"
17
18
  import { RichTextNodeType } from "../types/value/richText"
@@ -20,6 +21,7 @@ import * as isFilled from "../helpers/isFilled"
20
21
  import type { Migration } from "../Migration"
21
22
 
22
23
  import * as isMigration from "./isMigrationValue"
24
+ import { getOptionalLinkProperties } from "./getOptionalLinkProperties"
23
25
 
24
26
  /**
25
27
  * Resolves a migration content relationship to a content relationship field.
@@ -29,8 +31,8 @@ import * as isMigration from "./isMigrationValue"
29
31
  * @returns Resolved content relationship field.
30
32
  */
31
33
  export async function resolveMigrationContentRelationship(
32
- relation: MigrationContentRelationship,
33
- ): Promise<MigrationContentRelationshipField> {
34
+ relation: MaybeLink<MigrationContentRelationship>,
35
+ ): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {
34
36
  if (typeof relation === "function") {
35
37
  return resolveMigrationContentRelationship(await relation())
36
38
  }
@@ -38,26 +40,39 @@ export async function resolveMigrationContentRelationship(
38
40
  if (relation instanceof PrismicMigrationDocument) {
39
41
  return relation.document.id
40
42
  ? { link_type: LinkType.Document, id: relation.document.id }
41
- : { link_type: LinkType.Document }
43
+ : { link_type: LinkType.Any }
42
44
  }
43
45
 
46
+ const optionalLinkProperties =
47
+ relation && "link_type" in relation
48
+ ? getOptionalLinkProperties(relation)
49
+ : undefined
50
+
44
51
  if (relation) {
45
52
  if (
46
53
  isMigration.contentRelationship(relation.id) ||
47
- typeof relation.id === "function"
54
+ typeof relation.id !== "string"
48
55
  ) {
49
56
  return {
57
+ ...optionalLinkProperties,
50
58
  ...(await resolveMigrationContentRelationship(relation.id)),
51
- // TODO: Remove when link text PR is merged
52
- // @ts-expect-error - Future-proofing for link text
53
- text: relation.text,
54
59
  }
55
60
  }
56
61
 
57
- return { link_type: LinkType.Document, id: relation.id }
62
+ // This is only called when resolveMigrationContentRelationship recursively
63
+ // calls itself from the statement above and the resolved content relation
64
+ // is a Prismic document value.
65
+ return {
66
+ ...optionalLinkProperties,
67
+ link_type: LinkType.Document,
68
+ id: relation.id,
69
+ }
58
70
  }
59
71
 
60
- return { link_type: LinkType.Document }
72
+ return {
73
+ ...optionalLinkProperties,
74
+ link_type: LinkType.Any,
75
+ }
61
76
  }
62
77
 
63
78
  /**
@@ -154,20 +169,24 @@ export const resolveMigrationRTImageNode = async (
154
169
  * @returns Resolved link to media field.
155
170
  */
156
171
  export const resolveMigrationLinkToMedia = (
157
- linkToMedia: MigrationLinkToMedia,
172
+ linkToMedia: MaybeLink<MigrationLinkToMedia>,
158
173
  migration: Migration,
159
174
  ): MigrationLinkToMediaField => {
160
175
  const asset = migration._assets.get(linkToMedia.id.config.id)?.asset
176
+ const optionalLinkProperties = getOptionalLinkProperties(linkToMedia)
161
177
 
162
178
  if (asset) {
163
179
  return {
180
+ ...optionalLinkProperties,
164
181
  id: asset.id,
165
182
  link_type: LinkType.Media,
166
- text: linkToMedia.text,
167
183
  }
168
184
  }
169
185
 
170
- return { link_type: LinkType.Media }
186
+ return {
187
+ ...optionalLinkProperties,
188
+ link_type: LinkType.Any,
189
+ }
171
190
  }
172
191
 
173
192
  /**
@@ -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
 
@@ -73,15 +72,14 @@ export type MigrationImage =
73
72
  */
74
73
  export type MigrationLinkToMedia = Pick<
75
74
  LinkToMediaField<"filled">,
76
- "link_type"
77
- > &
78
- Partial<Pick<LinkToMediaField<"filled">, "text">> & {
79
- /**
80
- * A reference to the migration asset used to resolve the link to media
81
- * field's value.
82
- */
83
- id: PrismicMigrationAsset
84
- }
75
+ "link_type" | "text"
76
+ > & {
77
+ /**
78
+ * A reference to the migration asset used to resolve the link to media
79
+ * field's value.
80
+ */
81
+ id: PrismicMigrationAsset
82
+ }
85
83
 
86
84
  /**
87
85
  * The minimum amount of information needed to represent a link to media field
@@ -89,7 +87,7 @@ export type MigrationLinkToMedia = Pick<
89
87
  */
90
88
  export type MigrationLinkToMediaField =
91
89
  | Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text">
92
- | EmptyLinkField<"Media">
90
+ | LinkToMediaField<"empty">
93
91
 
94
92
  /**
95
93
  * A rich text image node in a migration.
@@ -1,6 +1,9 @@
1
- import type { FilledContentRelationshipField } from "../value/contentRelationship"
1
+ import type {
2
+ ContentRelationshipField,
3
+ EmptyContentRelationshipField,
4
+ FilledContentRelationshipField,
5
+ } from "../value/contentRelationship"
2
6
  import type { PrismicDocument } from "../value/document"
3
- import type { EmptyLinkField } from "../value/link"
4
7
 
5
8
  import type { PrismicMigrationDocument } from "./Document"
6
9
 
@@ -13,12 +16,11 @@ export type MigrationContentRelationship<
13
16
  TDocuments extends PrismicDocument = PrismicDocument,
14
17
  > =
15
18
  | ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined>
16
- | (Pick<FilledContentRelationshipField, "link_type"> &
17
- Partial<Pick<FilledContentRelationshipField, "text">> & {
18
- id: ValueOrThunk<
19
- TDocuments | PrismicMigrationDocument<TDocuments> | undefined
20
- >
21
- })
19
+ | (Pick<ContentRelationshipField, "link_type"> & {
20
+ id: ValueOrThunk<
21
+ TDocuments | PrismicMigrationDocument<TDocuments> | undefined
22
+ >
23
+ })
22
24
 
23
25
  /**
24
26
  * The minimum amount of information needed to represent a content relationship
@@ -26,4 +28,4 @@ export type MigrationContentRelationship<
26
28
  */
27
29
  export type MigrationContentRelationshipField =
28
30
  | Pick<FilledContentRelationshipField, "link_type" | "id">
29
- | EmptyLinkField<"Document">
31
+ | EmptyContentRelationshipField
@@ -0,0 +1,19 @@
1
+ import type { LinkType, OptionalLinkProperties } from "../value/link"
2
+
3
+ /**
4
+ * Adds `OptionalLinkProperties` to any type that looks like a link object (one
5
+ * that includes a valid `link_type` property).
6
+ *
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * type Example = MaybeLink<PrismicDocument | LinkField>
11
+ * // PrismicDocument | (LinkField & OptionalLinkProperties)
12
+ * ```
13
+ *
14
+ * @typeParam T - The type to augment.
15
+ */
16
+ export type MaybeLink<T> =
17
+ | Exclude<T, { link_type: (typeof LinkType)[keyof typeof LinkType] }>
18
+ | (Extract<T, { link_type: (typeof LinkType)[keyof typeof LinkType] }> &
19
+ OptionalLinkProperties)
@@ -18,6 +18,5 @@ export interface CustomTypeModelContentRelationshipField<
18
18
  select: typeof CustomTypeModelLinkSelectType.Document
19
19
  customtypes?: readonly CustomTypeIDs[]
20
20
  tags?: readonly Tags[]
21
- allowText?: boolean
22
21
  }
23
22
  }
@@ -14,5 +14,6 @@ export interface CustomTypeModelLinkToMediaField {
14
14
  placeholder?: string
15
15
  select: typeof CustomTypeModelLinkSelectType.Media
16
16
  allowText?: boolean
17
+ variants?: string[]
17
18
  }
18
19
  }
@@ -1,7 +1,6 @@
1
1
  import type { AnyRegularField, FieldState } from "./types"
2
2
 
3
3
  import type { GroupField } from "./group"
4
- import type { EmptyLinkField, LinkType } from "./link"
5
4
  import type { SliceZone } from "./sliceZone"
6
5
 
7
6
  /**
@@ -21,9 +20,13 @@ export type ContentRelationshipField<
21
20
  | unknown = unknown,
22
21
  State extends FieldState = FieldState,
23
22
  > = State extends "empty"
24
- ? EmptyLinkField<typeof LinkType.Document>
23
+ ? EmptyContentRelationshipField
25
24
  : FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>
26
25
 
26
+ export type EmptyContentRelationshipField = {
27
+ link_type: "Any"
28
+ }
29
+
27
30
  /**
28
31
  * Links that refer to documents
29
32
  */
@@ -34,7 +37,7 @@ export interface FilledContentRelationshipField<
34
37
  | Record<string, AnyRegularField | GroupField | SliceZone>
35
38
  | unknown = unknown,
36
39
  > {
37
- link_type: typeof LinkType.Document
40
+ link_type: "Document"
38
41
  id: string
39
42
  uid?: string
40
43
  type: TypeEnum
@@ -44,6 +47,4 @@ export interface FilledContentRelationshipField<
44
47
  slug?: string
45
48
  isBroken?: boolean
46
49
  data?: DataInterface
47
- text?: string
48
- variant?: string
49
50
  }
@@ -1,8 +1,8 @@
1
1
  import type { AnyRegularField, FieldState } from "./types"
2
2
 
3
- import type { ContentRelationshipField } from "./contentRelationship"
3
+ import type { FilledContentRelationshipField } from "./contentRelationship"
4
4
  import type { GroupField } from "./group"
5
- import type { LinkToMediaField } from "./linkToMedia"
5
+ import type { FilledLinkToMediaField } from "./linkToMedia"
6
6
  import type { SliceZone } from "./sliceZone"
7
7
 
8
8
  /**
@@ -15,37 +15,13 @@ export const LinkType = {
15
15
  Web: "Web",
16
16
  } as const
17
17
 
18
- /**
19
- * For link fields that haven't been filled
20
- *
21
- * @typeParam Type - The type of link.
22
- */
23
- export type EmptyLinkField<
24
- Type extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,
25
- > = {
26
- link_type: Type | string
27
- text?: string
28
- variant?: string
29
- }
30
-
31
- /**
32
- * Link that points to external website
33
- */
34
- export interface FilledLinkToWebField {
35
- link_type: typeof LinkType.Web
36
- url: string
37
- target?: string
38
- text?: string
39
- variant?: string
40
- }
41
-
42
18
  /**
43
19
  * A link field.
44
20
  *
45
21
  * @typeParam TypeEnum - Type API ID of the document.
46
22
  * @typeParam LangEnum - Language API ID of the document.
47
- * @typeParam DataInterface - Data fields for the document (filled in via
48
- * GraphQuery of `fetchLinks`).
23
+ * @typeParam DataInterface - Data fields for the document (filled via the
24
+ * `fetchLinks` or `graphQuery` query parameter).
49
25
  * @typeParam State - State of the field which determines its shape.
50
26
  */
51
27
  export type LinkField<
@@ -56,8 +32,62 @@ export type LinkField<
56
32
  | unknown = unknown,
57
33
  State extends FieldState = FieldState,
58
34
  > = State extends "empty"
59
- ? EmptyLinkField<typeof LinkType.Any>
60
- :
61
- | ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>
62
- | FilledLinkToWebField
63
- | LinkToMediaField<State>
35
+ ? EmptyLinkField
36
+ : FilledLinkField<TypeEnum, LangEnum, DataInterface>
37
+
38
+ /**
39
+ * A link field that is filled.
40
+ *
41
+ * @typeParam TypeEnum - Type API ID of the document.
42
+ * @typeParam LangEnum - Language API ID of the document.
43
+ * @typeParam DataInterface - Data fields for the document (filled via the
44
+ * `fetchLinks` or `graphQuery` query parameter).
45
+ */
46
+ export type FilledLinkField<
47
+ TypeEnum = string,
48
+ LangEnum = string,
49
+ DataInterface extends
50
+ | Record<string, AnyRegularField | GroupField | SliceZone>
51
+ | unknown = unknown,
52
+ > = (
53
+ | FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>
54
+ | FilledLinkToMediaField
55
+ | FilledLinkToWebField
56
+ ) &
57
+ OptionalLinkProperties
58
+
59
+ /**
60
+ * A link field that is not filled.
61
+ *
62
+ * @typeParam _Unused - THIS PARAMETER IS NOT USED. If you are passing a type,
63
+ * **please remove it**.
64
+ */
65
+ export type EmptyLinkField<
66
+ _Unused extends
67
+ (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,
68
+ > = {
69
+ link_type: "Any"
70
+ } & OptionalLinkProperties
71
+
72
+ /**
73
+ * A link field pointing to a relative or absolute URL.
74
+ */
75
+ export type FilledLinkToWebField = {
76
+ link_type: "Web"
77
+ url: string
78
+ target?: string
79
+ } & OptionalLinkProperties
80
+
81
+ /**
82
+ * Optional properties available to link fields. It is used to augment existing
83
+ * link-like fields (like content relationship fields) with field-specific
84
+ * properties.
85
+ *
86
+ * @internal
87
+ */
88
+ // Remember to update the `getOptionalLinkProperties()` function when updating
89
+ // this type. The function should check for every property.
90
+ export type OptionalLinkProperties = {
91
+ text?: string
92
+ variant?: string
93
+ }