@prismicio/client 7.20.1 → 7.20.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 (76) hide show
  1. package/dist/buildQueryURL.cjs.map +1 -1
  2. package/dist/buildQueryURL.d.ts +29 -21
  3. package/dist/buildQueryURL.js.map +1 -1
  4. package/dist/createClient.cjs.map +1 -1
  5. package/dist/createClient.d.ts +11 -8
  6. package/dist/createClient.js.map +1 -1
  7. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  8. package/dist/getRepositoryEndpoint.d.ts +9 -2
  9. package/dist/getRepositoryEndpoint.js.map +1 -1
  10. package/dist/helpers/asDate.cjs.map +1 -1
  11. package/dist/helpers/asDate.d.ts +11 -4
  12. package/dist/helpers/asDate.js.map +1 -1
  13. package/dist/helpers/asHTML.cjs.map +1 -1
  14. package/dist/helpers/asHTML.d.ts +34 -26
  15. package/dist/helpers/asHTML.js.map +1 -1
  16. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  17. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +16 -15
  18. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  19. package/dist/helpers/asImageSrc.cjs.map +1 -1
  20. package/dist/helpers/asImageSrc.d.ts +11 -10
  21. package/dist/helpers/asImageSrc.js.map +1 -1
  22. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  23. package/dist/helpers/asImageWidthSrcSet.d.ts +18 -17
  24. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  25. package/dist/helpers/asLink.cjs.map +1 -1
  26. package/dist/helpers/asLink.d.ts +32 -31
  27. package/dist/helpers/asLink.js.map +1 -1
  28. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  29. package/dist/helpers/asLinkAttrs.d.ts +6 -9
  30. package/dist/helpers/asLinkAttrs.js.map +1 -1
  31. package/dist/helpers/asText.cjs.map +1 -1
  32. package/dist/helpers/asText.d.ts +20 -10
  33. package/dist/helpers/asText.js.map +1 -1
  34. package/dist/helpers/isFilled.cjs +1 -1
  35. package/dist/helpers/isFilled.cjs.map +1 -1
  36. package/dist/helpers/isFilled.d.ts +14 -13
  37. package/dist/helpers/isFilled.js +1 -1
  38. package/dist/helpers/isFilled.js.map +1 -1
  39. package/dist/helpers/mapSliceZone.cjs.map +1 -1
  40. package/dist/helpers/mapSliceZone.d.ts +10 -10
  41. package/dist/helpers/mapSliceZone.js.map +1 -1
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  45. package/dist/isRepositoryEndpoint.d.ts +2 -2
  46. package/dist/isRepositoryEndpoint.js.map +1 -1
  47. package/dist/package.json.cjs +1 -1
  48. package/dist/package.json.js +1 -1
  49. package/dist/richtext/asText.cjs.map +1 -1
  50. package/dist/richtext/asText.d.ts +5 -5
  51. package/dist/richtext/asText.js.map +1 -1
  52. package/dist/richtext/serialize.cjs.map +1 -1
  53. package/dist/richtext/serialize.d.ts +8 -8
  54. package/dist/richtext/serialize.js.map +1 -1
  55. package/dist/richtext/types.cjs.map +1 -1
  56. package/dist/richtext/types.d.ts +6 -6
  57. package/dist/richtext/types.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/buildQueryURL.ts +29 -21
  60. package/src/createClient.ts +11 -8
  61. package/src/getRepositoryEndpoint.ts +9 -2
  62. package/src/helpers/asDate.ts +11 -4
  63. package/src/helpers/asHTML.ts +34 -26
  64. package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
  65. package/src/helpers/asImageSrc.ts +11 -10
  66. package/src/helpers/asImageWidthSrcSet.ts +18 -17
  67. package/src/helpers/asLink.ts +33 -32
  68. package/src/helpers/asLinkAttrs.ts +6 -9
  69. package/src/helpers/asText.ts +20 -10
  70. package/src/helpers/isFilled.ts +15 -14
  71. package/src/helpers/mapSliceZone.ts +10 -10
  72. package/src/index.ts +1 -1
  73. package/src/isRepositoryEndpoint.ts +2 -2
  74. package/src/richtext/asText.ts +5 -5
  75. package/src/richtext/serialize.ts +8 -8
  76. package/src/richtext/types.ts +6 -6
@@ -39,11 +39,11 @@ export interface Ordering {
39
39
  }
40
40
 
41
41
  /**
42
- * A `routes` parameter that determines how a document's URL field is resolved.
42
+ * A `routes` parameter that determines how a page's URL field is resolved.
43
43
  *
44
44
  * {@link https://prismic.io/docs/route-resolver}
45
45
  *
46
- * @example With a document's UID field.
46
+ * @example With a page's UID field.
47
47
  *
48
48
  * ```ts
49
49
  * {
@@ -66,24 +66,24 @@ export interface Ordering {
66
66
  */
67
67
  export interface Route {
68
68
  /**
69
- * The custom type of the document.
69
+ * The custom type of the page.
70
70
  */
71
71
  type: string
72
72
 
73
73
  /**
74
74
  * A specific UID to which this route definition is scoped. The route is only
75
- * defined for the document whose UID matches the given UID.
75
+ * defined for the page whose UID matches the given UID.
76
76
  */
77
77
  uid?: string
78
78
 
79
79
  /**
80
80
  * A specific language to which this route definition is scoped. The route is
81
- * only defined for documents whose language matches the given language.
81
+ * only defined for pages whose language matches the given language.
82
82
  */
83
83
  lang?: string
84
84
 
85
85
  /**
86
- * The resolved path of the document with optional placeholders.
86
+ * The resolved path of the page with optional placeholders.
87
87
  */
88
88
  path: string
89
89
 
@@ -94,9 +94,9 @@ export interface Route {
94
94
  }
95
95
 
96
96
  /**
97
- * Parameters for the Prismic REST API V2.
97
+ * Parameters for the Prismic Content API.
98
98
  *
99
- * {@link https://prismic.io/docs/api}
99
+ * @see Learn how to fetch content from Prismic: {@link https://prismic.io/docs/fetch-content}
100
100
  */
101
101
  export interface QueryParams {
102
102
  /**
@@ -108,8 +108,8 @@ export interface QueryParams {
108
108
  accessToken?: string
109
109
 
110
110
  /**
111
- * The `pageSize` parameter defines the maximum number of documents that the
112
- * API will return for your query.
111
+ * The `pageSize` parameter defines the maximum number of pages that the API
112
+ * will return for your query.
113
113
  *
114
114
  * {@link https://prismic.io/docs/rest-api-technical-reference#pagesize}
115
115
  */
@@ -124,8 +124,8 @@ export interface QueryParams {
124
124
 
125
125
  /**
126
126
  * The `after` parameter can be used along with the orderings option. It will
127
- * remove all the documents except for those after the specified document in
128
- * the list.
127
+ * remove all the pages except for those after the specified page in the
128
+ * list.
129
129
  *
130
130
  * {@link https://prismic.io/docs/rest-api-technical-reference#after}
131
131
  */
@@ -141,7 +141,7 @@ export interface QueryParams {
141
141
 
142
142
  /**
143
143
  * The `fetchLinks` parameter allows you to retrieve a specific content field
144
- * from a linked document and add it to the document response object.
144
+ * from a linked page and add it to the page response object.
145
145
  *
146
146
  * {@link https://prismic.io/docs/rest-api-technical-reference#fetchlinks}
147
147
  */
@@ -189,7 +189,7 @@ export interface QueryParams {
189
189
  orderings?: string | Ordering | (string | Ordering)[]
190
190
 
191
191
  /**
192
- * The `routes` option allows you to define how a document's `url` field is
192
+ * The `routes` option allows you to define how a page's `url` field is
193
193
  * resolved.
194
194
  *
195
195
  * {@link https://prismic.io/docs/route-resolver}
@@ -199,7 +199,7 @@ export interface QueryParams {
199
199
  /**
200
200
  * The `brokenRoute` option allows you to define the route populated in the
201
201
  * `url` property for broken link or content relationship fields. A broken
202
- * link is a link or content relationship field whose linked document has been
202
+ * link is a link or content relationship field whose linked page has been
203
203
  * unpublished or deleted.
204
204
  *
205
205
  * {@link https://prismic.io/docs/route-resolver}
@@ -296,21 +296,29 @@ const castOrderingToString = (ordering: Ordering | string): string => {
296
296
  export type BuildQueryURLArgs = QueryParams & BuildQueryURLParams
297
297
 
298
298
  /**
299
- * Build a Prismic REST API V2 URL to request documents from a repository. The
300
- * paginated response for this URL includes documents matching the parameters.
299
+ * Builds a Prismic Content API URL to request pages from a repository. The
300
+ * paginated response for this URL includes pages matching the parameters.
301
301
  *
302
302
  * A ref is required to make a request. Request the `endpoint` URL to retrieve a
303
303
  * list of available refs.
304
304
  *
305
305
  * Type the JSON response with `Query`.
306
306
  *
307
- * {@link https://prismic.io/docs/api#refs-and-the-entry-api}
308
- * {@link https://prismic.io/docs/rest-api-technical-reference}
307
+ * @example
309
308
  *
310
- * @param endpoint - URL to the repository's REST API V2.
309
+ * ```ts
310
+ * const url = buildQueryURL("https://my-repo.cdn.prismic.io/api/v2", {
311
+ * ref: "my-ref",
312
+ * filters: [filter.at("document.type", "blog_post")],
313
+ * })
314
+ * ```
315
+ *
316
+ * @param endpoint - URL to the repository's Content API.
311
317
  * @param args - Arguments to filter and scope the query.
312
318
  *
313
- * @returns URL that can be used to request documents from the repository.
319
+ * @returns URL that can be used to request pages from the repository.
320
+ *
321
+ * @see Prismic Content API technical reference: {@link https://prismic.io/docs/content-api}
314
322
  */
315
323
  export const buildQueryURL = (
316
324
  endpoint: string,
@@ -14,26 +14,29 @@ export interface CreateClient {
14
14
  }
15
15
 
16
16
  /**
17
- * Creates a Prismic client that can be used to query a repository.
17
+ * Creates a Prismic client that can be used to query content from a repository.
18
18
  *
19
19
  * @example
20
20
  *
21
21
  * ```ts
22
- * // With a repository name.
23
- * createClient("qwerty")
22
+ * // With a repository name
23
+ * createClient("my-repo")
24
24
  *
25
- * // Or with a full Prismic Rest API V2 endpoint.
26
- * createClient("https://qwerty.cdn.prismic.io/api/v2")
25
+ * // With a full Prismic Content API endpoint
26
+ * createClient("https://my-repo.cdn.prismic.io/api/v2")
27
27
  * ```
28
28
  *
29
- * @typeParam TDocuments - A union of Prismic document types for the repository.
29
+ * @typeParam TDocuments - A union of Prismic page and custom types for the
30
+ * repository.
30
31
  *
31
- * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
32
- * API V2 endpoint for the repository.
32
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full Content
33
+ * API endpoint for the repository.
33
34
  * @param options - Configuration that determines how content will be queried
34
35
  * from the Prismic repository.
35
36
  *
36
37
  * @returns A client that can query content from the repository.
38
+ *
39
+ * @see @prismicio/client technical reference: {@link https://prismic.io/docs/technical-reference/prismicio-client/v7}
37
40
  */
38
41
  export const createClient: CreateClient = <TDocuments extends PrismicDocument>(
39
42
  repositoryNameOrEndpoint: string,
@@ -3,13 +3,20 @@ import { PrismicError } from "./errors/PrismicError"
3
3
  import { isRepositoryName } from "./isRepositoryName"
4
4
 
5
5
  /**
6
- * Get a repository's Prismic Rest API V2 endpoint.
6
+ * Get a repository's Prismic Content API endpoint.
7
+ *
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * getRepositoryEndpoint("my-repo")
12
+ * // => "https://my-repo.cdn.prismic.io/api/v2"
13
+ * ```
7
14
  *
8
15
  * @typeParam RepositoryName - Name of the Prismic repository.
9
16
  *
10
17
  * @param repositoryName - Name of the repository.
11
18
  *
12
- * @returns The repository's Prismic Rest API V2 endpoint
19
+ * @returns The repository's Prismic Content API endpoint.
13
20
  *
14
21
  * @throws {@link Error} Thrown if an invalid repository name is provided.
15
22
  */
@@ -9,13 +9,20 @@ type AsDateReturnType<
9
9
  > = Field extends DateField<"filled"> | TimestampField<"filled"> ? Date : null
10
10
 
11
11
  /**
12
- * Transforms a date or timestamp field into a JavaScript Date object
12
+ * Converts a date or timestamp field to a JavaScript Date object.
13
13
  *
14
- * @param dateOrTimestampField - A date or timestamp field from Prismic
14
+ * @example
15
15
  *
16
- * @returns A Date object, null if provided date is falsy
16
+ * ```ts
17
+ * const date = asDate(document.data.release_date)
18
+ * // => Date object or null
19
+ * ```
17
20
  *
18
- * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}
21
+ * @param dateOrTimestampField - A date or timestamp field from Prismic.
22
+ *
23
+ * @returns A Date object, or `null` if the field is empty.
24
+ *
25
+ * @see Learn about date and timestamp fields: {@link https://prismic.io/docs/fields/date}
19
26
  */
20
27
  export const asDate = <
21
28
  Field extends DateField | TimestampField | null | undefined,
@@ -19,13 +19,13 @@ import { composeSerializers, serialize, wrapMapSerializer } from "../richtext"
19
19
  import type { LinkResolverFunction } from "./asLink"
20
20
 
21
21
  /**
22
- * Serializes a node from a rich text or title field with a function to HTML.
22
+ * Serializes a node from a rich text field with a function to HTML.
23
23
  *
24
24
  * Unlike a typical `@prismicio/client/richtext` function serializer, this
25
25
  * serializer converts the `children` argument to a single string rather than an
26
26
  * array of strings.
27
27
  *
28
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
28
+ * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
29
29
  */
30
30
  export type HTMLRichTextFunctionSerializer = (
31
31
  type: Parameters<RichTextFunctionSerializer<string>>[0],
@@ -36,13 +36,13 @@ export type HTMLRichTextFunctionSerializer = (
36
36
  ) => string | null | undefined
37
37
 
38
38
  /**
39
- * Serializes a node from a rich text or title field with a map to HTML
39
+ * Serializes a node from a rich text field with a map to HTML.
40
40
  *
41
41
  * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
42
42
  * converts the `children` property to a single string rather than an array of
43
43
  * strings and accepts shorthand declarations.
44
44
  *
45
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
45
+ * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
46
46
  */
47
47
  export type HTMLRichTextMapSerializer = {
48
48
  [P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>["span"]
@@ -51,13 +51,13 @@ export type HTMLRichTextMapSerializer = {
51
51
  }
52
52
 
53
53
  /**
54
- * Serializes a node from a rich text or title field with a map to HTML
54
+ * Serializes a node from a rich text field with a map to HTML.
55
55
  *
56
56
  * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
57
57
  * converts the `children` property to a single string rather than an array of
58
58
  * strings but doesn't accept shorthand declarations.
59
59
  *
60
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
60
+ * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
61
61
  */
62
62
  export type HTMLStrictRichTextMapSerializer = {
63
63
  [P in keyof RichTextMapSerializer<string>]: (payload: {
@@ -135,11 +135,10 @@ export type HTMLRichTextMapSerializerShorthand = {
135
135
  }
136
136
 
137
137
  /**
138
- * Serializes a node from a rich text or title field with a map or a function to
139
- * HTML
138
+ * Serializes a node from a rich text field with a map or a function to HTML.
140
139
  *
141
140
  * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}
142
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
141
+ * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
143
142
  */
144
143
  export type HTMLRichTextSerializer =
145
144
  | HTMLRichTextMapSerializer
@@ -291,14 +290,14 @@ const wrapMapSerializerWithStringChildren = (
291
290
  */
292
291
  type AsHTMLConfig = {
293
292
  /**
294
- * An optional link resolver function to resolve links. Without it you're
295
- * expected to use the `routes` options from the API.
293
+ * An optional link resolver function to resolve links. Without it, you're
294
+ * expected to use the `routes` option from the API.
296
295
  */
297
296
  linkResolver?: LinkResolverFunction | null
298
297
 
299
298
  /**
300
- * An optional rich text serializer, unhandled cases will fallback to the
301
- * default serializer
299
+ * An optional rich text serializer. Unhandled cases will fall back to the
300
+ * default serializer.
302
301
  */
303
302
  serializer?: HTMLRichTextSerializer | null
304
303
  }
@@ -321,14 +320,22 @@ type AsHTMLReturnType<Field extends RichTextField | null | undefined> =
321
320
  // TODO: Remove overload when we remove support for deprecated tuple-style configuration.
322
321
  export const asHTML: {
323
322
  /**
324
- * Serializes a rich text or title field to an HTML string.
323
+ * Converts a rich text field to an HTML string.
325
324
  *
326
- * @param richTextField - A rich text or title field from Prismic
327
- * @param config - Configuration that determines the output of `asHTML()`
325
+ * @example
328
326
  *
329
- * @returns HTML equivalent of the provided rich text or title field
327
+ * ```ts
328
+ * const html = asHTML(document.data.content)
329
+ * // => "<p>Hello world</p>"
330
+ * ```
330
331
  *
331
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
332
+ * @param richTextField - A rich text field from Prismic.
333
+ * @param config - Configuration that determines the output of `asHTML()`.
334
+ *
335
+ * @returns HTML equivalent of the rich text field, or `null` if the field is
336
+ * empty.
337
+ *
338
+ * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
332
339
  */
333
340
  <Field extends RichTextField | null | undefined>(
334
341
  richTextField: Field,
@@ -336,19 +343,20 @@ export const asHTML: {
336
343
  ): AsHTMLReturnType<Field>
337
344
 
338
345
  /**
339
- * Serializes a rich text or title field to an HTML string.
346
+ * Converts a rich text field to an HTML string.
340
347
  *
341
348
  * @deprecated Use object-style configuration instead.
342
349
  *
343
- * @param richTextField - A rich text or title field from Prismic
344
- * @param linkResolver - An optional link resolver function to resolve links,
345
- * without it you're expected to use the `routes` options from the API
346
- * @param serializer - An optional rich text serializer, unhandled cases will
347
- * fallback to the default serializer
350
+ * @param richTextField - A rich text field from Prismic.
351
+ * @param linkResolver - An optional link resolver function to resolve links.
352
+ * Without it, you're expected to use the `routes` option from the API.
353
+ * @param serializer - An optional rich text serializer. Unhandled cases will
354
+ * fall back to the default serializer.
348
355
  *
349
- * @returns HTML equivalent of the provided rich text or title field
356
+ * @returns HTML equivalent of the rich text field, or `null` if the field is
357
+ * empty.
350
358
  *
351
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
359
+ * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
352
360
  */
353
361
  <Field extends RichTextField | null | undefined>(
354
362
  richTextField: Field,
@@ -28,13 +28,13 @@ type AsImagePixelDensitySrcSetReturnType<
28
28
  Field extends ImageFieldImage<"filled">
29
29
  ? {
30
30
  /**
31
- * The image field's image URL with Imgix URL parameters (if given).
31
+ * The image field's URL with imgix URL parameters (if given).
32
32
  */
33
33
  src: string
34
34
 
35
35
  /**
36
- * A pixel-densitye-based `srcset` attribute value for the image field's
37
- * image with Imgix URL parameters (if given).
36
+ * A pixel-density-based `srcset` attribute value for the image field
37
+ * with imgix URL parameters (if given).
38
38
  */
39
39
  srcset: string
40
40
  }
@@ -42,7 +42,7 @@ type AsImagePixelDensitySrcSetReturnType<
42
42
 
43
43
  /**
44
44
  * Creates a pixel-density-based `srcset` from an image field with optional
45
- * image transformations (via Imgix URL parameters).
45
+ * image transformations via imgix URL parameters.
46
46
  *
47
47
  * If a `pixelDensities` parameter is not given, the following pixel densities
48
48
  * will be used by default: 1, 2, 3.
@@ -50,26 +50,27 @@ type AsImagePixelDensitySrcSetReturnType<
50
50
  * @example
51
51
  *
52
52
  * ```ts
53
- * const srcset = asImagePixelDensitySrcSet(document.data.imageField, {
53
+ * const srcset = asImagePixelDensitySrcSet(document.data.photo, {
54
54
  * pixelDensities: [1, 2],
55
55
  * sat: -100,
56
56
  * })
57
57
  * // => {
58
- * // src: 'https://images.prismic.io/repo/image.png?sat=-100',
59
- * // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, ' +
60
- * // 'https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x'
58
+ * // src: "https://images.prismic.io/repo/image.png?sat=-100",
59
+ * // srcset: "https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, " +
60
+ * // "https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x"
61
61
  * // }
62
62
  * ```
63
63
  *
64
- * @param field - Image field (or one of its responsive views) from which to get
65
- * an image URL.
66
- * @param config - An object of Imgix URL API parameters. The `pixelDensities`
67
- * parameter defines the resulting `srcset` widths.
64
+ * @param field - An image field (or one of its responsive views) from which to
65
+ * get an image URL.
66
+ * @param config - An object of imgix URL API parameters. The `pixelDensities`
67
+ * parameter defines the resulting `srcset` pixel densities.
68
68
  *
69
- * @returns A `srcset` attribute value for the image field with Imgix URL
70
- * parameters (if given). If the image field is empty, `null` is returned.
69
+ * @returns A `srcset` attribute value for the image field with imgix URL
70
+ * parameters, or `null` if the field is empty.
71
71
  *
72
- * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
72
+ * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
73
+ * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
73
74
  */
74
75
  export const asImagePixelDensitySrcSet = <
75
76
  Field extends ImageFieldImage | null | undefined,
@@ -12,24 +12,25 @@ type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =
12
12
  Field extends ImageFieldImage<"filled"> ? string : null
13
13
 
14
14
  /**
15
- * Returns the URL of an image field with optional image transformations (via
16
- * Imgix URL parameters).
15
+ * Returns the URL of an image field with optional image transformations via
16
+ * imgix URL parameters.
17
17
  *
18
18
  * @example
19
19
  *
20
20
  * ```ts
21
- * const src = asImageSrc(document.data.imageField, { sat: -100 })
22
- * // => https://images.prismic.io/repo/image.png?sat=-100
21
+ * const src = asImageSrc(document.data.photo, { sat: -100 })
22
+ * // => "https://images.prismic.io/repo/image.png?sat=-100"
23
23
  * ```
24
24
  *
25
- * @param field - Image field (or one of its responsive views) from which to get
26
- * an image URL.
27
- * @param config - An object of Imgix URL API parameters to transform the image.
25
+ * @param field - An image field (or one of its responsive views) from which to
26
+ * get an image URL.
27
+ * @param config - An object of imgix URL API parameters to transform the image.
28
28
  *
29
- * @returns The image field's image URL with transformations applied (if given).
30
- * If the image field is empty, `null` is returned.
29
+ * @returns The image field's URL with transformations applied, or `null` if the
30
+ * field is empty.
31
31
  *
32
- * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
32
+ * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
33
+ * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
33
34
  */
34
35
  export const asImageSrc = <Field extends ImageFieldImage | null | undefined>(
35
36
  field: Field,
@@ -19,13 +19,13 @@ type AsImageWidthSrcSetReturnType<
19
19
  Field extends ImageFieldImage<"filled">
20
20
  ? {
21
21
  /**
22
- * The image field's image URL with Imgix URL parameters (if given).
22
+ * The image field's URL with imgix URL parameters (if given).
23
23
  */
24
24
  src: string
25
25
 
26
26
  /**
27
- * A width-based `srcset` attribute value for the image field's image
28
- * with Imgix URL parameters (if given).
27
+ * A width-based `srcset` attribute value for the image field with imgix
28
+ * URL parameters (if given).
29
29
  */
30
30
  srcset: string
31
31
  }
@@ -40,10 +40,10 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
40
40
 
41
41
  /**
42
42
  * Creates a width-based `srcset` from an image field with optional image
43
- * transformations (via Imgix URL parameters).
43
+ * transformations via imgix URL parameters.
44
44
  *
45
- * If a `widths` parameter is not given, the following widths will be used by
46
- * default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
45
+ * If a `widths` parameter is not given, the following widths (in pixels) will
46
+ * be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
47
47
  *
48
48
  * If the image field contains responsive views, each responsive view can be
49
49
  * used as a width in the resulting `srcset` by passing `"thumbnails"` as the
@@ -52,28 +52,29 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
52
52
  * @example
53
53
  *
54
54
  * ```ts
55
- * const srcset = asImageWidthSrcSet(document.data.imageField, {
55
+ * const srcset = asImageWidthSrcSet(document.data.photo, {
56
56
  * widths: [400, 800, 1600],
57
57
  * sat: -100,
58
58
  * })
59
59
  * // => {
60
- * // src: 'https://images.prismic.io/repo/image.png?sat=-100',
61
- * // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, ' +
62
- * // 'https://images.prismic.io/repo/image.png?sat=-100&width=800 800w,' +
63
- * // 'https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w'
60
+ * // src: "https://images.prismic.io/repo/image.png?sat=-100",
61
+ * // srcset: "https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, " +
62
+ * // "https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, " +
63
+ * // "https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w"
64
64
  * // }
65
65
  * ```
66
66
  *
67
- * @param field - Image field (or one of its responsive views) from which to get
68
- * an image URL.
69
- * @param config - An object of Imgix URL API parameters. The `widths` parameter
67
+ * @param field - An image field (or one of its responsive views) from which to
68
+ * get an image URL.
69
+ * @param config - An object of imgix URL API parameters. The `widths` parameter
70
70
  * defines the resulting `srcset` widths. Pass `"thumbnails"` to automatically
71
71
  * use the field's responsive views.
72
72
  *
73
- * @returns A `srcset` attribute value for the image field with Imgix URL
74
- * parameters (if given). If the image field is empty, `null` is returned.
73
+ * @returns A `srcset` attribute value for the image field with imgix URL
74
+ * parameters, or `null` if the field is empty.
75
75
  *
76
- * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
76
+ * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
77
+ * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
77
78
  */
78
79
  export const asImageWidthSrcSet = <
79
80
  Field extends ImageFieldImage | null | undefined,
@@ -7,16 +7,16 @@ import type { FilledLinkToMediaField } from "../types/value/linkToMedia"
7
7
  import { documentToLinkField } from "./documentToLinkField"
8
8
 
9
9
  /**
10
- * Resolves a link to a Prismic document to a URL
10
+ * Resolves a link to a Prismic page to a URL.
11
11
  *
12
- * @typeParam ReturnType - Return type of your link resolver function, useful if
13
- * you prefer to return a complex object
12
+ * @typeParam ReturnType - Return type of your link resolver function. Useful if
13
+ * you prefer to return a complex object.
14
14
  *
15
- * @param linkToDocumentField - A document link field to resolve
15
+ * @param linkToDocumentField - A page link field to resolve.
16
16
  *
17
- * @returns Resolved URL
17
+ * @returns Resolved URL.
18
18
  *
19
- * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
19
+ * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
20
20
  */
21
21
  export type LinkResolverFunction<ReturnType = string | null | undefined> = (
22
22
  linkToDocumentField: FilledContentRelationshipField,
@@ -28,8 +28,8 @@ export type LinkResolverFunction<ReturnType = string | null | undefined> = (
28
28
  type AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =
29
29
  {
30
30
  /**
31
- * An optional link resolver function. Without it, you are expected to use
32
- * the `routes` options from the API.
31
+ * An optional link resolver function. Without it, you're expected to use
32
+ * the `routes` option from the API.
33
33
  */
34
34
  linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null
35
35
  }
@@ -63,21 +63,25 @@ export type AsLinkReturnType<
63
63
  // TODO: Remove overload when we remove support for deprecated tuple-style configuration.
64
64
  export const asLink: {
65
65
  /**
66
- * Resolves any type of link field or Prismic document to a URL.
66
+ * Converts any type of link field or Prismic page to a URL.
67
67
  *
68
- * @typeParam LinkResolverFunctionReturnType - link resolver function return
69
- * type
70
- * @typeParam Field - Link field or Prismic document to resolve to a URL
68
+ * @example
71
69
  *
72
- * @param linkFieldOrDocument - Any kind of link field or a document to
73
- * resolve
74
- * @param config - Configuration that determines the output of `asLink()`
70
+ * ```ts
71
+ * const url = asLink(document.data.link)
72
+ * // => "/blog/my-post"
73
+ * ```
75
74
  *
76
- * @returns Resolved URL or, if the provided link field or document is empty,
77
- * `null`
75
+ * @typeParam LinkResolverFunctionReturnType - Link resolver function return
76
+ * type.
77
+ * @typeParam Field - Link field or Prismic page to resolve to a URL.
78
78
  *
79
- * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
80
- * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
79
+ * @param linkFieldOrDocument - Any kind of link field or a page to resolve.
80
+ * @param config - Configuration that determines the output of `asLink()`.
81
+ *
82
+ * @returns Resolved URL, or `null` if the link field or page is empty.
83
+ *
84
+ * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
81
85
  */
82
86
  <
83
87
  LinkResolverFunctionReturnType = string | null | undefined,
@@ -92,24 +96,21 @@ export const asLink: {
92
96
  ): AsLinkReturnType<LinkResolverFunctionReturnType, Field>
93
97
 
94
98
  /**
95
- * Resolves any type of link field or Prismic document to a URL.
99
+ * Converts any type of link field or Prismic page to a URL.
96
100
  *
97
101
  * @deprecated Use object-style configuration instead.
98
102
  *
99
- * @typeParam LinkResolverFunctionReturnType - link resolver function return
100
- * type
101
- * @typeParam Field - Link field or Prismic document to resolve to a URL
103
+ * @typeParam LinkResolverFunctionReturnType - Link resolver function return
104
+ * type.
105
+ * @typeParam Field - Link field or Prismic page to resolve to a URL.
102
106
  *
103
- * @param linkFieldOrDocument - Any kind of link field or a document to
104
- * resolve
105
- * @param linkResolver - An optional link resolver function. Without it, you
106
- * are expected to use the `routes` options from the API
107
+ * @param linkFieldOrDocument - Any kind of link field or a page to resolve.
108
+ * @param linkResolver - An optional link resolver function. Without it,
109
+ * you're expected to use the `routes` option from the API.
107
110
  *
108
- * @returns Resolved URL or, if the provided link field or document is empty,
109
- * `null`
111
+ * @returns Resolved URL, or `null` if the link field or page is empty.
110
112
  *
111
- * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
112
- * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
113
+ * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
113
114
  */
114
115
  <
115
116
  LinkResolverFunctionReturnType = string | null | undefined,
@@ -195,7 +196,7 @@ export const asLink: {
195
196
  >
196
197
  }
197
198
 
198
- // When empty or link resolver and route resolver are not used...
199
+ // When empty or route resolver and link resolver are not used...
199
200
  return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
200
201
  }
201
202