@prismicio/client 7.12.0-alpha.0 → 7.12.0

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 (54) hide show
  1. package/dist/Client.cjs +47 -7
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.ts +20 -2
  4. package/dist/Client.js +47 -7
  5. package/dist/Client.js.map +1 -1
  6. package/dist/helpers/asLink.cjs +7 -9
  7. package/dist/helpers/asLink.cjs.map +1 -1
  8. package/dist/helpers/asLink.js +7 -9
  9. package/dist/helpers/asLink.js.map +1 -1
  10. package/dist/helpers/isFilled.cjs +0 -3
  11. package/dist/helpers/isFilled.cjs.map +1 -1
  12. package/dist/helpers/isFilled.d.ts +1 -2
  13. package/dist/helpers/isFilled.js +0 -3
  14. package/dist/helpers/isFilled.js.map +1 -1
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/lib/resolveMigrationDocumentData.cjs +1 -6
  19. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
  20. package/dist/lib/resolveMigrationDocumentData.js +1 -6
  21. package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
  22. package/dist/lib/serializerHelpers.cjs +3 -0
  23. package/dist/lib/serializerHelpers.cjs.map +1 -1
  24. package/dist/lib/serializerHelpers.js +3 -0
  25. package/dist/lib/serializerHelpers.js.map +1 -1
  26. package/dist/package.json.cjs +1 -1
  27. package/dist/package.json.js +1 -1
  28. package/dist/types/migration/Asset.cjs.map +1 -1
  29. package/dist/types/migration/Asset.d.ts +3 -3
  30. package/dist/types/migration/Asset.js.map +1 -1
  31. package/dist/types/model/contentRelationship.d.ts +0 -1
  32. package/dist/types/model/link.cjs.map +1 -1
  33. package/dist/types/model/link.d.ts +0 -1
  34. package/dist/types/model/link.js.map +1 -1
  35. package/dist/types/model/linkToMedia.d.ts +0 -1
  36. package/dist/types/value/contentRelationship.d.ts +1 -24
  37. package/dist/types/value/link.cjs.map +1 -1
  38. package/dist/types/value/link.d.ts +3 -26
  39. package/dist/types/value/link.js.map +1 -1
  40. package/dist/types/value/linkToMedia.d.ts +1 -13
  41. package/package.json +9 -9
  42. package/src/Client.ts +74 -7
  43. package/src/helpers/asLink.ts +8 -11
  44. package/src/helpers/isFilled.ts +1 -6
  45. package/src/index.ts +0 -1
  46. package/src/lib/resolveMigrationDocumentData.ts +3 -10
  47. package/src/lib/serializerHelpers.ts +5 -0
  48. package/src/types/migration/Asset.ts +4 -7
  49. package/src/types/model/contentRelationship.ts +0 -1
  50. package/src/types/model/link.ts +0 -1
  51. package/src/types/model/linkToMedia.ts +0 -1
  52. package/src/types/value/contentRelationship.ts +2 -45
  53. package/src/types/value/link.ts +6 -49
  54. package/src/types/value/linkToMedia.ts +2 -21
@@ -12,6 +12,5 @@ export interface CustomTypeModelLinkToMediaField {
12
12
  placeholder?: string;
13
13
  select: typeof CustomTypeModelLinkSelectType.Media;
14
14
  allowText?: boolean;
15
- repeat?: boolean;
16
15
  };
17
16
  }
@@ -2,29 +2,6 @@ import type { AnyRegularField, FieldState } from "./types";
2
2
  import type { GroupField } from "./group";
3
3
  import type { EmptyLinkField, LinkType } from "./link";
4
4
  import type { SliceZone } from "./sliceZone";
5
- /**
6
- * Single field value for related documents
7
- *
8
- * @typeParam TypeEnum - Type API ID of the document.
9
- * @typeParam LangEnum - Language API ID of the document.
10
- * @typeParam DataInterface - Data fields for the document (filled in via
11
- * GraphQuery of `fetchLinks`).
12
- * @typeParam State - State of the field which determines its shape.
13
- */
14
- export type SingleContentRelationshipField<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>;
15
- /**
16
- * Repeatable field value for related documents
17
- *
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 in via
21
- * GraphQuery of `fetchLinks`).
22
- * @typeParam State - State of the field which determines its shape.
23
- */
24
- export type RepeatableContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? [] : [
25
- SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface>,
26
- ...SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface>[]
27
- ];
28
5
  /**
29
6
  * Field for related documents
30
7
  *
@@ -34,7 +11,7 @@ export type RepeatableContentRelationshipField<TypeEnum = string, LangEnum = str
34
11
  * GraphQuery of `fetchLinks`).
35
12
  * @typeParam State - State of the field which determines its shape.
36
13
  */
37
- export type ContentRelationshipField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface, State> | RepeatableContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>;
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>;
38
15
  /**
39
16
  * Links that refer to documents
40
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"link.cjs","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { SingleContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { SingleLinkToMediaField } 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}\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}\n\n/**\n * A single link field value.\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 SingleLinkField<\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| SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>\n\t\t\t| FilledLinkToWebField\n\t\t\t| SingleLinkToMediaField<State>\n\n/**\n * A repeatable link field value.\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 RepeatableLinkFieldValue<\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? []\n\t: [\n\t\t\tSingleLinkField<TypeEnum, LangEnum, DataInterface>,\n\t\t\t...SingleLinkField<TypeEnum, LangEnum, DataInterface>[],\n\t\t]\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> =\n\t| SingleLinkField<TypeEnum, LangEnum, DataInterface, State>\n\t| RepeatableLinkFieldValue<TypeEnum, LangEnum, DataInterface, 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 { 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}\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}\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,7 +1,7 @@
1
1
  import type { AnyRegularField, FieldState } from "./types";
2
- import type { SingleContentRelationshipField } from "./contentRelationship";
2
+ import type { ContentRelationshipField } from "./contentRelationship";
3
3
  import type { GroupField } from "./group";
4
- import type { SingleLinkToMediaField } from "./linkToMedia";
4
+ import type { LinkToMediaField } from "./linkToMedia";
5
5
  import type { SliceZone } from "./sliceZone";
6
6
  /**
7
7
  * Link types
@@ -30,29 +30,6 @@ export interface FilledLinkToWebField {
30
30
  target?: string;
31
31
  text?: string;
32
32
  }
33
- /**
34
- * A single link field value.
35
- *
36
- * @typeParam TypeEnum - Type API ID of the document.
37
- * @typeParam LangEnum - Language API ID of the document.
38
- * @typeParam DataInterface - Data fields for the document (filled in via
39
- * GraphQuery of `fetchLinks`).
40
- * @typeParam State - State of the field which determines its shape.
41
- */
42
- export type SingleLinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Any> : SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface, State> | FilledLinkToWebField | SingleLinkToMediaField<State>;
43
- /**
44
- * A repeatable link field value.
45
- *
46
- * @typeParam TypeEnum - Type API ID of the document.
47
- * @typeParam LangEnum - Language API ID of the document.
48
- * @typeParam DataInterface - Data fields for the document (filled in via
49
- * GraphQuery of `fetchLinks`).
50
- * @typeParam State - State of the field which determines its shape.
51
- */
52
- export type RepeatableLinkFieldValue<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = State extends "empty" ? [] : [
53
- SingleLinkField<TypeEnum, LangEnum, DataInterface>,
54
- ...SingleLinkField<TypeEnum, LangEnum, DataInterface>[]
55
- ];
56
33
  /**
57
34
  * A link field.
58
35
  *
@@ -62,4 +39,4 @@ export type RepeatableLinkFieldValue<TypeEnum = string, LangEnum = string, DataI
62
39
  * GraphQuery of `fetchLinks`).
63
40
  * @typeParam State - State of the field which determines its shape.
64
41
  */
65
- export type LinkField<TypeEnum = string, LangEnum = string, DataInterface extends Record<string, AnyRegularField | GroupField | SliceZone> | unknown = unknown, State extends FieldState = FieldState> = SingleLinkField<TypeEnum, LangEnum, DataInterface, State> | RepeatableLinkFieldValue<TypeEnum, LangEnum, DataInterface, State>;
42
+ 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>;
@@ -1 +1 @@
1
- {"version":3,"file":"link.js","sources":["../../../../src/types/value/link.ts"],"sourcesContent":["import type { AnyRegularField, FieldState } from \"./types\"\n\nimport type { SingleContentRelationshipField } from \"./contentRelationship\"\nimport type { GroupField } from \"./group\"\nimport type { SingleLinkToMediaField } 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}\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}\n\n/**\n * A single link field value.\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 SingleLinkField<\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| SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>\n\t\t\t| FilledLinkToWebField\n\t\t\t| SingleLinkToMediaField<State>\n\n/**\n * A repeatable link field value.\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 RepeatableLinkFieldValue<\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? []\n\t: [\n\t\t\tSingleLinkField<TypeEnum, LangEnum, DataInterface>,\n\t\t\t...SingleLinkField<TypeEnum, LangEnum, DataInterface>[],\n\t\t]\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> =\n\t| SingleLinkField<TypeEnum, LangEnum, DataInterface, State>\n\t| RepeatableLinkFieldValue<TypeEnum, LangEnum, DataInterface, 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 { 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}\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}\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,23 +1,11 @@
1
1
  import type { FieldState } from "./types";
2
2
  import type { EmptyLinkField, LinkType } from "./link";
3
- /**
4
- * A single link field value that points to media.
5
- *
6
- * @typeParam State - State of the field which determines its shape.
7
- */
8
- export type SingleLinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Media> : FilledLinkToMediaField;
9
- /**
10
- * Repeatable link field values that point to media.
11
- *
12
- * @typeParam State - State of the field which determines its shape.
13
- */
14
- export type RepeatableLinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? [] : [SingleLinkToMediaField, ...SingleLinkToMediaField[]];
15
3
  /**
16
4
  * A link field that points to media.
17
5
  *
18
6
  * @typeParam State - State of the field which determines its shape.
19
7
  */
20
- export type LinkToMediaField<State extends FieldState = FieldState> = SingleLinkToMediaField<State> | RepeatableLinkToMediaField<State>;
8
+ export type LinkToMediaField<State extends FieldState = FieldState> = State extends "empty" ? EmptyLinkField<typeof LinkType.Media> : FilledLinkToMediaField;
21
9
  /**
22
10
  * A link that points to media.
23
11
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/client",
3
- "version": "7.12.0-alpha.0",
3
+ "version": "7.12.0",
4
4
  "description": "The official JavaScript + TypeScript client library for Prismic",
5
5
  "keywords": [
6
6
  "typescript",
@@ -83,28 +83,28 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@prismicio/mock": "^0.3.9",
86
- "@prismicio/types-internal": "^2.9.0-alpha.0",
87
- "@size-limit/preset-small-lib": "^11.1.4",
86
+ "@prismicio/types-internal": "^2.8.0",
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",
90
90
  "@typescript-eslint/parser": "^6.21.0",
91
- "@vitest/coverage-v8": "^2.0.4",
91
+ "@vitest/coverage-v8": "^2.1.4",
92
92
  "abort-controller": "^3.0.0",
93
- "eslint": "^8.57.0",
93
+ "eslint": "^8.57.1",
94
94
  "eslint-config-prettier": "^9.1.0",
95
95
  "eslint-plugin-prettier": "^5.2.1",
96
96
  "eslint-plugin-tsdoc": "^0.3.0",
97
- "msw": "^1.3.3",
97
+ "msw": "^1.3.5",
98
98
  "node-fetch": "^3.3.2",
99
99
  "prettier": "^3.3.3",
100
100
  "prettier-plugin-jsdoc": "1.3.0",
101
- "size-limit": "^11.1.4",
101
+ "size-limit": "^11.1.6",
102
102
  "standard-version": "^9.5.0",
103
103
  "ts-expect": "^1.3.0",
104
- "typescript": "^5.5.4",
104
+ "typescript": "^5.6.3",
105
105
  "vite": "^5.3.5",
106
106
  "vite-plugin-sdk": "^0.1.2",
107
- "vitest": "^2.0.4"
107
+ "vitest": "^2.1.4"
108
108
  },
109
109
  "engines": {
110
110
  "node": ">=14.15.0"
package/src/Client.ts CHANGED
@@ -73,6 +73,13 @@ export const GET_ALL_QUERY_DELAY = 500
73
73
  */
74
74
  const DEFUALT_RETRY_AFTER_MS = 1000
75
75
 
76
+ /**
77
+ * The maximum number of attemps to retry a query with an invalid ref. We allow
78
+ * multiple attempts since each attempt may use a different (and possibly
79
+ * invalid) ref. Capping the number of attemps prevents infinite loops.
80
+ */
81
+ const MAX_INVALID_REF_RETRY_ATTEMPS = 3
82
+
76
83
  /**
77
84
  * Extracts one or more Prismic document types that match a given Prismic
78
85
  * document type. If no matches are found, no extraction is performed and the
@@ -529,9 +536,9 @@ export class Client<
529
536
  async get<TDocument extends TDocuments>(
530
537
  params?: Partial<BuildQueryURLArgs> & FetchParams,
531
538
  ): Promise<Query<TDocument>> {
532
- const url = await this.buildQueryURL(params)
539
+ const { data } = await this._get<TDocument>(params)
533
540
 
534
- return await this.fetch<Query<TDocument>>(url, params)
541
+ return data
535
542
  }
536
543
 
537
544
  /**
@@ -546,8 +553,9 @@ export class Client<
546
553
  *
547
554
  * @typeParam TDocument - Type of the Prismic document returned.
548
555
  *
549
- * @param params - Parameters to filter, sort, and paginate results. @returns
550
- * The first result of the query, if any.
556
+ * @param params - Parameters to filter, sort, and paginate results.
557
+ *
558
+ * @returns The first result of the query, if any.
551
559
  */
552
560
  async getFirst<TDocument extends TDocuments>(
553
561
  params?: Partial<BuildQueryURLArgs> & FetchParams,
@@ -556,10 +564,9 @@ export class Client<
556
564
  if (!(params && params.page) && !params?.pageSize) {
557
565
  actualParams.pageSize = this.defaultParams?.pageSize ?? 1
558
566
  }
559
- const url = await this.buildQueryURL(actualParams)
560
- const result = await this.fetch<Query<TDocument>>(url, params)
567
+ const { data, url } = await this._get<TDocument>(actualParams)
561
568
 
562
- const firstResult = result.results[0]
569
+ const firstResult = data.results[0]
563
570
 
564
571
  if (firstResult) {
565
572
  return firstResult
@@ -1678,6 +1685,66 @@ export class Client<
1678
1685
  return findMasterRef(cachedRepository.refs).ref
1679
1686
  }
1680
1687
 
1688
+ /**
1689
+ * The private implementation of `this.get`. It returns the API response and
1690
+ * the URL used to make the request. The URL is sometimes used in the public
1691
+ * method to include in thrown errors.
1692
+ *
1693
+ * This method retries requests that throw `RefNotFoundError` or
1694
+ * `RefExpiredError`. It contains special logic to retry with the latest
1695
+ * master ref, provided in the API's error message.
1696
+ *
1697
+ * @typeParam TDocument - Type of Prismic documents returned.
1698
+ *
1699
+ * @param params - Parameters to filter, sort, and paginate results.
1700
+ *
1701
+ * @returns An object containing the paginated response containing the result
1702
+ * of the query and the URL used to make the API request.
1703
+ */
1704
+ private async _get<TDocument extends TDocuments>(
1705
+ params?: Partial<BuildQueryURLArgs> & FetchParams,
1706
+ attemptCount = 0,
1707
+ ): Promise<{ data: Query<TDocument>; url: string }> {
1708
+ const url = await this.buildQueryURL(params)
1709
+
1710
+ try {
1711
+ const data = await this.fetch<Query<TDocument>>(url, params)
1712
+
1713
+ return { data, url }
1714
+ } catch (error) {
1715
+ if (
1716
+ !(
1717
+ error instanceof RefNotFoundError || error instanceof RefExpiredError
1718
+ ) ||
1719
+ attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPS - 1
1720
+ ) {
1721
+ throw error
1722
+ }
1723
+
1724
+ // If no explicit ref is given (i.e. the master ref from
1725
+ // /api/v2 is used), clear the cached repository value.
1726
+ // Clearing the cached value prevents other methods from
1727
+ // using a known-stale ref.
1728
+ if (!params?.ref) {
1729
+ this.cachedRepository = undefined
1730
+ }
1731
+
1732
+ const masterRef = error.message.match(/Master ref is: (?<ref>.*)$/)
1733
+ ?.groups?.ref
1734
+ if (!masterRef) {
1735
+ throw error
1736
+ }
1737
+
1738
+ const badRef = new URL(url).searchParams.get("ref")
1739
+ const issue = error instanceof RefNotFoundError ? "invalid" : "expired"
1740
+ console.warn(
1741
+ `The ref (${badRef}) was ${issue}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`,
1742
+ )
1743
+
1744
+ return await this._get({ ...params, ref: masterRef }, attemptCount + 1)
1745
+ }
1746
+ }
1747
+
1681
1748
  /**
1682
1749
  * Performs a network request using the configured `fetch` function. It
1683
1750
  * assumes all successful responses will have a JSON content type. It also
@@ -140,20 +140,17 @@ export const asLink: {
140
140
  return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
141
141
  }
142
142
 
143
- // If the link field is repeatable, then it returns the first link in
144
- // the array. If not, then it converts document to link field if needed
145
- let linkField: LinkField
146
- if (Array.isArray(linkFieldOrDocument)) {
147
- if (!linkFieldOrDocument[0]) {
148
- return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
149
- }
150
- linkField = linkFieldOrDocument[0]
151
- } else {
152
- linkField =
143
+ // Converts document to link field if needed
144
+ const linkField =
145
+ // prettier-ignore
146
+ (
147
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
148
+ // @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
149
+ // TODO: Remove the `prettier-ignore` comment when this bug is fixed.
153
150
  "link_type" in linkFieldOrDocument
154
151
  ? linkFieldOrDocument
155
152
  : documentToLinkField(linkFieldOrDocument)
156
- }
153
+ ) as LinkField
157
154
 
158
155
  // TODO: Remove when we remove support for deprecated tuple-style configuration.
159
156
  const [configObjectOrLinkResolver] = configObjectOrTuple
@@ -100,8 +100,7 @@ export const image = imageThumbnail as <
100
100
  ) => field is ImageField<ThumbnailNames, "filled">
101
101
 
102
102
  /**
103
- * Determines if a link field is filled. If the field is repeatable, it checks
104
- * if the link array contains at least one item
103
+ * Determines if a link field is filled.
105
104
  *
106
105
  * @param field - Link field to check.
107
106
  *
@@ -116,10 +115,6 @@ export const link = <
116
115
  >(
117
116
  field: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined,
118
117
  ): field is LinkField<TypeEnum, LangEnum, DataInterface, "filled"> => {
119
- if (Array.isArray(field)) {
120
- return isNonNullish(field) && isNonEmptyArray(field)
121
- }
122
-
123
118
  return isNonNullish(field) && ("id" in field || "url" in field)
124
119
  }
125
120
 
package/src/index.ts CHANGED
@@ -207,7 +207,6 @@ export type {
207
207
  export type {
208
208
  LinkToMediaField,
209
209
  FilledLinkToMediaField,
210
- SingleLinkToMediaField,
211
210
  } from "./types/value/linkToMedia"
212
211
 
213
212
  export type {
@@ -11,7 +11,7 @@ import type {
11
11
  } from "../types/migration/ContentRelationship"
12
12
  import { PrismicMigrationDocument } from "../types/migration/Document"
13
13
  import type { FilledImageFieldImage } from "../types/value/image"
14
- import type { SingleLinkField } from "../types/value/link"
14
+ import type { LinkField } from "../types/value/link"
15
15
  import { LinkType } from "../types/value/link"
16
16
  import type { RTImageNode } from "../types/value/richText"
17
17
  import { RichTextNodeType } from "../types/value/richText"
@@ -78,14 +78,7 @@ export const resolveMigrationImage = (
78
78
  image instanceof PrismicMigrationAsset ? { id: image } : image
79
79
 
80
80
  const asset = migration._assets.get(master.config.id)?.asset
81
- let maybeInitialField
82
- if (Array.isArray(master.originalField)) {
83
- maybeInitialField = isFilled.link(master.originalField[0])
84
- ? master.originalField[0]
85
- : undefined
86
- } else {
87
- maybeInitialField = master.originalField
88
- }
81
+ const maybeInitialField = master.originalField
89
82
 
90
83
  if (asset) {
91
84
  const parameters = (maybeInitialField?.url || asset.url).split("?")[1]
@@ -142,7 +135,7 @@ export const resolveMigrationRTImageNode = async (
142
135
  const linkTo = (await resolveMigrationDocumentData(
143
136
  rtImageNode.linkTo,
144
137
  migration,
145
- )) as SingleLinkField
138
+ )) as LinkField
146
139
 
147
140
  return {
148
141
  ...image,
@@ -15,6 +15,11 @@ type Attributes = Record<string, string | boolean | null | undefined>
15
15
  const formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {
16
16
  const _attributes = { ...attributes }
17
17
 
18
+ // Respect `ltr` and `rtl` direction
19
+ if ("direction" in node && node.direction === "rtl") {
20
+ _attributes.dir = node.direction
21
+ }
22
+
18
23
  // Add label to attributes
19
24
  if ("data" in node && "label" in node.data && node.data.label) {
20
25
  _attributes.class = _attributes.class
@@ -1,10 +1,7 @@
1
1
  import type { Asset } from "../api/asset/asset"
2
2
  import type { FilledImageFieldImage } from "../value/image"
3
3
  import type { EmptyLinkField } from "../value/link"
4
- import type {
5
- LinkToMediaField,
6
- SingleLinkToMediaField,
7
- } from "../value/linkToMedia"
4
+ import type { LinkToMediaField } from "../value/linkToMedia"
8
5
  import { type RTImageNode } from "../value/richText"
9
6
 
10
7
  import type { InjectMigrationSpecificTypes } from "./Document"
@@ -75,10 +72,10 @@ export type MigrationImage =
75
72
  * A link to media field in a migration.
76
73
  */
77
74
  export type MigrationLinkToMedia = Pick<
78
- SingleLinkToMediaField<"filled">,
75
+ LinkToMediaField<"filled">,
79
76
  "link_type"
80
77
  > &
81
- Partial<Pick<SingleLinkToMediaField<"filled">, "text">> & {
78
+ Partial<Pick<LinkToMediaField<"filled">, "text">> & {
82
79
  /**
83
80
  * A reference to the migration asset used to resolve the link to media
84
81
  * field's value.
@@ -91,7 +88,7 @@ export type MigrationLinkToMedia = Pick<
91
88
  * with the migration API.
92
89
  */
93
90
  export type MigrationLinkToMediaField =
94
- | Pick<SingleLinkToMediaField<"filled">, "link_type" | "id" | "text">
91
+ | Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text">
95
92
  | EmptyLinkField<"Media">
96
93
 
97
94
  /**
@@ -19,6 +19,5 @@ export interface CustomTypeModelContentRelationshipField<
19
19
  customtypes?: readonly CustomTypeIDs[]
20
20
  tags?: readonly Tags[]
21
21
  allowText?: boolean
22
- repeat?: boolean
23
22
  }
24
23
  }
@@ -15,7 +15,6 @@ export interface CustomTypeModelLinkField {
15
15
  | (typeof CustomTypeModelLinkSelectType)[keyof typeof CustomTypeModelLinkSelectType]
16
16
  allowText?: boolean
17
17
  allowTargetBlank?: boolean
18
- repeat?: boolean
19
18
  }
20
19
  }
21
20
 
@@ -14,6 +14,5 @@ export interface CustomTypeModelLinkToMediaField {
14
14
  placeholder?: string
15
15
  select: typeof CustomTypeModelLinkSelectType.Media
16
16
  allowText?: boolean
17
- repeat?: boolean
18
17
  }
19
18
  }
@@ -5,7 +5,7 @@ import type { EmptyLinkField, LinkType } from "./link"
5
5
  import type { SliceZone } from "./sliceZone"
6
6
 
7
7
  /**
8
- * Single field value for related documents
8
+ * Field for related documents
9
9
  *
10
10
  * @typeParam TypeEnum - Type API ID of the document.
11
11
  * @typeParam LangEnum - Language API ID of the document.
@@ -13,7 +13,7 @@ import type { SliceZone } from "./sliceZone"
13
13
  * GraphQuery of `fetchLinks`).
14
14
  * @typeParam State - State of the field which determines its shape.
15
15
  */
16
- export type SingleContentRelationshipField<
16
+ export type ContentRelationshipField<
17
17
  TypeEnum = string,
18
18
  LangEnum = string,
19
19
  DataInterface extends
@@ -24,49 +24,6 @@ export type SingleContentRelationshipField<
24
24
  ? EmptyLinkField<typeof LinkType.Document>
25
25
  : FilledContentRelationshipField<TypeEnum, LangEnum, DataInterface>
26
26
 
27
- /**
28
- * Repeatable field value for related documents
29
- *
30
- * @typeParam TypeEnum - Type API ID of the document.
31
- * @typeParam LangEnum - Language API ID of the document.
32
- * @typeParam DataInterface - Data fields for the document (filled in via
33
- * GraphQuery of `fetchLinks`).
34
- * @typeParam State - State of the field which determines its shape.
35
- */
36
- export type RepeatableContentRelationshipField<
37
- TypeEnum = string,
38
- LangEnum = string,
39
- DataInterface extends
40
- | Record<string, AnyRegularField | GroupField | SliceZone>
41
- | unknown = unknown,
42
- State extends FieldState = FieldState,
43
- > = State extends "empty"
44
- ? []
45
- : [
46
- SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface>,
47
- ...SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface>[],
48
- ]
49
-
50
- /**
51
- * Field for related documents
52
- *
53
- * @typeParam TypeEnum - Type API ID of the document.
54
- * @typeParam LangEnum - Language API ID of the document.
55
- * @typeParam DataInterface - Data fields for the document (filled in via
56
- * GraphQuery of `fetchLinks`).
57
- * @typeParam State - State of the field which determines its shape.
58
- */
59
- export type ContentRelationshipField<
60
- TypeEnum = string,
61
- LangEnum = string,
62
- DataInterface extends
63
- | Record<string, AnyRegularField | GroupField | SliceZone>
64
- | unknown = unknown,
65
- State extends FieldState = FieldState,
66
- > =
67
- | SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>
68
- | RepeatableContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>
69
-
70
27
  /**
71
28
  * Links that refer to documents
72
29
  */
@@ -1,8 +1,8 @@
1
1
  import type { AnyRegularField, FieldState } from "./types"
2
2
 
3
- import type { SingleContentRelationshipField } from "./contentRelationship"
3
+ import type { ContentRelationshipField } from "./contentRelationship"
4
4
  import type { GroupField } from "./group"
5
- import type { SingleLinkToMediaField } from "./linkToMedia"
5
+ import type { LinkToMediaField } from "./linkToMedia"
6
6
  import type { SliceZone } from "./sliceZone"
7
7
 
8
8
  /**
@@ -38,7 +38,7 @@ export interface FilledLinkToWebField {
38
38
  }
39
39
 
40
40
  /**
41
- * A single link field value.
41
+ * A link field.
42
42
  *
43
43
  * @typeParam TypeEnum - Type API ID of the document.
44
44
  * @typeParam LangEnum - Language API ID of the document.
@@ -46,7 +46,7 @@ export interface FilledLinkToWebField {
46
46
  * GraphQuery of `fetchLinks`).
47
47
  * @typeParam State - State of the field which determines its shape.
48
48
  */
49
- export type SingleLinkField<
49
+ export type LinkField<
50
50
  TypeEnum = string,
51
51
  LangEnum = string,
52
52
  DataInterface extends
@@ -56,49 +56,6 @@ export type SingleLinkField<
56
56
  > = State extends "empty"
57
57
  ? EmptyLinkField<typeof LinkType.Any>
58
58
  :
59
- | SingleContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>
59
+ | ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>
60
60
  | FilledLinkToWebField
61
- | SingleLinkToMediaField<State>
62
-
63
- /**
64
- * A repeatable link field value.
65
- *
66
- * @typeParam TypeEnum - Type API ID of the document.
67
- * @typeParam LangEnum - Language API ID of the document.
68
- * @typeParam DataInterface - Data fields for the document (filled in via
69
- * GraphQuery of `fetchLinks`).
70
- * @typeParam State - State of the field which determines its shape.
71
- */
72
- export type RepeatableLinkFieldValue<
73
- TypeEnum = string,
74
- LangEnum = string,
75
- DataInterface extends
76
- | Record<string, AnyRegularField | GroupField | SliceZone>
77
- | unknown = unknown,
78
- State extends FieldState = FieldState,
79
- > = State extends "empty"
80
- ? []
81
- : [
82
- SingleLinkField<TypeEnum, LangEnum, DataInterface>,
83
- ...SingleLinkField<TypeEnum, LangEnum, DataInterface>[],
84
- ]
85
-
86
- /**
87
- * A link field.
88
- *
89
- * @typeParam TypeEnum - Type API ID of the document.
90
- * @typeParam LangEnum - Language API ID of the document.
91
- * @typeParam DataInterface - Data fields for the document (filled in via
92
- * GraphQuery of `fetchLinks`).
93
- * @typeParam State - State of the field which determines its shape.
94
- */
95
- export type LinkField<
96
- TypeEnum = string,
97
- LangEnum = string,
98
- DataInterface extends
99
- | Record<string, AnyRegularField | GroupField | SliceZone>
100
- | unknown = unknown,
101
- State extends FieldState = FieldState,
102
- > =
103
- | SingleLinkField<TypeEnum, LangEnum, DataInterface, State>
104
- | RepeatableLinkFieldValue<TypeEnum, LangEnum, DataInterface, State>
61
+ | LinkToMediaField<State>