@prismicio/client 7.0.0 → 7.0.1-alpha.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 (131) hide show
  1. package/dist/buildQueryURL.cjs.map +1 -1
  2. package/dist/buildQueryURL.d.ts +11 -10
  3. package/dist/buildQueryURL.js.map +1 -1
  4. package/dist/createClient.cjs +39 -6
  5. package/dist/createClient.cjs.map +1 -1
  6. package/dist/createClient.d.ts +68 -21
  7. package/dist/createClient.js +39 -6
  8. package/dist/createClient.js.map +1 -1
  9. package/dist/filter.cjs +38 -38
  10. package/dist/filter.cjs.map +1 -1
  11. package/dist/filter.d.ts +38 -38
  12. package/dist/filter.js +38 -38
  13. package/dist/filter.js.map +1 -1
  14. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  15. package/dist/getGraphQLEndpoint.d.ts +1 -0
  16. package/dist/getGraphQLEndpoint.js.map +1 -1
  17. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  18. package/dist/getRepositoryEndpoint.d.ts +2 -0
  19. package/dist/getRepositoryEndpoint.js.map +1 -1
  20. package/dist/getRepositoryName.cjs.map +1 -1
  21. package/dist/getRepositoryName.d.ts +1 -0
  22. package/dist/getRepositoryName.js.map +1 -1
  23. package/dist/getToolbarSrc.cjs.map +1 -1
  24. package/dist/getToolbarSrc.d.ts +1 -1
  25. package/dist/getToolbarSrc.js.map +1 -1
  26. package/dist/helpers/asDate.cjs.map +1 -1
  27. package/dist/helpers/asDate.d.ts +1 -0
  28. package/dist/helpers/asDate.js.map +1 -1
  29. package/dist/helpers/asHTML.cjs.map +1 -1
  30. package/dist/helpers/asHTML.d.ts +21 -15
  31. package/dist/helpers/asHTML.js.map +1 -1
  32. package/dist/helpers/asLink.cjs.map +1 -1
  33. package/dist/helpers/asLink.d.ts +24 -15
  34. package/dist/helpers/asLink.js.map +1 -1
  35. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  36. package/dist/helpers/asLinkAttrs.d.ts +9 -4
  37. package/dist/helpers/asLinkAttrs.js.map +1 -1
  38. package/dist/helpers/asText.cjs.map +1 -1
  39. package/dist/helpers/asText.d.ts +11 -7
  40. package/dist/helpers/asText.js.map +1 -1
  41. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  42. package/dist/helpers/documentToLinkField.d.ts +2 -0
  43. package/dist/helpers/documentToLinkField.js.map +1 -1
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.ts +1 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/lib/appendFilters.cjs.map +1 -1
  48. package/dist/lib/appendFilters.d.ts +4 -4
  49. package/dist/lib/appendFilters.js.map +1 -1
  50. package/dist/lib/castArray.cjs.map +1 -1
  51. package/dist/lib/castArray.d.ts +1 -0
  52. package/dist/lib/castArray.js.map +1 -1
  53. package/dist/lib/castThunk.cjs.map +1 -1
  54. package/dist/lib/castThunk.d.ts +2 -1
  55. package/dist/lib/castThunk.js.map +1 -1
  56. package/dist/lib/everyTagFilter.cjs.map +1 -1
  57. package/dist/lib/everyTagFilter.d.ts +2 -2
  58. package/dist/lib/everyTagFilter.js.map +1 -1
  59. package/dist/lib/findMasterRef.cjs.map +1 -1
  60. package/dist/lib/findMasterRef.d.ts +1 -0
  61. package/dist/lib/findMasterRef.js.map +1 -1
  62. package/dist/lib/findRef.cjs.map +1 -1
  63. package/dist/lib/findRef.d.ts +3 -2
  64. package/dist/lib/findRef.js.map +1 -1
  65. package/dist/lib/findRefByID.cjs.map +1 -1
  66. package/dist/lib/findRefByID.d.ts +1 -0
  67. package/dist/lib/findRefByID.js.map +1 -1
  68. package/dist/lib/findRefByLabel.cjs.map +1 -1
  69. package/dist/lib/findRefByLabel.d.ts +1 -0
  70. package/dist/lib/findRefByLabel.js.map +1 -1
  71. package/dist/package.json.cjs +1 -1
  72. package/dist/package.json.js +1 -1
  73. package/dist/types/api/query.d.ts +1 -0
  74. package/dist/types/api/release.d.ts +1 -0
  75. package/dist/types/api/tags.d.ts +1 -0
  76. package/dist/types/model/contentRelationship.d.ts +1 -2
  77. package/dist/types/model/link.cjs.map +1 -1
  78. package/dist/types/model/link.d.ts +2 -4
  79. package/dist/types/model/link.js.map +1 -1
  80. package/dist/types/model/linkToMedia.d.ts +1 -2
  81. package/dist/types/value/color.d.ts +1 -0
  82. package/dist/types/value/date.d.ts +1 -0
  83. package/dist/types/value/embed.cjs.map +1 -1
  84. package/dist/types/value/embed.d.ts +1 -0
  85. package/dist/types/value/embed.js.map +1 -1
  86. package/dist/types/value/geoPoint.d.ts +1 -0
  87. package/dist/types/value/image.d.ts +2 -0
  88. package/dist/types/value/integration.d.ts +1 -0
  89. package/dist/types/value/keyText.d.ts +1 -0
  90. package/dist/types/value/number.d.ts +1 -0
  91. package/dist/types/value/select.d.ts +1 -0
  92. package/dist/types/value/types.d.ts +1 -0
  93. package/package.json +3 -3
  94. package/src/buildQueryURL.ts +11 -10
  95. package/src/createClient.ts +85 -28
  96. package/src/filter.ts +42 -42
  97. package/src/getGraphQLEndpoint.ts +1 -0
  98. package/src/getRepositoryEndpoint.ts +2 -0
  99. package/src/getRepositoryName.ts +1 -0
  100. package/src/getToolbarSrc.ts +1 -1
  101. package/src/helpers/asDate.ts +1 -0
  102. package/src/helpers/asHTML.ts +23 -17
  103. package/src/helpers/asLink.ts +24 -15
  104. package/src/helpers/asLinkAttrs.ts +9 -4
  105. package/src/helpers/asText.ts +11 -7
  106. package/src/helpers/documentToLinkField.ts +2 -0
  107. package/src/index.ts +1 -0
  108. package/src/lib/appendFilters.ts +4 -4
  109. package/src/lib/castArray.ts +1 -0
  110. package/src/lib/castThunk.ts +9 -2
  111. package/src/lib/everyTagFilter.ts +2 -2
  112. package/src/lib/findMasterRef.ts +1 -0
  113. package/src/lib/findRef.ts +3 -2
  114. package/src/lib/findRefByID.ts +1 -0
  115. package/src/lib/findRefByLabel.ts +1 -0
  116. package/src/types/api/query.ts +1 -0
  117. package/src/types/api/release.ts +1 -0
  118. package/src/types/api/tags.ts +1 -0
  119. package/src/types/model/contentRelationship.ts +1 -2
  120. package/src/types/model/link.ts +2 -4
  121. package/src/types/model/linkToMedia.ts +1 -2
  122. package/src/types/value/color.ts +1 -0
  123. package/src/types/value/date.ts +1 -0
  124. package/src/types/value/embed.ts +1 -0
  125. package/src/types/value/geoPoint.ts +1 -0
  126. package/src/types/value/image.ts +2 -0
  127. package/src/types/value/integration.ts +1 -0
  128. package/src/types/value/keyText.ts +1 -0
  129. package/src/types/value/number.ts +1 -0
  130. package/src/types/value/select.ts +1 -0
  131. package/src/types/value/types.ts +1 -0
package/src/filter.ts CHANGED
@@ -30,10 +30,10 @@ const formatValue = (
30
30
  };
31
31
 
32
32
  /**
33
- * Creates a filter builder function for filters with a path and
34
- * arguments.
33
+ * Creates a filter builder function for filters with a path and arguments.
35
34
  *
36
35
  * @typeParam Args - Arguments for the filter.
36
+ *
37
37
  * @param name - Name of the filter used in the resulting string.
38
38
  *
39
39
  * @returns Filter builder function for the given name.
@@ -73,8 +73,8 @@ const pathFilter = (name: string) => {
73
73
  };
74
74
 
75
75
  /**
76
- * Creates a filter builder function for filters with only arguments and
77
- * no path.
76
+ * Creates a filter builder function for filters with only arguments and no
77
+ * path.
78
78
  *
79
79
  * @param name - Name of the filter used in the resulting string.
80
80
  *
@@ -95,8 +95,8 @@ const argsFilter = <Args extends unknown[]>(name: string) => {
95
95
 
96
96
  export const filter = {
97
97
  /**
98
- * The `at` filter checks that the path matches the described value
99
- * exactly. It takes a single value for a field or an array (only for tags).
98
+ * The `at` filter checks that the path matches the described value exactly.
99
+ * It takes a single value for a field or an array (only for tags).
100
100
  *
101
101
  * {@link https://prismic.io/docs/rest-api-technical-reference#at}
102
102
  */
@@ -115,8 +115,8 @@ export const filter = {
115
115
  ),
116
116
 
117
117
  /**
118
- * The `any` filter takes an array of values. It works exactly the same way
119
- * as the `at` operator, but checks whether the fragment matches any of the
118
+ * The `any` filter takes an array of values. It works exactly the same way as
119
+ * the `at` operator, but checks whether the fragment matches any of the
120
120
  * values in the array.
121
121
  *
122
122
  * {@link https://prismic.io/docs/rest-api-technical-reference#any}
@@ -126,9 +126,9 @@ export const filter = {
126
126
  ),
127
127
 
128
128
  /**
129
- * The `in` filter is used specifically to retrieve an array of documents
130
- * by their IDs or UIDs. This filter is much more efficient at this than
131
- * the any filter.
129
+ * The `in` filter is used specifically to retrieve an array of documents by
130
+ * their IDs or UIDs. This filter is much more efficient at this than the any
131
+ * filter.
132
132
  *
133
133
  * {@link https://prismic.io/docs/rest-api-technical-reference#in}
134
134
  */
@@ -147,9 +147,9 @@ export const filter = {
147
147
  fulltext: pathWithArgsFilter<[searchTerms: string]>("fulltext"),
148
148
 
149
149
  /**
150
- * The `has` filter checks whether a fragment has a value. It will return
151
- * all the documents of the specified type that contain a value for the
152
- * specified field.
150
+ * The `has` filter checks whether a fragment has a value. It will return all
151
+ * the documents of the specified type that contain a value for the specified
152
+ * field.
153
153
  *
154
154
  * {@link https://prismic.io/docs/rest-api-technical-reference#has}
155
155
  */
@@ -174,8 +174,8 @@ export const filter = {
174
174
  similar: argsFilter<[id: string, value: number]>("similar"),
175
175
 
176
176
  /**
177
- * The `geopoint.near` filter checks that the value in the path is within
178
- * the radius of the given coordinates.
177
+ * The `geopoint.near` filter checks that the value in the path is within the
178
+ * radius of the given coordinates.
179
179
  *
180
180
  * This filter will only work for a geopoint field.
181
181
  *
@@ -195,16 +195,16 @@ export const filter = {
195
195
  numberLessThan: pathWithArgsFilter<[value: number]>("number.lt"),
196
196
 
197
197
  /**
198
- * The `number.gt` filter checks that the value in the number field is
199
- * greater than the value passed into the filter.
198
+ * The `number.gt` filter checks that the value in the number field is greater
199
+ * than the value passed into the filter.
200
200
  *
201
201
  * {@link https://prismic.io/docs/rest-api-technical-reference#numbergreaterthan}
202
202
  */
203
203
  numberGreaterThan: pathWithArgsFilter<[value: number]>("number.gt"),
204
204
 
205
205
  /**
206
- * The `number.inRange` filter checks that the value in the path is within
207
- * the two values passed into the filter.
206
+ * The `number.inRange` filter checks that the value in the path is within the
207
+ * two values passed into the filter.
208
208
  *
209
209
  * {@link https://prismic.io/docs/rest-api-technical-reference#numberinrange}
210
210
  */
@@ -214,8 +214,8 @@ export const filter = {
214
214
  ),
215
215
 
216
216
  /**
217
- * The `date.after` filter checks that the value in the path is after the
218
- * date value passed into the filter.
217
+ * The `date.after` filter checks that the value in the path is after the date
218
+ * value passed into the filter.
219
219
  *
220
220
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
221
221
  */
@@ -230,8 +230,8 @@ export const filter = {
230
230
  dateBefore: pathWithArgsFilter<[date: string | number | Date]>("date.before"),
231
231
 
232
232
  /**
233
- * The `date.between` filter checks that the value in the path is within
234
- * the date values passed into the filter.
233
+ * The `date.between` filter checks that the value in the path is within the
234
+ * date values passed into the filter.
235
235
  *
236
236
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
237
237
  */
@@ -241,16 +241,16 @@ export const filter = {
241
241
  >("date.between"),
242
242
 
243
243
  /**
244
- * The `date.day-of-month` filter checks that the value in the path is
245
- * equal to the day of the month passed into the filter.
244
+ * The `date.day-of-month` filter checks that the value in the path is equal
245
+ * to the day of the month passed into the filter.
246
246
  *
247
247
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
248
248
  */
249
249
  dateDayOfMonth: pathWithArgsFilter<[day: number]>("date.day-of-month"),
250
250
 
251
251
  /**
252
- * The `date.day-of-month-after` filter checks that the value in the path
253
- * is after the day of the month passed into the filter.
252
+ * The `date.day-of-month-after` filter checks that the value in the path is
253
+ * after the day of the month passed into the filter.
254
254
  *
255
255
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
256
256
  */
@@ -259,8 +259,8 @@ export const filter = {
259
259
  ),
260
260
 
261
261
  /**
262
- * The `date.day-of-month-before` filter checks that the value in the path
263
- * is before the day of the month passed into the filter.
262
+ * The `date.day-of-month-before` filter checks that the value in the path is
263
+ * before the day of the month passed into the filter.
264
264
  *
265
265
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
266
266
  */
@@ -269,8 +269,8 @@ export const filter = {
269
269
  ),
270
270
 
271
271
  /**
272
- * The `date.day-of-week` filter checks that the value in the path is equal
273
- * to the day of the week passed into the filter.
272
+ * The `date.day-of-week` filter checks that the value in the path is equal to
273
+ * the day of the week passed into the filter.
274
274
  *
275
275
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
276
276
  */
@@ -305,8 +305,8 @@ export const filter = {
305
305
  dateMonth: pathWithArgsFilter<[month: string | number]>("date.month"),
306
306
 
307
307
  /**
308
- * The `date.month-after` filter checks that the value in the path occurs
309
- * in any month after the value passed into the filter.
308
+ * The `date.month-after` filter checks that the value in the path occurs in
309
+ * any month after the value passed into the filter.
310
310
  *
311
311
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
312
312
  */
@@ -314,8 +314,8 @@ export const filter = {
314
314
  pathWithArgsFilter<[month: string | number]>("date.month-after"),
315
315
 
316
316
  /**
317
- * The `date.month-before` filter checks that the value in the path occurs
318
- * in any month before the value passed into the filter.
317
+ * The `date.month-before` filter checks that the value in the path occurs in
318
+ * any month before the value passed into the filter.
319
319
  *
320
320
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
321
321
  */
@@ -323,24 +323,24 @@ export const filter = {
323
323
  pathWithArgsFilter<[month: string | number]>("date.month-before"),
324
324
 
325
325
  /**
326
- * The `date.year` filter checks that the value in the path occurs in the
327
- * year value passed into the filter.
326
+ * The `date.year` filter checks that the value in the path occurs in the year
327
+ * value passed into the filter.
328
328
  *
329
329
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
330
330
  */
331
331
  dateYear: pathWithArgsFilter<[year: number]>("date.year"),
332
332
 
333
333
  /**
334
- * The `date.hour` filter checks that the value in the path occurs within
335
- * the hour value passed into the filter.
334
+ * The `date.hour` filter checks that the value in the path occurs within the
335
+ * hour value passed into the filter.
336
336
  *
337
337
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
338
338
  */
339
339
  dateHour: pathWithArgsFilter<[hour: number]>("date.hour"),
340
340
 
341
341
  /**
342
- * The `date.hour-after` filter checks that the value in the path occurs
343
- * after the hour value passed into the filter.
342
+ * The `date.hour-after` filter checks that the value in the path occurs after
343
+ * the hour value passed into the filter.
344
344
  *
345
345
  * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}
346
346
  */
@@ -6,6 +6,7 @@ import { isRepositoryName } from "./isRepositoryName";
6
6
  * Get a repository's Prismic GraphQL endpoint.
7
7
  *
8
8
  * @typeParam RepositoryName - Name of the Prismic repository.
9
+ *
9
10
  * @param repositoryName - Name of the repository.
10
11
  *
11
12
  * @returns The repository's Prismic REST API V2 endpoint
@@ -6,9 +6,11 @@ import { isRepositoryName } from "./isRepositoryName";
6
6
  * Get a repository's Prismic Rest API V2 endpoint.
7
7
  *
8
8
  * @typeParam RepositoryName - Name of the Prismic repository.
9
+ *
9
10
  * @param repositoryName - Name of the repository.
10
11
  *
11
12
  * @returns The repository's Prismic Rest API V2 endpoint
13
+ *
12
14
  * @throws {@link Error} Thrown if an invalid repository name is provided.
13
15
  */
14
16
  export const getRepositoryEndpoint = <RepositoryName extends string>(
@@ -9,6 +9,7 @@ import { PrismicError } from "./errors/PrismicError";
9
9
  * @param repositoryEndpoint - Prismic Rest API V2 endpoint for the repository.
10
10
  *
11
11
  * @returns The Prismic repository's name.
12
+ *
12
13
  * @throws {@link Error} Thrown if an invalid Prismic Rest API V2 endpoint is
13
14
  * provided.
14
15
  */
@@ -12,7 +12,7 @@ import { isRepositoryName } from "./isRepositoryName";
12
12
  * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.
13
13
  *
14
14
  * import Script from "next/script";
15
- * import * as prismic from '@prismicio/client'
15
+ * import * as prismic from "@prismicio/client";
16
16
  *
17
17
  * export default function RootLayout({
18
18
  * children,
@@ -14,6 +14,7 @@ type AsDateReturnType<
14
14
  * @param dateOrTimestampField - A date or timestamp field from Prismic
15
15
  *
16
16
  * @returns A Date object, null if provided date is falsy
17
+ *
17
18
  * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}
18
19
  */
19
20
  export const asDate = <
@@ -106,7 +106,8 @@ type ExtractTextTypeGeneric<T> = T extends RichTextMapSerializerFunction<
106
106
  : never;
107
107
 
108
108
  /**
109
- * Serializes a node from a rich text or title field with a map or a function to HTML
109
+ * Serializes a node from a rich text or title field with a map or a function to
110
+ * HTML
110
111
  *
111
112
  * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}
112
113
  * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
@@ -116,8 +117,8 @@ export type HTMLRichTextSerializer =
116
117
  | HTMLRichTextFunctionSerializer;
117
118
 
118
119
  /**
119
- * Creates a default HTML rich text serializer with a given link resolver providing
120
- * sensible and safe defaults for every node type
120
+ * Creates a default HTML rich text serializer with a given link resolver
121
+ * providing sensible and safe defaults for every node type
121
122
  *
122
123
  * @internal
123
124
  */
@@ -205,13 +206,14 @@ const wrapMapSerializerWithStringChildren = (
205
206
  */
206
207
  type AsHTMLConfig = {
207
208
  /**
208
- * An optional link resolver function to resolve links.
209
- * Without it you're expected to use the `routes` options from the API.
209
+ * An optional link resolver function to resolve links. Without it you're
210
+ * expected to use the `routes` options from the API.
210
211
  */
211
212
  linkResolver?: LinkResolverFunction | null;
212
213
 
213
214
  /**
214
- * An optional rich text serializer, unhandled cases will fallback to the default serializer
215
+ * An optional rich text serializer, unhandled cases will fallback to the
216
+ * default serializer
215
217
  */
216
218
  serializer?: HTMLRichTextSerializer | null;
217
219
  };
@@ -236,10 +238,20 @@ export const asHTML: {
236
238
  /**
237
239
  * Serializes a rich text or title field to an HTML string.
238
240
  *
241
+ * @example
242
+ *
243
+ * ```ts
244
+ * asHTML(field);
245
+ * asHTML(field, { linkResolver });
246
+ * asHTML(field, { serializer });
247
+ * asHTML(field, { linkResolver, serializer });
248
+ * ```
249
+ *
239
250
  * @param richTextField - A rich text or title field from Prismic
240
251
  * @param config - Configuration that determines the output of `asHTML()`
241
252
  *
242
253
  * @returns HTML equivalent of the provided rich text or title field
254
+ *
243
255
  * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
244
256
  */
245
257
  <Field extends RichTextField | null | undefined>(
@@ -250,23 +262,17 @@ export const asHTML: {
250
262
  /**
251
263
  * Serializes a rich text or title field to an HTML string.
252
264
  *
265
+ * @deprecated Use object-style configuration instead.
266
+ *
253
267
  * @param richTextField - A rich text or title field from Prismic
254
268
  * @param linkResolver - An optional link resolver function to resolve links,
255
269
  * without it you're expected to use the `routes` options from the API
256
- * @param serializer - An optional rich text serializer, unhandled cases will fallback
257
- * to the default serializer
270
+ * @param serializer - An optional rich text serializer, unhandled cases will
271
+ * fallback to the default serializer
258
272
  *
259
273
  * @returns HTML equivalent of the provided rich text or title field
260
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
261
- *
262
- * @deprecated Use object-style configuration instead.
263
274
  *
264
- * ```ts
265
- * asHTML(field);
266
- * asHTML(field, { linkResolver });
267
- * asHTML(field, { serializer });
268
- * asHTML(field, { linkResolver, serializer });
269
- * ```
275
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
270
276
  */
271
277
  <Field extends RichTextField | null | undefined>(
272
278
  richTextField: Field,
@@ -13,6 +13,7 @@ import { documentToLinkField } from "./documentToLinkField";
13
13
  * @param linkToDocumentField - A document link field to resolve
14
14
  *
15
15
  * @returns Resolved URL
16
+ *
16
17
  * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
17
18
  */
18
19
  export type LinkResolverFunction<ReturnType = string | null | undefined> = (
@@ -25,8 +26,8 @@ export type LinkResolverFunction<ReturnType = string | null | undefined> = (
25
26
  type AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =
26
27
  {
27
28
  /**
28
- * An optional link resolver function. Without it, you are
29
- * expected to use the `routes` options from the API.
29
+ * An optional link resolver function. Without it, you are expected to use
30
+ * the `routes` options from the API.
30
31
  */
31
32
  linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null;
32
33
  };
@@ -64,13 +65,23 @@ export const asLink: {
64
65
  /**
65
66
  * Resolves any type of link field or Prismic document to a URL.
66
67
  *
68
+ * @example
69
+ *
70
+ * ```ts
71
+ * asLink(field);
72
+ * asLink(field, { linkResolver });
73
+ * ```
74
+ *
67
75
  * @typeParam LinkResolverFunctionReturnType - link resolver function return
68
76
  * type
69
77
  * @typeParam Field - Link field or Prismic document to resolve to a URL
70
- * @param linkFieldOrDocument - Any kind of link field or a document to resolve
78
+ *
79
+ * @param linkFieldOrDocument - Any kind of link field or a document to
80
+ * resolve
71
81
  * @param config - Configuration that determines the output of `asLink()`
72
82
  *
73
- * @returns Resolved URL or, if the provided link field or document is empty, `null`
83
+ * @returns Resolved URL or, if the provided link field or document is empty,
84
+ * `null`
74
85
  * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
75
86
  * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
76
87
  */
@@ -89,23 +100,21 @@ export const asLink: {
89
100
  /**
90
101
  * Resolves any type of link field or Prismic document to a URL.
91
102
  *
103
+ * @deprecated Use object-style configuration instead.
104
+ *
92
105
  * @typeParam LinkResolverFunctionReturnType - link resolver function return
93
106
  * type
94
107
  * @typeParam Field - Link field or Prismic document to resolve to a URL
95
- * @param linkFieldOrDocument - Any kind of link field or a document to resolve
96
- * @param linkResolver - An optional link resolver function. Without it, you are
97
- * expected to use the `routes` options from the API
98
108
  *
99
- * @returns Resolved URL or, if the provided link field or document is empty, `null`
109
+ * @param linkFieldOrDocument - Any kind of link field or a document to
110
+ * resolve
111
+ * @param linkResolver - An optional link resolver function. Without it, you
112
+ * are expected to use the `routes` options from the API
113
+ *
114
+ * @returns Resolved URL or, if the provided link field or document is empty,
115
+ * `null`
100
116
  * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
101
117
  * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
102
- *
103
- * @deprecated Use object-style configuration instead.
104
- *
105
- * ```ts
106
- * asLink(field);
107
- * asLink(field, { linkResolver });
108
- * ```
109
118
  */
110
119
  <
111
120
  LinkResolverFunctionReturnType = string | null | undefined,
@@ -66,17 +66,22 @@ type AsLinkAttrsReturnType<
66
66
  };
67
67
 
68
68
  /**
69
- * Resolves any type of link field or Prismic document to a set of link attributes. The attributes are designed to be passed to link HTML elements, like `<a>`.
69
+ * Resolves any type of link field or Prismic document to a set of link
70
+ * attributes. The attributes are designed to be passed to link HTML elements,
71
+ * like `<a>`.
70
72
  *
71
- * If a resolved URL is external (i.e. starts with a protocol like `https://`), `rel` is returned as `"noreferrer"`.
73
+ * If a resolved URL is external (i.e. starts with a protocol like `https://`),
74
+ * `rel` is returned as `"noreferrer"`.
72
75
  *
73
76
  * @typeParam LinkResolverFunctionReturnType - link resolver function return
74
77
  * type
75
- * @typeParam Field - Link field or Prismic document to resolve to link attributes
78
+ * @typeParam Field - Link field or Prismic document to resolve to link
79
+ * attributes
76
80
  * @param linkFieldOrDocument - Any kind of link field or a document to resolve
77
81
  * @param config - Configuration that determines the output of `asLinkAttrs()`
78
82
  *
79
- * @returns Resolved set of link attributes or, if the provided link field or document is empty, and empty object
83
+ * @returns Resolved set of link attributes or, if the provided link field or
84
+ * document is empty, and empty object
80
85
  * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
81
86
  * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
82
87
  */
@@ -30,10 +30,18 @@ export const asText: {
30
30
  /**
31
31
  * Serializes a rich text or title field to a plain text string.
32
32
  *
33
+ * @example
34
+ *
35
+ * ```ts
36
+ * asText(field);
37
+ * asText(field, { separator });
38
+ * ```
39
+ *
33
40
  * @param richTextField - A rich text or title field from Prismic
34
41
  * @param config - Configuration that determines the output of `asText()`
35
42
  *
36
43
  * @returns Plain text equivalent of the provided rich text or title field
44
+ *
37
45
  * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
38
46
  */
39
47
  <Field extends RichTextField | null | undefined>(
@@ -44,18 +52,14 @@ export const asText: {
44
52
  /**
45
53
  * Serializes a rich text or title field to a plain text string.
46
54
  *
55
+ * @deprecated Use object-style configuration instead.
56
+ *
47
57
  * @param richTextField - A rich text or title field from Prismic
48
58
  * @param separator - Separator used to join each element, defaults to a space
49
59
  *
50
60
  * @returns Plain text equivalent of the provided rich text or title field
51
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
52
- *
53
- * @deprecated Use object-style configuration instead.
54
61
  *
55
- * ```ts
56
- * asText(field);
57
- * asText(field, { separator });
58
- * ```
62
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
59
63
  */
60
64
  <Field extends RichTextField | null | undefined>(
61
65
  richTextField: Field,
@@ -10,9 +10,11 @@ type SetOptional<T, Keys extends keyof T> = Omit<T, Keys> &
10
10
  * for document links
11
11
  *
12
12
  * @typeParam TDocument - Specific interface of the provided document
13
+ *
13
14
  * @param prismicDocument - A document coming from Prismic
14
15
  *
15
16
  * @returns The equivalent link field to use with `asLink()`
17
+ *
16
18
  * @internal
17
19
  */
18
20
  export const documentToLinkField = <
package/src/index.ts CHANGED
@@ -46,6 +46,7 @@ export type {
46
46
  FetchLike,
47
47
  HttpRequestLike,
48
48
  RequestInitLike,
49
+ RequestInitLikeOrThunk,
49
50
  ResponseLike,
50
51
  } from "./createClient";
51
52
  export type {
@@ -5,12 +5,12 @@ interface WithFilters {
5
5
  }
6
6
 
7
7
  /**
8
- * Adds one or more filters to an object with a `filters` property.
9
- * Appended filters are added to the end of the existing list.
8
+ * Adds one or more filters to an object with a `filters` property. Appended
9
+ * filters are added to the end of the existing list.
10
10
  *
11
11
  * @typeParam T - Object to which filters will be append.
12
- * @param objWithFilters - Object to append filters on the `filters`
13
- * property.
12
+ *
13
+ * @param objWithFilters - Object to append filters on the `filters` property.
14
14
  * @param filters - One or more filters to append.
15
15
  *
16
16
  * @returns The object with the appended filters.
@@ -4,6 +4,7 @@
4
4
  * only element.
5
5
  *
6
6
  * @typeParam A - Element of the array.
7
+ *
7
8
  * @param a - Value to ensure is an array.
8
9
  *
9
10
  * @returns `a` as an array.
@@ -3,10 +3,17 @@
3
3
  * is. If it is not a thunk, it is converted to a thunk.
4
4
  *
5
5
  * @typeParam A - Value returned by the thunk.
6
+ *
6
7
  * @param a - Value to ensure is a thunk.
7
8
  *
8
9
  * @returns `a` as a a thunk.
9
10
  */
10
- export const castThunk = <A>(a: A | (() => A)): (() => A) => {
11
- return typeof a === "function" ? (a as () => A) : () => a;
11
+ export const castThunk = <
12
+ A,
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ TArgs extends any[],
15
+ >(
16
+ a: A | ((...args: TArgs) => A),
17
+ ): ((...args: TArgs) => A) => {
18
+ return typeof a === "function" ? (a as (...args: TArgs) => A) : () => a;
12
19
  };
@@ -3,8 +3,8 @@ import { filter } from "../filter";
3
3
  import { castArray } from "./castArray";
4
4
 
5
5
  /**
6
- * Creates a filter to filter content by document tags. All tags are required
7
- * on the document.
6
+ * Creates a filter to filter content by document tags. All tags are required on
7
+ * the document.
8
8
  *
9
9
  * @param tags - Document tags to filter queried content.
10
10
  *
@@ -8,6 +8,7 @@ import { findRef } from "./findRef";
8
8
  * @param refs - A list of refs to search.
9
9
  *
10
10
  * @returns The master ref from the list.
11
+ *
11
12
  * @throws If a matching ref cannot be found.
12
13
  */
13
14
  export const findMasterRef = (refs: Ref[]): Ref => {
@@ -7,10 +7,11 @@ import { PrismicError } from "../errors/PrismicError";
7
7
  * returns true).
8
8
  *
9
9
  * @param refs - A list of refs to search.
10
- * @param filter - A function that determines if a ref from the list matches
11
- * the criteria.
10
+ * @param filter - A function that determines if a ref from the list matches the
11
+ * criteria.
12
12
  *
13
13
  * @returns The first matching ref.
14
+ *
14
15
  * @throws If a matching ref cannot be found.
15
16
  */
16
17
  export const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {
@@ -9,6 +9,7 @@ import { findRef } from "./findRef";
9
9
  * @param id - The ID of the ref to find.
10
10
  *
11
11
  * @returns The ref with a matching ID from the list.
12
+ *
12
13
  * @throws If a matching ref cannot be found.
13
14
  */
14
15
  export const findRefByID = (refs: Ref[], id: string): Ref => {
@@ -9,6 +9,7 @@ import { findRef } from "./findRef";
9
9
  * @param id - The label of the ref to find.
10
10
  *
11
11
  * @returns The ref with a matching label from the list.
12
+ *
12
13
  * @throws If a matching ref cannot be found.
13
14
  */
14
15
  export const findRefByLabel = (refs: Ref[], label: string): Ref => {
@@ -5,6 +5,7 @@ import { PrismicDocument } from "../value/document";
5
5
  * paginated metadata and a list of matching results for the query.
6
6
  *
7
7
  * @typeParam Document - The type(s) of Prismic document that can be returned.
8
+ *
8
9
  * @see More details on querying: {@link https://prismic.io/docs/api}
9
10
  */
10
11
  export interface Query<Document extends PrismicDocument = PrismicDocument> {
@@ -5,6 +5,7 @@ import { Ref } from "./ref";
5
5
  *
6
6
  * @remarks
7
7
  * This is an alias for `Ref`.
8
+ *
8
9
  * @see {@link Ref}
9
10
  * @see More details on Releases: {@link https://prismic.io/docs/guides/draft-plan-and-schedule-content#releases}
10
11
  */
@@ -3,6 +3,7 @@
3
3
  * sending a `GET` request to a repository's `/api/tags` endpoint.
4
4
  *
5
5
  * @typeParam Tag - Tags that are returned by the Tags API.
6
+ *
6
7
  * @see More details on the Tags API: {@link https://prismic.io/docs/tags-api-technical-reference}
7
8
  */
8
9
  export type Tags<Tag extends string = string> = Tag[];
@@ -5,8 +5,7 @@ import type { CustomTypeModelLinkSelectType } from "./link";
5
5
  /**
6
6
  * A content relationship custom type field.
7
7
  *
8
- * More details:
9
- * {@link https://prismic.io/docs/content-relationship}
8
+ * More details: {@link https://prismic.io/docs/content-relationship}
10
9
  */
11
10
  export interface CustomTypeModelContentRelationshipField<
12
11
  CustomTypeIDs extends string = string,