@prismicio/client 7.21.0-alpha.1 → 7.21.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/Client.cjs +120 -132
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.ts +7 -7
- package/dist/Client.js +120 -132
- package/dist/Client.js.map +1 -1
- package/dist/Migration.cjs +83 -101
- package/dist/Migration.cjs.map +1 -1
- package/dist/Migration.d.ts +9 -9
- package/dist/Migration.js +83 -101
- package/dist/Migration.js.map +1 -1
- package/dist/WriteClient.cjs +113 -98
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.ts +6 -6
- package/dist/WriteClient.js +113 -98
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +29 -21
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +13 -10
- package/dist/createClient.js.map +1 -1
- package/dist/createMigration.cjs.map +1 -1
- package/dist/createMigration.d.ts +2 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createWriteClient.cjs.map +1 -1
- package/dist/createWriteClient.d.ts +2 -2
- package/dist/errors/ForbiddenError.d.ts +1 -1
- package/dist/errors/InvalidDataError.d.ts +1 -1
- package/dist/errors/NotFoundError.d.ts +1 -1
- package/dist/errors/ParsingError.d.ts +1 -1
- package/dist/errors/PreviewTokenExpired.d.ts +1 -1
- package/dist/errors/PrismicError.cjs +2 -5
- package/dist/errors/PrismicError.cjs.map +1 -1
- package/dist/errors/PrismicError.js +2 -5
- package/dist/errors/PrismicError.js.map +1 -1
- package/dist/errors/RefExpiredError.d.ts +1 -1
- package/dist/errors/RefNotFoundError.d.ts +1 -1
- package/dist/errors/RepositoryNotFoundError.d.ts +1 -1
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +9 -2
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +13 -6
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs +22 -22
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +37 -29
- package/dist/helpers/asHTML.js +22 -22
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +17 -16
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +12 -11
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +19 -18
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +36 -35
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +11 -14
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +21 -11
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs +1 -2
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.d.ts +2 -2
- package/dist/helpers/documentToLinkField.js +1 -2
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.ts +35 -34
- package/dist/helpers/isFilled.js +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +11 -11
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +121 -120
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +2 -2
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.js.map +1 -1
- package/dist/lib/appendFilters.cjs.map +1 -1
- package/dist/lib/appendFilters.js.map +1 -1
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js.map +1 -1
- package/dist/lib/everyTagFilter.cjs.map +1 -1
- package/dist/lib/everyTagFilter.js.map +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +1 -1
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +1 -1
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +1 -1
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +1 -1
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
- package/dist/lib/getOptionalLinkProperties.d.ts +1 -1
- package/dist/lib/getOptionalLinkProperties.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js.map +1 -1
- package/dist/lib/isMigrationValue.cjs.map +1 -1
- package/dist/lib/isMigrationValue.d.ts +8 -8
- package/dist/lib/isMigrationValue.js.map +1 -1
- package/dist/lib/isValue.cjs.map +1 -1
- package/dist/lib/isValue.d.ts +10 -10
- package/dist/lib/isValue.js.map +1 -1
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
- package/dist/lib/minifyGraphQLQuery.js.map +1 -1
- package/dist/lib/pLimit.cjs +3 -4
- package/dist/lib/pLimit.cjs.map +1 -1
- package/dist/lib/pLimit.js +3 -4
- package/dist/lib/pLimit.js.map +1 -1
- package/dist/lib/request.cjs +8 -10
- package/dist/lib/request.cjs.map +1 -1
- package/dist/lib/request.js +8 -10
- package/dist/lib/request.js.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.cjs +4 -6
- package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.d.ts +8 -8
- package/dist/lib/resolveMigrationDocumentData.js +4 -6
- package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +2 -2
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.d.ts +3 -3
- package/dist/lib/serializerHelpers.js +2 -2
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/someTagsFilter.cjs.map +1 -1
- package/dist/lib/someTagsFilter.js.map +1 -1
- package/dist/lib/throttledLog.cjs.map +1 -1
- package/dist/lib/throttledLog.js.map +1 -1
- package/dist/lib/typeFilter.cjs.map +1 -1
- package/dist/lib/typeFilter.js.map +1 -1
- package/dist/lib/validateAssetMetadata.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.d.ts +1 -1
- package/dist/lib/validateAssetMetadata.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.ts +6 -6
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.d.ts +2 -2
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.d.ts +1 -1
- package/dist/richtext/composeSerializers.js.map +1 -1
- package/dist/richtext/index.d.ts +7 -7
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.ts +10 -10
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.ts +7 -7
- package/dist/richtext/types.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.ts +1 -1
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/types/api/asset/asset.d.ts +1 -1
- package/dist/types/api/integration.d.ts +1 -1
- package/dist/types/api/migration/document.d.ts +1 -1
- package/dist/types/api/query.d.ts +1 -1
- package/dist/types/api/release.d.ts +1 -1
- package/dist/types/api/repository.d.ts +1 -1
- package/dist/types/migration/Asset.cjs +12 -15
- package/dist/types/migration/Asset.cjs.map +1 -1
- package/dist/types/migration/Asset.d.ts +7 -7
- package/dist/types/migration/Asset.js +12 -15
- package/dist/types/migration/Asset.js.map +1 -1
- package/dist/types/migration/ContentRelationship.d.ts +3 -3
- package/dist/types/migration/Document.cjs +24 -27
- package/dist/types/migration/Document.cjs.map +1 -1
- package/dist/types/migration/Document.d.ts +9 -9
- package/dist/types/migration/Document.js +24 -27
- package/dist/types/migration/Document.js.map +1 -1
- package/dist/types/migration/Link.d.ts +1 -1
- package/dist/types/model/boolean.d.ts +1 -1
- package/dist/types/model/color.d.ts +1 -1
- package/dist/types/model/contentRelationship.d.ts +3 -2
- package/dist/types/model/customType.d.ts +1 -1
- package/dist/types/model/date.d.ts +1 -1
- package/dist/types/model/embed.d.ts +1 -1
- package/dist/types/model/geoPoint.d.ts +1 -1
- package/dist/types/model/group.d.ts +1 -1
- package/dist/types/model/image.d.ts +1 -1
- package/dist/types/model/integration.d.ts +1 -1
- package/dist/types/model/keyText.d.ts +1 -1
- package/dist/types/model/link.d.ts +1 -1
- package/dist/types/model/linkToMedia.d.ts +2 -2
- package/dist/types/model/number.d.ts +1 -1
- package/dist/types/model/range.d.ts +1 -1
- package/dist/types/model/richText.d.ts +1 -1
- package/dist/types/model/select.d.ts +1 -1
- package/dist/types/model/separator.d.ts +1 -1
- package/dist/types/model/sharedSlice.d.ts +2 -2
- package/dist/types/model/sharedSliceVariation.d.ts +1 -1
- package/dist/types/model/slice.d.ts +3 -3
- package/dist/types/model/sliceZone.d.ts +2 -2
- package/dist/types/model/table.d.ts +1 -1
- package/dist/types/model/timestamp.d.ts +1 -1
- package/dist/types/model/title.d.ts +1 -1
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.d.ts +22 -23
- package/dist/types/model/types.js.map +1 -1
- package/dist/types/model/uid.d.ts +1 -1
- package/dist/types/value/color.d.ts +1 -1
- package/dist/types/value/contentRelationship.d.ts +3 -3
- package/dist/types/value/date.d.ts +1 -1
- package/dist/types/value/document.d.ts +4 -4
- package/dist/types/value/embed.d.ts +1 -1
- package/dist/types/value/geoPoint.d.ts +1 -1
- package/dist/types/value/group.d.ts +1 -1
- package/dist/types/value/image.d.ts +1 -1
- package/dist/types/value/integration.d.ts +1 -1
- package/dist/types/value/keyText.d.ts +1 -1
- package/dist/types/value/link.d.ts +5 -5
- package/dist/types/value/linkToMedia.d.ts +2 -2
- package/dist/types/value/number.d.ts +1 -1
- package/dist/types/value/richText.d.ts +3 -3
- package/dist/types/value/select.d.ts +1 -1
- package/dist/types/value/sharedSlice.d.ts +1 -1
- package/dist/types/value/sharedSliceVariation.d.ts +1 -1
- package/dist/types/value/slice.d.ts +1 -1
- package/dist/types/value/sliceZone.d.ts +3 -3
- package/dist/types/value/table.d.ts +2 -2
- package/dist/types/value/timestamp.d.ts +2 -2
- package/dist/types/value/title.d.ts +2 -2
- package/dist/types/value/types.d.ts +18 -18
- package/dist/types/webhook/apiUpdate.d.ts +1 -1
- package/dist/types/webhook/testTrigger.d.ts +1 -1
- package/dist/types/webhook/types.d.ts +2 -2
- package/package.json +11 -11
- package/src/WriteClient.ts +21 -32
- package/src/buildQueryURL.ts +29 -21
- package/src/createClient.ts +11 -8
- package/src/getRepositoryEndpoint.ts +9 -2
- package/src/helpers/asDate.ts +11 -4
- package/src/helpers/asHTML.ts +34 -26
- package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
- package/src/helpers/asImageSrc.ts +11 -10
- package/src/helpers/asImageWidthSrcSet.ts +18 -17
- package/src/helpers/asLink.ts +33 -32
- package/src/helpers/asLinkAttrs.ts +6 -9
- package/src/helpers/asText.ts +20 -10
- package/src/helpers/isFilled.ts +15 -14
- package/src/helpers/mapSliceZone.ts +10 -10
- package/src/index.ts +3 -2
- package/src/isRepositoryEndpoint.ts +2 -2
- package/src/richtext/asText.ts +5 -5
- package/src/richtext/serialize.ts +8 -8
- package/src/richtext/types.ts +6 -6
- package/src/types/migration/Asset.ts +10 -2
- package/src/types/model/contentRelationship.ts +1 -0
- package/src/types/model/types.ts +0 -2
|
@@ -19,13 +19,13 @@ type AsImageWidthSrcSetReturnType<
|
|
|
19
19
|
Field extends ImageFieldImage<"filled">
|
|
20
20
|
? {
|
|
21
21
|
/**
|
|
22
|
-
* The image field's
|
|
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
|
|
28
|
-
*
|
|
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
|
|
43
|
+
* transformations via imgix URL parameters.
|
|
44
44
|
*
|
|
45
|
-
* If a `widths` parameter is not given, the following widths
|
|
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.
|
|
55
|
+
* const srcset = asImageWidthSrcSet(document.data.photo, {
|
|
56
56
|
* widths: [400, 800, 1600],
|
|
57
57
|
* sat: -100,
|
|
58
58
|
* })
|
|
59
59
|
* // => {
|
|
60
|
-
* // src:
|
|
61
|
-
* // srcset:
|
|
62
|
-
* //
|
|
63
|
-
* //
|
|
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 -
|
|
68
|
-
* an image URL.
|
|
69
|
-
* @param config - An object of
|
|
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
|
|
74
|
-
* parameters
|
|
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
|
|
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,
|
package/src/helpers/asLink.ts
CHANGED
|
@@ -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
|
|
10
|
+
* Resolves a link to a Prismic page to a URL.
|
|
11
11
|
*
|
|
12
|
-
* @typeParam ReturnType - Return type of your link resolver function
|
|
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
|
|
15
|
+
* @param linkToDocumentField - A page link field to resolve.
|
|
16
16
|
*
|
|
17
|
-
* @returns Resolved URL
|
|
17
|
+
* @returns Resolved URL.
|
|
18
18
|
*
|
|
19
|
-
* @see
|
|
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
|
|
32
|
-
* the `routes`
|
|
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
|
-
*
|
|
66
|
+
* Converts any type of link field or Prismic page to a URL.
|
|
67
67
|
*
|
|
68
|
-
* @
|
|
69
|
-
* type
|
|
70
|
-
* @typeParam Field - Link field or Prismic document to resolve to a URL
|
|
68
|
+
* @example
|
|
71
69
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* const url = asLink(document.data.link)
|
|
72
|
+
* // => "/blog/my-post"
|
|
73
|
+
* ```
|
|
75
74
|
*
|
|
76
|
-
* @
|
|
77
|
-
*
|
|
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
|
-
* @
|
|
80
|
-
* @
|
|
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
|
-
*
|
|
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 -
|
|
100
|
-
* type
|
|
101
|
-
* @typeParam Field - Link field or Prismic
|
|
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
|
|
104
|
-
*
|
|
105
|
-
*
|
|
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
|
|
109
|
-
* `null`
|
|
111
|
+
* @returns Resolved URL, or `null` if the link field or page is empty.
|
|
110
112
|
*
|
|
111
|
-
* @see
|
|
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
|
|
199
|
+
// When empty or route resolver and link resolver are not used...
|
|
199
200
|
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>
|
|
200
201
|
}
|
|
201
202
|
|
|
@@ -67,26 +67,23 @@ type AsLinkAttrsReturnType<
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* Resolves any type of link field or Prismic
|
|
71
|
-
*
|
|
72
|
-
* like `<a>`.
|
|
70
|
+
* Resolves any type of link field or Prismic page to a set of link attributes.
|
|
71
|
+
* The attributes are designed to be passed to link HTML elements, like `<a>`.
|
|
73
72
|
*
|
|
74
73
|
* If a resolved URL is external (i.e. starts with a protocol like `https://`),
|
|
75
74
|
* `rel` is returned as `"noreferrer"`.
|
|
76
75
|
*
|
|
77
76
|
* @typeParam LinkResolverFunctionReturnType - link resolver function return
|
|
78
77
|
* type
|
|
79
|
-
* @typeParam Field - Link field or Prismic
|
|
80
|
-
* attributes
|
|
78
|
+
* @typeParam Field - Link field or Prismic page to resolve to link attributes
|
|
81
79
|
*
|
|
82
|
-
* @param linkFieldOrDocument - Any kind of link field or a
|
|
80
|
+
* @param linkFieldOrDocument - Any kind of link field or a page to resolve
|
|
83
81
|
* @param config - Configuration that determines the output of `asLinkAttrs()`
|
|
84
82
|
*
|
|
85
83
|
* @returns Resolved set of link attributes or, if the provided link field or
|
|
86
|
-
*
|
|
84
|
+
* page is empty, and empty object
|
|
87
85
|
*
|
|
88
|
-
* @see
|
|
89
|
-
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
86
|
+
* @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
|
|
90
87
|
*/
|
|
91
88
|
export const asLinkAttrs = <
|
|
92
89
|
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
package/src/helpers/asText.ts
CHANGED
|
@@ -28,14 +28,22 @@ type AsTextReturnType<Field extends RichTextField | null | undefined> =
|
|
|
28
28
|
|
|
29
29
|
export const asText: {
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Converts a rich text field to a plain text string.
|
|
32
32
|
*
|
|
33
|
-
* @
|
|
34
|
-
* @param config - Configuration that determines the output of `asText()`
|
|
33
|
+
* @example
|
|
35
34
|
*
|
|
36
|
-
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const text = asText(document.data.content)
|
|
37
|
+
* // => "Hello world"
|
|
38
|
+
* ```
|
|
37
39
|
*
|
|
38
|
-
* @
|
|
40
|
+
* @param richTextField - A rich text field from Prismic.
|
|
41
|
+
* @param config - Configuration that determines the output of `asText()`.
|
|
42
|
+
*
|
|
43
|
+
* @returns Plain text equivalent of the rich text field, or `null` if the
|
|
44
|
+
* field is empty.
|
|
45
|
+
*
|
|
46
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
39
47
|
*/
|
|
40
48
|
<Field extends RichTextField | null | undefined>(
|
|
41
49
|
richTextField: Field,
|
|
@@ -43,16 +51,18 @@ export const asText: {
|
|
|
43
51
|
): AsTextReturnType<Field>
|
|
44
52
|
|
|
45
53
|
/**
|
|
46
|
-
*
|
|
54
|
+
* Converts a rich text field to a plain text string.
|
|
47
55
|
*
|
|
48
56
|
* @deprecated Use object-style configuration instead.
|
|
49
57
|
*
|
|
50
|
-
* @param richTextField - A rich text
|
|
51
|
-
* @param separator - Separator used to join each element
|
|
58
|
+
* @param richTextField - A rich text field from Prismic.
|
|
59
|
+
* @param separator - Separator used to join each element. Defaults to a
|
|
60
|
+
* space.
|
|
52
61
|
*
|
|
53
|
-
* @returns Plain text equivalent of the
|
|
62
|
+
* @returns Plain text equivalent of the rich text field, or `null` if the
|
|
63
|
+
* field is empty.
|
|
54
64
|
*
|
|
55
|
-
* @see
|
|
65
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
56
66
|
*/
|
|
57
67
|
<Field extends RichTextField | null | undefined>(
|
|
58
68
|
richTextField: Field,
|
package/src/helpers/isFilled.ts
CHANGED
|
@@ -81,11 +81,11 @@ export const title = richText as (
|
|
|
81
81
|
) => field is TitleField<"filled">
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
* Determines if an
|
|
84
|
+
* Determines if an image thumbnail is filled.
|
|
85
85
|
*
|
|
86
86
|
* @param thumbnail - Image thumbnail to check.
|
|
87
87
|
*
|
|
88
|
-
* @returns `true` if
|
|
88
|
+
* @returns `true` if the thumbnail is filled, `false` otherwise.
|
|
89
89
|
*/
|
|
90
90
|
export const imageThumbnail = (
|
|
91
91
|
thumbnail: ImageFieldImage | null | undefined,
|
|
@@ -139,9 +139,9 @@ export const linkToMedia = link as (
|
|
|
139
139
|
/**
|
|
140
140
|
* Determines if a content relationship field is filled.
|
|
141
141
|
*
|
|
142
|
-
* @param field - Content
|
|
142
|
+
* @param field - Content relationship field to check.
|
|
143
143
|
*
|
|
144
|
-
* @returns `true` if
|
|
144
|
+
* @returns `true` if the field is filled, `false` otherwise.
|
|
145
145
|
*/
|
|
146
146
|
export const contentRelationship = link as <
|
|
147
147
|
Field extends ContentRelationshipField,
|
|
@@ -196,14 +196,14 @@ export const number = isNonNullish as (
|
|
|
196
196
|
/**
|
|
197
197
|
* Determines if a key text field is filled.
|
|
198
198
|
*
|
|
199
|
-
* @param field - Key
|
|
199
|
+
* @param field - Key text field to check.
|
|
200
200
|
*
|
|
201
|
-
* @returns `true` if
|
|
201
|
+
* @returns `true` if the field is filled, `false` otherwise.
|
|
202
202
|
*/
|
|
203
203
|
export const keyText = (
|
|
204
204
|
field: KeyTextField | null | undefined,
|
|
205
205
|
): field is KeyTextField<"filled"> => {
|
|
206
|
-
return
|
|
206
|
+
return !!field
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
@@ -233,9 +233,9 @@ export const embed = <Field extends EmbedField<AnyOEmbed>>(
|
|
|
233
233
|
/**
|
|
234
234
|
* Determines if a geopoint field is filled.
|
|
235
235
|
*
|
|
236
|
-
* @param field -
|
|
236
|
+
* @param field - Geopoint field to check.
|
|
237
237
|
*
|
|
238
|
-
* @returns `true` if
|
|
238
|
+
* @returns `true` if the field is filled, `false` otherwise.
|
|
239
239
|
*/
|
|
240
240
|
export const geoPoint = (
|
|
241
241
|
field: GeoPointField | null | undefined,
|
|
@@ -290,11 +290,11 @@ export const repeatable = <T extends LinkField>(
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
|
-
* Determines if a
|
|
293
|
+
* Determines if a group has at least one item.
|
|
294
294
|
*
|
|
295
295
|
* @param group - Group to check.
|
|
296
296
|
*
|
|
297
|
-
* @returns `true` if
|
|
297
|
+
* @returns `true` if the group contains at least one item, `false` otherwise.
|
|
298
298
|
*/
|
|
299
299
|
export const group = <
|
|
300
300
|
Fields extends Record<string, AnyRegularField | NestedGroupField>,
|
|
@@ -305,11 +305,12 @@ export const group = <
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
/**
|
|
308
|
-
* Determines if a
|
|
308
|
+
* Determines if a slice zone has at least one slice.
|
|
309
309
|
*
|
|
310
|
-
* @param slices - Slice
|
|
310
|
+
* @param slices - Slice zone to check.
|
|
311
311
|
*
|
|
312
|
-
* @returns `true` if
|
|
312
|
+
* @returns `true` if the slice zone contains at least one slice, `false`
|
|
313
|
+
* otherwise.
|
|
313
314
|
*/
|
|
314
315
|
export const sliceZone = <Slices extends Slice | SharedSlice>(
|
|
315
316
|
slices: SliceZone<Slices> | null | undefined,
|
|
@@ -26,10 +26,10 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends SliceLikeRestV2
|
|
|
26
26
|
: never
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* The minimum required properties to represent a Prismic
|
|
30
|
-
*
|
|
29
|
+
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
30
|
+
* Content API for the `mapSliceZone()` helper.
|
|
31
31
|
*
|
|
32
|
-
* @typeParam SliceType - Type name of the
|
|
32
|
+
* @typeParam SliceType - Type name of the slice.
|
|
33
33
|
*/
|
|
34
34
|
type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
35
35
|
Slice<TSliceType>,
|
|
@@ -37,23 +37,23 @@ type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
|
37
37
|
>
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* The minimum required properties to represent a Prismic
|
|
40
|
+
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
41
41
|
* GraphQL API for the `mapSliceZone()` helper.
|
|
42
42
|
*
|
|
43
|
-
* @typeParam SliceType - Type name of the
|
|
43
|
+
* @typeParam SliceType - Type name of the slice.
|
|
44
44
|
*/
|
|
45
45
|
type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
46
46
|
type: Slice<TSliceType>["slice_type"]
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* The minimum required properties to represent a Prismic
|
|
50
|
+
* The minimum required properties to represent a Prismic slice for the
|
|
51
51
|
* `mapSliceZone()` helper.
|
|
52
52
|
*
|
|
53
|
-
* If using Prismic's
|
|
53
|
+
* If using Prismic's Content API, use the `Slice` export from
|
|
54
54
|
* `@prismicio/client` for a full interface.
|
|
55
55
|
*
|
|
56
|
-
* @typeParam SliceType - Type name of the
|
|
56
|
+
* @typeParam SliceType - Type name of the slice.
|
|
57
57
|
*/
|
|
58
58
|
type SliceLike<TSliceType extends string = string> =
|
|
59
59
|
| SliceLikeRestV2<TSliceType>
|
|
@@ -63,10 +63,10 @@ type SliceLike<TSliceType extends string = string> =
|
|
|
63
63
|
* A looser version of the `SliceZone` type from `@prismicio/client` using
|
|
64
64
|
* `SliceLike`.
|
|
65
65
|
*
|
|
66
|
-
* If using Prismic's
|
|
66
|
+
* If using Prismic's Content API, use the `SliceZone` export from
|
|
67
67
|
* `@prismicio/client` for the full type.
|
|
68
68
|
*
|
|
69
|
-
* @typeParam TSlice - The type(s) of a
|
|
69
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
70
70
|
*/
|
|
71
71
|
type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[]
|
|
72
72
|
|
package/src/index.ts
CHANGED
|
@@ -119,6 +119,7 @@ export type { HTMLRichTextSerializer } from "./helpers/asHTML"
|
|
|
119
119
|
// Client Errors
|
|
120
120
|
export { PrismicError } from "./errors/PrismicError"
|
|
121
121
|
export { ForbiddenError } from "./errors/ForbiddenError"
|
|
122
|
+
export { InvalidDataError } from "./errors/InvalidDataError"
|
|
122
123
|
export { NotFoundError } from "./errors/NotFoundError"
|
|
123
124
|
export { RefNotFoundError } from "./errors/RefNotFoundError"
|
|
124
125
|
export { RefExpiredError } from "./errors/RefExpiredError"
|
|
@@ -360,7 +361,7 @@ export type {
|
|
|
360
361
|
} from "./types/migration/Asset"
|
|
361
362
|
export type { MigrationContentRelationship } from "./types/migration/ContentRelationship"
|
|
362
363
|
|
|
363
|
-
// API - Types representing Prismic
|
|
364
|
+
// API - Types representing Prismic Content API responses.
|
|
364
365
|
export type { Query } from "./types/api/query"
|
|
365
366
|
|
|
366
367
|
export type { Ref } from "./types/api/ref"
|
|
@@ -377,7 +378,7 @@ export type {
|
|
|
377
378
|
export type { Tags } from "./types/api/tags"
|
|
378
379
|
|
|
379
380
|
// Integration - Types representing Prismic's integration API.
|
|
380
|
-
export {
|
|
381
|
+
export type {
|
|
381
382
|
IntegrationAPIItem,
|
|
382
383
|
IntegrationAPIResults,
|
|
383
384
|
} from "./types/api/integration"
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Determines if a string
|
|
2
|
+
* Determines if a string is a Prismic Content API endpoint. Note that any valid
|
|
3
3
|
* URL is a valid endpoint to support network proxies.
|
|
4
4
|
*
|
|
5
5
|
* @param input - Input to test.
|
|
6
6
|
*
|
|
7
|
-
* @returns `true` if `input` is a valid Prismic
|
|
7
|
+
* @returns `true` if `input` is a valid Prismic Content API endpoint, `false`
|
|
8
8
|
* otherwise.
|
|
9
9
|
*/
|
|
10
10
|
export const isRepositoryEndpoint = (input: string): boolean => {
|
package/src/richtext/asText.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { RTTextNode, RichTextField } from "../types/value/richText"
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Converts a rich text field to a plain text string.
|
|
5
5
|
*
|
|
6
|
-
* @param richTextField - A rich text
|
|
7
|
-
* @param separator - Separator used to join each element
|
|
6
|
+
* @param richTextField - A rich text field from Prismic.
|
|
7
|
+
* @param separator - Separator used to join each element. Defaults to a space.
|
|
8
8
|
*
|
|
9
|
-
* @returns Plain text equivalent of the
|
|
9
|
+
* @returns Plain text equivalent of the rich text field.
|
|
10
10
|
*
|
|
11
|
-
* @see
|
|
11
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
12
12
|
*/
|
|
13
13
|
export const asText = (
|
|
14
14
|
richTextField: RichTextField,
|
|
@@ -4,20 +4,20 @@ import type { RichTextFunctionSerializer, TreeNode } from "./types"
|
|
|
4
4
|
import { asTree } from "./asTree"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Serializes a rich text
|
|
7
|
+
* Serializes a rich text field with a given serializer.
|
|
8
8
|
*
|
|
9
9
|
* @remarks
|
|
10
|
-
* This is a low
|
|
11
|
-
* packages Most users aren't expected to this function directly
|
|
10
|
+
* This is a low-level helper mainly intended to be used by higher-level
|
|
11
|
+
* packages. Most users aren't expected to use this function directly.
|
|
12
12
|
*
|
|
13
|
-
* @typeParam SerializerReturnType - Return type of the serializer
|
|
13
|
+
* @typeParam SerializerReturnType - Return type of the serializer.
|
|
14
14
|
*
|
|
15
|
-
* @param richTextField - A rich text
|
|
16
|
-
* @param serializer - A function serializer to apply
|
|
15
|
+
* @param richTextField - A rich text field from Prismic.
|
|
16
|
+
* @param serializer - A function serializer to apply.
|
|
17
17
|
*
|
|
18
|
-
* @returns An array of serialized nodes
|
|
18
|
+
* @returns An array of serialized nodes.
|
|
19
19
|
*
|
|
20
|
-
* @see
|
|
20
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
21
21
|
*/
|
|
22
22
|
export const serialize = <SerializerReturnType>(
|
|
23
23
|
richTextField: RichTextField,
|
package/src/richtext/types.ts
CHANGED
|
@@ -28,9 +28,9 @@ import { RichTextNodeType } from "../types/value/richText"
|
|
|
28
28
|
/**
|
|
29
29
|
* Serializes a node from a rich text or title field with a function
|
|
30
30
|
*
|
|
31
|
-
* @typeParam ReturnType - Return type of the function serializer
|
|
31
|
+
* @typeParam ReturnType - Return type of the function serializer.
|
|
32
32
|
*
|
|
33
|
-
* @see
|
|
33
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
34
34
|
*/
|
|
35
35
|
export type RichTextFunctionSerializer<ReturnType> = (
|
|
36
36
|
type: RichTextNodeTypes,
|
|
@@ -59,15 +59,15 @@ export type RichTextMapSerializerFunction<
|
|
|
59
59
|
}) => ReturnType | null | undefined
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Serializes a node from a rich text
|
|
62
|
+
* Serializes a node from a rich text field with a map.
|
|
63
63
|
*
|
|
64
64
|
* @remarks
|
|
65
65
|
* This type of serializer needs to be processed through
|
|
66
|
-
* {@link wrapMapSerializer} before being used with {@link serialize}
|
|
66
|
+
* {@link wrapMapSerializer} before being used with {@link serialize}.
|
|
67
67
|
*
|
|
68
|
-
* @typeParam ReturnType - Return type of the map serializer
|
|
68
|
+
* @typeParam ReturnType - Return type of the map serializer.
|
|
69
69
|
*
|
|
70
|
-
* @see
|
|
70
|
+
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
|
|
71
71
|
*/
|
|
72
72
|
export type RichTextMapSerializer<ReturnType> = {
|
|
73
73
|
heading1?: RichTextMapSerializerFunction<
|
|
@@ -17,12 +17,20 @@ export type MigrationAssetConfig = {
|
|
|
17
17
|
* `file` property. It is mainly used for deduplication within a `Migration`
|
|
18
18
|
* instance.
|
|
19
19
|
*/
|
|
20
|
-
id:
|
|
20
|
+
id:
|
|
21
|
+
| string
|
|
22
|
+
| URL
|
|
23
|
+
| File
|
|
24
|
+
| NonNullable<ConstructorParameters<typeof File>[0]>[0]
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* File to be uploaded as an asset.
|
|
24
28
|
*/
|
|
25
|
-
file:
|
|
29
|
+
file:
|
|
30
|
+
| string
|
|
31
|
+
| URL
|
|
32
|
+
| File
|
|
33
|
+
| NonNullable<ConstructorParameters<typeof File>[0]>[0]
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
36
|
* Filename of the asset.
|