@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.
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +11 -10
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs +39 -6
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +68 -21
- package/dist/createClient.js +39 -6
- package/dist/createClient.js.map +1 -1
- package/dist/filter.cjs +38 -38
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.d.ts +38 -38
- package/dist/filter.js +38 -38
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.d.ts +1 -0
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +2 -0
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.d.ts +1 -0
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.d.ts +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +1 -0
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +21 -15
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +24 -15
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +9 -4
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +11 -7
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.d.ts +2 -0
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/appendFilters.cjs.map +1 -1
- package/dist/lib/appendFilters.d.ts +4 -4
- package/dist/lib/appendFilters.js.map +1 -1
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.d.ts +1 -0
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.d.ts +2 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/everyTagFilter.cjs.map +1 -1
- package/dist/lib/everyTagFilter.d.ts +2 -2
- package/dist/lib/everyTagFilter.js.map +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +1 -0
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +3 -2
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +1 -0
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +1 -0
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/types/api/query.d.ts +1 -0
- package/dist/types/api/release.d.ts +1 -0
- package/dist/types/api/tags.d.ts +1 -0
- package/dist/types/model/contentRelationship.d.ts +1 -2
- package/dist/types/model/link.cjs.map +1 -1
- package/dist/types/model/link.d.ts +2 -4
- package/dist/types/model/link.js.map +1 -1
- package/dist/types/model/linkToMedia.d.ts +1 -2
- package/dist/types/value/color.d.ts +1 -0
- package/dist/types/value/date.d.ts +1 -0
- package/dist/types/value/embed.cjs.map +1 -1
- package/dist/types/value/embed.d.ts +1 -0
- package/dist/types/value/embed.js.map +1 -1
- package/dist/types/value/geoPoint.d.ts +1 -0
- package/dist/types/value/image.d.ts +2 -0
- package/dist/types/value/integration.d.ts +1 -0
- package/dist/types/value/keyText.d.ts +1 -0
- package/dist/types/value/number.d.ts +1 -0
- package/dist/types/value/select.d.ts +1 -0
- package/dist/types/value/types.d.ts +1 -0
- package/package.json +3 -3
- package/src/buildQueryURL.ts +11 -10
- package/src/createClient.ts +85 -28
- package/src/filter.ts +42 -42
- package/src/getGraphQLEndpoint.ts +1 -0
- package/src/getRepositoryEndpoint.ts +2 -0
- package/src/getRepositoryName.ts +1 -0
- package/src/getToolbarSrc.ts +1 -1
- package/src/helpers/asDate.ts +1 -0
- package/src/helpers/asHTML.ts +23 -17
- package/src/helpers/asLink.ts +24 -15
- package/src/helpers/asLinkAttrs.ts +9 -4
- package/src/helpers/asText.ts +11 -7
- package/src/helpers/documentToLinkField.ts +2 -0
- package/src/index.ts +1 -0
- package/src/lib/appendFilters.ts +4 -4
- package/src/lib/castArray.ts +1 -0
- package/src/lib/castThunk.ts +9 -2
- package/src/lib/everyTagFilter.ts +2 -2
- package/src/lib/findMasterRef.ts +1 -0
- package/src/lib/findRef.ts +3 -2
- package/src/lib/findRefByID.ts +1 -0
- package/src/lib/findRefByLabel.ts +1 -0
- package/src/types/api/query.ts +1 -0
- package/src/types/api/release.ts +1 -0
- package/src/types/api/tags.ts +1 -0
- package/src/types/model/contentRelationship.ts +1 -2
- package/src/types/model/link.ts +2 -4
- package/src/types/model/linkToMedia.ts +1 -2
- package/src/types/value/color.ts +1 -0
- package/src/types/value/date.ts +1 -0
- package/src/types/value/embed.ts +1 -0
- package/src/types/value/geoPoint.ts +1 -0
- package/src/types/value/image.ts +2 -0
- package/src/types/value/integration.ts +1 -0
- package/src/types/value/keyText.ts +1 -0
- package/src/types/value/number.ts +1 -0
- package/src/types/value/select.ts +1 -0
- 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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
131
|
-
*
|
|
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
|
-
*
|
|
152
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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>(
|
package/src/getRepositoryName.ts
CHANGED
|
@@ -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
|
*/
|
package/src/getToolbarSrc.ts
CHANGED
|
@@ -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
|
|
15
|
+
* import * as prismic from "@prismicio/client";
|
|
16
16
|
*
|
|
17
17
|
* export default function RootLayout({
|
|
18
18
|
* children,
|
package/src/helpers/asDate.ts
CHANGED
|
@@ -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 = <
|
package/src/helpers/asHTML.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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,
|
package/src/helpers/asLink.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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,
|
|
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
|
-
* @
|
|
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
|
|
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://`),
|
|
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
|
|
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
|
|
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
|
*/
|
package/src/helpers/asText.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
package/src/lib/appendFilters.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
13
|
-
*
|
|
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.
|
package/src/lib/castArray.ts
CHANGED
package/src/lib/castThunk.ts
CHANGED
|
@@ -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 = <
|
|
11
|
-
|
|
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
|
-
*
|
|
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
|
*
|
package/src/lib/findMasterRef.ts
CHANGED
package/src/lib/findRef.ts
CHANGED
|
@@ -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
|
-
*
|
|
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 => {
|
package/src/lib/findRefByID.ts
CHANGED
|
@@ -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 => {
|
package/src/types/api/query.ts
CHANGED
|
@@ -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> {
|
package/src/types/api/release.ts
CHANGED
package/src/types/api/tags.ts
CHANGED
|
@@ -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,
|