@prismicio/client 7.0.0-alpha.0 → 7.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/buildQueryURL.cjs +26 -8
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +207 -130
- package/dist/buildQueryURL.js +25 -7
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/cookie.cjs +1 -1
- package/dist/cookie.cjs.map +1 -1
- package/dist/cookie.d.ts +5 -5
- package/dist/cookie.js.map +1 -1
- package/dist/createClient.cjs +1142 -0
- package/dist/createClient.cjs.map +1 -0
- package/dist/{client.d.ts → createClient.d.ts} +980 -908
- package/dist/createClient.js +1142 -0
- package/dist/createClient.js.map +1 -0
- package/dist/{ForbiddenError.cjs → errors/ForbiddenError.cjs} +1 -1
- package/dist/errors/ForbiddenError.cjs.map +1 -0
- package/dist/{ForbiddenError.d.ts → errors/ForbiddenError.d.ts} +11 -11
- package/dist/errors/ForbiddenError.js.map +1 -0
- package/dist/{NotFoundError.cjs → errors/NotFoundError.cjs} +1 -1
- package/dist/errors/NotFoundError.cjs.map +1 -0
- package/dist/{NotFoundError.d.ts → errors/NotFoundError.d.ts} +3 -3
- package/dist/errors/NotFoundError.js.map +1 -0
- package/dist/{ParsingError.cjs → errors/ParsingError.cjs} +1 -1
- package/dist/errors/ParsingError.cjs.map +1 -0
- package/dist/{ParsingError.d.ts → errors/ParsingError.d.ts} +12 -12
- package/dist/errors/ParsingError.js.map +1 -0
- package/dist/{PrismicError.cjs → errors/PrismicError.cjs} +1 -1
- package/dist/errors/PrismicError.cjs.map +1 -0
- package/dist/{PrismicError.d.ts → errors/PrismicError.d.ts} +5 -5
- package/dist/errors/PrismicError.js.map +1 -0
- package/dist/filter.cjs +247 -0
- package/dist/filter.cjs.map +1 -0
- package/dist/filter.d.ts +209 -0
- package/dist/filter.js +247 -0
- package/dist/filter.js.map +1 -0
- package/dist/getGraphQLEndpoint.cjs +2 -2
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.d.ts +9 -9
- package/dist/getGraphQLEndpoint.js +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs +2 -2
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +10 -10
- package/dist/getRepositoryEndpoint.js +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs +2 -2
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.d.ts +13 -13
- package/dist/getRepositoryName.js +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs +13 -0
- package/dist/getToolbarSrc.cjs.map +1 -0
- package/dist/getToolbarSrc.d.ts +34 -0
- package/dist/getToolbarSrc.js +13 -0
- package/dist/getToolbarSrc.js.map +1 -0
- package/dist/helpers/asDate.cjs +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +16 -16
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs +7 -6
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +77 -20
- package/dist/helpers/asHTML.js +6 -5
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -52
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +27 -27
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs +19 -14
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +60 -60
- package/dist/helpers/asImageWidthSrcSet.js +18 -13
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs +8 -2
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +34 -24
- package/dist/helpers/asLink.js +7 -1
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs +28 -0
- package/dist/helpers/asLinkAttrs.cjs.map +1 -0
- package/dist/helpers/asLinkAttrs.d.ts +63 -0
- package/dist/helpers/asLinkAttrs.js +28 -0
- package/dist/helpers/asLinkAttrs.js.map +1 -0
- package/dist/helpers/asText.cjs +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +16 -16
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs +12 -5
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.d.ts +15 -15
- package/dist/helpers/documentToLinkField.js +11 -4
- 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 +172 -175
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/index.cjs +20 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +139 -92
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +10 -10
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/isRepositoryName.cjs +1 -1
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.d.ts +9 -9
- package/dist/isRepositoryName.js.map +1 -1
- package/dist/lib/appendFilters.cjs +11 -0
- package/dist/lib/appendFilters.cjs.map +1 -0
- package/dist/lib/appendFilters.d.ts +18 -0
- package/dist/lib/appendFilters.js +11 -0
- package/dist/lib/appendFilters.js.map +1 -0
- package/dist/lib/castArray.cjs +4 -2
- package/dist/lib/castArray.cjs.map +1 -1
- package/dist/lib/castArray.d.ts +11 -11
- package/dist/lib/castArray.js +3 -1
- package/dist/lib/castArray.js.map +1 -1
- package/dist/lib/castThunk.cjs +4 -2
- package/dist/lib/castThunk.cjs.map +1 -1
- package/dist/lib/castThunk.d.ts +10 -10
- package/dist/lib/castThunk.js +3 -1
- package/dist/lib/castThunk.js.map +1 -1
- package/dist/lib/devMsg.cjs +8 -0
- package/dist/lib/devMsg.cjs.map +1 -0
- package/dist/lib/devMsg.d.ts +16 -0
- package/dist/lib/devMsg.js +8 -0
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/escapeHTML.cjs +43 -0
- package/dist/lib/escapeHTML.cjs.map +1 -0
- package/dist/lib/escapeHTML.d.ts +1 -0
- package/dist/lib/escapeHTML.js +43 -0
- package/dist/lib/escapeHTML.js.map +1 -0
- package/dist/lib/everyTagFilter.cjs +9 -0
- package/dist/lib/everyTagFilter.cjs.map +1 -0
- package/dist/lib/everyTagFilter.d.ts +9 -0
- package/dist/lib/everyTagFilter.js +9 -0
- package/dist/lib/everyTagFilter.js.map +1 -0
- package/dist/lib/findMasterRef.cjs +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findMasterRef.d.ts +10 -10
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs +4 -4
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.d.ts +13 -13
- package/dist/lib/findRef.js +3 -3
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/findRefByID.cjs +1 -1
- package/dist/lib/findRefByID.cjs.map +1 -1
- package/dist/lib/findRefByID.d.ts +11 -11
- package/dist/lib/findRefByID.js.map +1 -1
- package/dist/lib/findRefByLabel.cjs +1 -1
- package/dist/lib/findRefByLabel.cjs.map +1 -1
- package/dist/lib/findRefByLabel.d.ts +11 -11
- package/dist/lib/findRefByLabel.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.d.ts +9 -9
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isInternalURL.cjs +9 -0
- package/dist/lib/isInternalURL.cjs.map +1 -0
- package/dist/lib/isInternalURL.d.ts +8 -0
- package/dist/lib/isInternalURL.js +9 -0
- package/dist/lib/isInternalURL.js.map +1 -0
- package/dist/lib/minifyGraphQLQuery.cjs +1 -1
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
- package/dist/lib/minifyGraphQLQuery.d.ts +8 -8
- package/dist/lib/minifyGraphQLQuery.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +7 -9
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.d.ts +9 -9
- package/dist/lib/serializerHelpers.js +6 -6
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/someTagsFilter.cjs +9 -0
- package/dist/lib/someTagsFilter.cjs.map +1 -0
- package/dist/lib/someTagsFilter.d.ts +9 -0
- package/dist/lib/someTagsFilter.js +9 -0
- package/dist/lib/someTagsFilter.js.map +1 -0
- package/dist/lib/typeFilter.cjs +8 -0
- package/dist/lib/typeFilter.cjs.map +1 -0
- package/dist/lib/typeFilter.d.ts +8 -0
- package/dist/lib/typeFilter.js +8 -0
- package/dist/lib/typeFilter.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/package.json.js +5 -0
- package/dist/package.json.js.map +1 -0
- package/dist/types/api/query.d.ts +42 -42
- package/dist/types/api/ref.d.ts +32 -32
- package/dist/types/api/release.d.ts +10 -10
- package/dist/types/api/repository.d.ts +100 -100
- package/dist/types/api/tags.d.ts +8 -8
- package/dist/types/model/boolean.d.ts +15 -15
- package/dist/types/model/color.d.ts +13 -13
- package/dist/types/model/contentRelationship.d.ts +18 -18
- package/dist/types/model/customType.d.ts +42 -42
- package/dist/types/model/date.d.ts +14 -14
- package/dist/types/model/embed.d.ts +13 -13
- package/dist/types/model/geoPoint.d.ts +12 -12
- package/dist/types/model/group.d.ts +15 -15
- package/dist/types/model/image.d.ts +31 -31
- package/dist/types/model/integrationFields.d.ts +14 -14
- package/dist/types/model/keyText.d.ts +13 -13
- package/dist/types/model/link.cjs +1 -1
- package/dist/types/model/link.cjs.map +1 -1
- package/dist/types/model/link.d.ts +27 -27
- package/dist/types/model/link.js.map +1 -1
- package/dist/types/model/linkToMedia.d.ts +16 -16
- package/dist/types/model/number.d.ts +15 -15
- package/dist/types/model/range.d.ts +14 -14
- package/dist/types/model/richText.d.ts +35 -35
- package/dist/types/model/select.d.ts +18 -18
- package/dist/types/model/separator.d.ts +10 -10
- package/dist/types/model/sharedSlice.d.ts +16 -19
- package/dist/types/model/sharedSliceVariation.d.ts +19 -22
- package/dist/types/model/slice.cjs +1 -1
- package/dist/types/model/slice.cjs.map +1 -1
- package/dist/types/model/slice.d.ts +33 -33
- package/dist/types/model/slice.js.map +1 -1
- package/dist/types/model/sliceZone.cjs +1 -1
- package/dist/types/model/sliceZone.cjs.map +1 -1
- package/dist/types/model/sliceZone.d.ts +41 -44
- package/dist/types/model/sliceZone.js.map +1 -1
- package/dist/types/model/timestamp.d.ts +14 -14
- package/dist/types/model/title.d.ts +7 -7
- package/dist/types/model/types.cjs +10 -1
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.d.ts +62 -62
- package/dist/types/model/types.js +9 -0
- package/dist/types/model/types.js.map +1 -1
- package/dist/types/model/uid.d.ts +13 -13
- package/dist/types/value/boolean.d.ts +6 -6
- package/dist/types/value/color.d.ts +8 -8
- package/dist/types/value/contentRelationship.d.ts +29 -29
- package/dist/types/value/date.d.ts +8 -8
- package/dist/types/value/document.d.ts +113 -113
- package/dist/types/value/embed.cjs +1 -1
- package/dist/types/value/embed.cjs.map +1 -1
- package/dist/types/value/embed.d.ts +167 -167
- package/dist/types/value/embed.js.map +1 -1
- package/dist/types/value/geoPoint.d.ts +11 -11
- package/dist/types/value/group.d.ts +7 -7
- package/dist/types/value/image.d.ts +36 -36
- package/dist/types/value/integrationFields.d.ts +9 -9
- package/dist/types/value/keyText.d.ts +8 -8
- package/dist/types/value/link.cjs +1 -1
- package/dist/types/value/link.cjs.map +1 -1
- package/dist/types/value/link.d.ts +40 -40
- package/dist/types/value/link.js.map +1 -1
- package/dist/types/value/linkToMedia.d.ts +20 -20
- package/dist/types/value/number.d.ts +8 -8
- package/dist/types/value/richText.cjs +1 -1
- package/dist/types/value/richText.cjs.map +1 -1
- package/dist/types/value/richText.d.ts +203 -203
- package/dist/types/value/richText.js.map +1 -1
- package/dist/types/value/select.d.ts +9 -9
- package/dist/types/value/sharedSlice.d.ts +11 -11
- package/dist/types/value/sharedSliceVariation.d.ts +7 -7
- package/dist/types/value/slice.d.ts +13 -13
- package/dist/types/value/sliceZone.d.ts +12 -12
- package/dist/types/value/timestamp.d.ts +8 -8
- package/dist/types/value/title.d.ts +12 -12
- package/dist/types/value/types.d.ts +40 -40
- package/dist/types/webhook/apiUpdate.d.ts +52 -52
- package/dist/types/webhook/testTrigger.d.ts +9 -9
- package/dist/types/webhook/types.cjs +1 -1
- package/dist/types/webhook/types.cjs.map +1 -1
- package/dist/types/webhook/types.d.ts +18 -18
- package/dist/types/webhook/types.js.map +1 -1
- package/package.json +23 -24
- package/src/buildQueryURL.ts +179 -33
- package/src/{client.ts → createClient.ts} +214 -110
- package/src/filter.ts +356 -0
- package/src/getGraphQLEndpoint.ts +2 -1
- package/src/getRepositoryEndpoint.ts +2 -1
- package/src/getRepositoryName.ts +1 -1
- package/src/getToolbarSrc.ts +50 -0
- package/src/helpers/asDate.ts +3 -3
- package/src/helpers/asHTML.ts +122 -27
- package/src/helpers/asImagePixelDensitySrcSet.ts +1 -1
- package/src/helpers/asImageSrc.ts +1 -1
- package/src/helpers/asImageWidthSrcSet.ts +1 -1
- package/src/helpers/asLink.ts +37 -18
- package/src/helpers/asLinkAttrs.ts +127 -0
- package/src/helpers/asText.ts +4 -4
- package/src/helpers/documentToLinkField.ts +3 -3
- package/src/helpers/isFilled.ts +9 -11
- package/src/index.ts +60 -29
- package/src/lib/appendFilters.ts +26 -0
- package/src/lib/castArray.ts +3 -1
- package/src/lib/castThunk.ts +3 -2
- package/src/lib/devMsg.ts +20 -0
- package/src/lib/escapeHTML.ts +51 -0
- package/src/lib/everyTagFilter.ts +15 -0
- package/src/lib/findRef.ts +5 -5
- package/src/lib/isInternalURL.ts +14 -0
- package/src/lib/serializerHelpers.ts +20 -15
- package/src/lib/someTagsFilter.ts +15 -0
- package/src/lib/typeFilter.ts +12 -0
- package/src/types/api/query.ts +1 -1
- package/src/types/api/ref.ts +2 -2
- package/src/types/api/release.ts +1 -1
- package/src/types/api/repository.ts +1 -1
- package/src/types/api/tags.ts +1 -1
- package/src/types/model/boolean.ts +1 -1
- package/src/types/model/color.ts +1 -1
- package/src/types/model/contentRelationship.ts +2 -1
- package/src/types/model/date.ts +1 -1
- package/src/types/model/embed.ts +1 -1
- package/src/types/model/geoPoint.ts +1 -1
- package/src/types/model/group.ts +2 -2
- package/src/types/model/image.ts +3 -3
- package/src/types/model/integrationFields.ts +1 -1
- package/src/types/model/keyText.ts +1 -1
- package/src/types/model/link.ts +3 -3
- package/src/types/model/linkToMedia.ts +2 -1
- package/src/types/model/number.ts +1 -1
- package/src/types/model/richText.ts +3 -3
- package/src/types/model/select.ts +1 -1
- package/src/types/model/sharedSlice.ts +2 -5
- package/src/types/model/sharedSliceVariation.ts +1 -4
- package/src/types/model/slice.ts +5 -4
- package/src/types/model/sliceZone.ts +5 -7
- package/src/types/model/timestamp.ts +1 -1
- package/src/types/model/title.ts +1 -1
- package/src/types/model/types.ts +12 -16
- package/src/types/model/uid.ts +1 -1
- package/src/types/value/boolean.ts +1 -1
- package/src/types/value/color.ts +1 -1
- package/src/types/value/contentRelationship.ts +8 -9
- package/src/types/value/date.ts +1 -1
- package/src/types/value/document.ts +6 -5
- package/src/types/value/embed.ts +2 -2
- package/src/types/value/geoPoint.ts +1 -1
- package/src/types/value/group.ts +2 -2
- package/src/types/value/image.ts +1 -1
- package/src/types/value/integrationFields.ts +1 -1
- package/src/types/value/keyText.ts +1 -1
- package/src/types/value/link.ts +8 -8
- package/src/types/value/linkToMedia.ts +2 -1
- package/src/types/value/number.ts +1 -1
- package/src/types/value/richText.ts +6 -5
- package/src/types/value/select.ts +1 -1
- package/src/types/value/sharedSlice.ts +1 -1
- package/src/types/value/slice.ts +1 -1
- package/src/types/value/sliceZone.ts +2 -1
- package/src/types/value/timestamp.ts +1 -0
- package/src/types/value/title.ts +2 -1
- package/src/types/value/types.ts +9 -11
- package/src/types/webhook/apiUpdate.ts +4 -4
- package/src/types/webhook/testTrigger.ts +1 -1
- package/src/types/webhook/types.ts +2 -2
- package/dist/ForbiddenError.cjs.map +0 -1
- package/dist/ForbiddenError.js.map +0 -1
- package/dist/NotFoundError.cjs.map +0 -1
- package/dist/NotFoundError.js.map +0 -1
- package/dist/ParsingError.cjs.map +0 -1
- package/dist/ParsingError.js.map +0 -1
- package/dist/PrismicError.cjs.map +0 -1
- package/dist/PrismicError.js.map +0 -1
- package/dist/client.cjs +0 -414
- package/dist/client.cjs.map +0 -1
- package/dist/client.js +0 -414
- package/dist/client.js.map +0 -1
- package/dist/lib/appendPredicates.cjs +0 -14
- package/dist/lib/appendPredicates.cjs.map +0 -1
- package/dist/lib/appendPredicates.d.ts +0 -18
- package/dist/lib/appendPredicates.js +0 -14
- package/dist/lib/appendPredicates.js.map +0 -1
- package/dist/predicate.cjs +0 -68
- package/dist/predicate.cjs.map +0 -1
- package/dist/predicate.d.ts +0 -209
- package/dist/predicate.js +0 -68
- package/dist/predicate.js.map +0 -1
- package/dist/types/client.d.ts +0 -128
- package/dist/types/helpers.d.ts +0 -63
- package/dist/types/utils.d.ts +0 -28
- package/src/lib/appendPredicates.ts +0 -29
- package/src/predicate.ts +0 -359
- package/src/types/client.ts +0 -157
- package/src/types/helpers.ts +0 -103
- package/src/types/utils.ts +0 -34
- /package/dist/{ForbiddenError.js → errors/ForbiddenError.js} +0 -0
- /package/dist/{NotFoundError.js → errors/NotFoundError.js} +0 -0
- /package/dist/{ParsingError.js → errors/ParsingError.js} +0 -0
- /package/dist/{PrismicError.js → errors/PrismicError.js} +0 -0
- /package/src/{ForbiddenError.ts → errors/ForbiddenError.ts} +0 -0
- /package/src/{NotFoundError.ts → errors/NotFoundError.ts} +0 -0
- /package/src/{ParsingError.ts → errors/ParsingError.ts} +0 -0
- /package/src/{PrismicError.ts → errors/PrismicError.ts} +0 -0
package/src/helpers/asLink.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
|
|
1
2
|
import type { PrismicDocument } from "../types/value/document";
|
|
2
3
|
import { FilledLinkToWebField, LinkField, LinkType } from "../types/value/link";
|
|
3
4
|
import type { FilledLinkToMediaField } from "../types/value/linkToMedia";
|
|
4
|
-
import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
|
|
5
|
-
import type { LinkResolverFunction } from "../types/helpers";
|
|
6
5
|
|
|
7
6
|
import { documentToLinkField } from "./documentToLinkField";
|
|
8
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a Link to a Prismic document to a URL
|
|
10
|
+
*
|
|
11
|
+
* @typeParam ReturnType - Return type of your link resolver function, useful if
|
|
12
|
+
* you prefer to return a complex object
|
|
13
|
+
* @param linkToDocumentField - A document Link Field to resolve
|
|
14
|
+
*
|
|
15
|
+
* @returns Resolved URL
|
|
16
|
+
* @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
17
|
+
*/
|
|
18
|
+
export type LinkResolverFunction<ReturnType = string | null | undefined> = (
|
|
19
|
+
linkToDocumentField: FilledContentRelationshipField,
|
|
20
|
+
) => ReturnType;
|
|
21
|
+
|
|
9
22
|
/**
|
|
10
23
|
* The return type of `asLink()`.
|
|
11
24
|
*/
|
|
12
|
-
type AsLinkReturnType<
|
|
13
|
-
LinkResolverFunctionReturnType = string,
|
|
25
|
+
export type AsLinkReturnType<
|
|
26
|
+
LinkResolverFunctionReturnType = string | null | undefined,
|
|
14
27
|
Field extends LinkField | PrismicDocument | null | undefined =
|
|
15
28
|
| LinkField
|
|
16
29
|
| PrismicDocument
|
|
@@ -25,20 +38,21 @@ type AsLinkReturnType<
|
|
|
25
38
|
: null;
|
|
26
39
|
|
|
27
40
|
/**
|
|
28
|
-
* Resolves any type of
|
|
41
|
+
* Resolves any type of Link field or Prismic document to a URL.
|
|
29
42
|
*
|
|
30
|
-
* @typeParam LinkResolverFunctionReturnType - Link
|
|
43
|
+
* @typeParam LinkResolverFunctionReturnType - Link Resolver function return
|
|
31
44
|
* type
|
|
32
|
-
* @
|
|
33
|
-
* @param
|
|
45
|
+
* @typeParam Field - Link field or Prismic document to resolve to a URL
|
|
46
|
+
* @param linkFieldOrDocument - Any kind of Link field or a document to resolve
|
|
47
|
+
* @param linkResolver - An optional Link Resolver function. Without it, you are
|
|
34
48
|
* expected to use the `routes` options from the API
|
|
35
49
|
*
|
|
36
|
-
* @returns Resolved URL,
|
|
37
|
-
* @see Prismic
|
|
38
|
-
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/
|
|
50
|
+
* @returns Resolved URL or, if the provided Link field or document is empty, `null`
|
|
51
|
+
* @see Prismic Link Resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
52
|
+
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
39
53
|
*/
|
|
40
54
|
export const asLink = <
|
|
41
|
-
LinkResolverFunctionReturnType = string,
|
|
55
|
+
LinkResolverFunctionReturnType = string | null | undefined,
|
|
42
56
|
Field extends LinkField | PrismicDocument | null | undefined =
|
|
43
57
|
| LinkField
|
|
44
58
|
| PrismicDocument
|
|
@@ -52,12 +66,17 @@ export const asLink = <
|
|
|
52
66
|
return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>;
|
|
53
67
|
}
|
|
54
68
|
|
|
55
|
-
// Converts document to
|
|
56
|
-
const linkField =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
// Converts document to Link Field if needed
|
|
70
|
+
const linkField =
|
|
71
|
+
// prettier-ignore
|
|
72
|
+
(
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
74
|
+
// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
|
|
75
|
+
// TODO: Remove the `prettier-ignore` comment when this bug is fixed.
|
|
76
|
+
"link_type" in linkFieldOrDocument
|
|
77
|
+
? linkFieldOrDocument
|
|
78
|
+
: documentToLinkField(linkFieldOrDocument)
|
|
79
|
+
) as LinkField;
|
|
61
80
|
|
|
62
81
|
switch (linkField.link_type) {
|
|
63
82
|
case LinkType.Media:
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { isInternalURL } from "../lib/isInternalURL";
|
|
2
|
+
|
|
3
|
+
import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
|
|
4
|
+
import type { PrismicDocument } from "../types/value/document";
|
|
5
|
+
import { FilledLinkToWebField, LinkField } from "../types/value/link";
|
|
6
|
+
import type { FilledLinkToMediaField } from "../types/value/linkToMedia";
|
|
7
|
+
|
|
8
|
+
import { AsLinkReturnType, LinkResolverFunction, asLink } from "./asLink";
|
|
9
|
+
import { link as isFilledLink } from "./isFilled";
|
|
10
|
+
|
|
11
|
+
type AsLinkAttrsConfigRelArgs<
|
|
12
|
+
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
|
13
|
+
Field extends LinkField | PrismicDocument | null | undefined =
|
|
14
|
+
| LinkField
|
|
15
|
+
| PrismicDocument
|
|
16
|
+
| null
|
|
17
|
+
| undefined,
|
|
18
|
+
> = {
|
|
19
|
+
href:
|
|
20
|
+
| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>
|
|
21
|
+
| undefined;
|
|
22
|
+
isExternal: boolean;
|
|
23
|
+
target?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type AsLinkAttrsConfig<
|
|
27
|
+
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
|
28
|
+
Field extends LinkField | PrismicDocument | null | undefined =
|
|
29
|
+
| LinkField
|
|
30
|
+
| PrismicDocument
|
|
31
|
+
| null
|
|
32
|
+
| undefined,
|
|
33
|
+
> = {
|
|
34
|
+
linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType>;
|
|
35
|
+
rel?: (
|
|
36
|
+
args: AsLinkAttrsConfigRelArgs<LinkResolverFunctionReturnType, Field>,
|
|
37
|
+
) => string | undefined | void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The return type of `asLinkAttrs()`.
|
|
42
|
+
*/
|
|
43
|
+
type AsLinkAttrsReturnType<
|
|
44
|
+
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
|
45
|
+
Field extends LinkField | PrismicDocument | null | undefined =
|
|
46
|
+
| LinkField
|
|
47
|
+
| PrismicDocument
|
|
48
|
+
| null
|
|
49
|
+
| undefined,
|
|
50
|
+
> = Field extends
|
|
51
|
+
| FilledLinkToWebField
|
|
52
|
+
| FilledLinkToMediaField
|
|
53
|
+
| FilledContentRelationshipField
|
|
54
|
+
| PrismicDocument
|
|
55
|
+
? {
|
|
56
|
+
href:
|
|
57
|
+
| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>
|
|
58
|
+
| undefined;
|
|
59
|
+
target?: string;
|
|
60
|
+
rel?: string;
|
|
61
|
+
}
|
|
62
|
+
: {
|
|
63
|
+
href?: undefined;
|
|
64
|
+
target?: undefined;
|
|
65
|
+
rel?: undefined;
|
|
66
|
+
};
|
|
67
|
+
|
|
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>`.
|
|
70
|
+
*
|
|
71
|
+
* If a resolved URL is external (i.e. starts with a protocol like `https://`), `rel` is returned as `"noreferrer"`.
|
|
72
|
+
*
|
|
73
|
+
* @typeParam LinkResolverFunctionReturnType - Link Resolver function return
|
|
74
|
+
* type
|
|
75
|
+
* @typeParam Field - Link field or Prismic document to resolve to link attributes
|
|
76
|
+
* @param linkFieldOrDocument - Any kind of Link field or a document to resolve
|
|
77
|
+
* @param config - Configuration that determines the output of `asLinkAttrs()`
|
|
78
|
+
*
|
|
79
|
+
* @returns Resolved set of link attributes or, if the provided Link field or document is empty, and empty object
|
|
80
|
+
* @see Prismic Link Resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
|
|
81
|
+
* @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
|
|
82
|
+
*/
|
|
83
|
+
export const asLinkAttrs = <
|
|
84
|
+
LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
|
|
85
|
+
Field extends LinkField | PrismicDocument | null | undefined =
|
|
86
|
+
| LinkField
|
|
87
|
+
| PrismicDocument
|
|
88
|
+
| null
|
|
89
|
+
| undefined,
|
|
90
|
+
>(
|
|
91
|
+
linkFieldOrDocument: Field,
|
|
92
|
+
config: AsLinkAttrsConfig<LinkResolverFunctionReturnType> = {},
|
|
93
|
+
): AsLinkAttrsReturnType<LinkResolverFunctionReturnType> => {
|
|
94
|
+
if (
|
|
95
|
+
linkFieldOrDocument &&
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
97
|
+
// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
|
|
98
|
+
("link_type" in linkFieldOrDocument
|
|
99
|
+
? isFilledLink(linkFieldOrDocument)
|
|
100
|
+
: linkFieldOrDocument)
|
|
101
|
+
) {
|
|
102
|
+
const target =
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
104
|
+
// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
|
|
105
|
+
"target" in linkFieldOrDocument ? linkFieldOrDocument.target : undefined;
|
|
106
|
+
|
|
107
|
+
const rawHref = asLink(linkFieldOrDocument, config.linkResolver);
|
|
108
|
+
const href =
|
|
109
|
+
rawHref == null ? undefined : (rawHref as NonNullable<typeof rawHref>);
|
|
110
|
+
|
|
111
|
+
const isExternal = typeof href === "string" ? !isInternalURL(href) : false;
|
|
112
|
+
|
|
113
|
+
const rel = config.rel
|
|
114
|
+
? config.rel({ href, isExternal, target })
|
|
115
|
+
: isExternal
|
|
116
|
+
? "noreferrer"
|
|
117
|
+
: undefined;
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
href,
|
|
121
|
+
target,
|
|
122
|
+
rel: rel == null ? undefined : rel,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {};
|
|
127
|
+
};
|
package/src/helpers/asText.ts
CHANGED
|
@@ -9,13 +9,13 @@ type AsTextReturnType<Field extends RichTextField | null | undefined> =
|
|
|
9
9
|
Field extends RichTextField ? string : null;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Serializes a
|
|
12
|
+
* Serializes a Rich Text or Title field to a plain text string
|
|
13
13
|
*
|
|
14
|
-
* @param richTextField - A
|
|
14
|
+
* @param richTextField - A Rich Text or Title field from Prismic
|
|
15
15
|
* @param separator - Separator used to join each element, defaults to a space
|
|
16
16
|
*
|
|
17
|
-
* @returns Plain text equivalent of the provided
|
|
18
|
-
* @see Templating
|
|
17
|
+
* @returns Plain text equivalent of the provided Rich Text or Title field
|
|
18
|
+
* @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
|
|
19
19
|
*/
|
|
20
20
|
export const asText = <Field extends RichTextField | null | undefined>(
|
|
21
21
|
richTextField: Field,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
|
|
1
2
|
import type { PrismicDocument } from "../types/value/document";
|
|
2
3
|
import { LinkType } from "../types/value/link";
|
|
3
|
-
import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
|
|
4
4
|
|
|
5
5
|
type SetOptional<T, Keys extends keyof T> = Omit<T, Keys> &
|
|
6
6
|
Partial<Pick<T, Keys>>;
|
|
@@ -27,11 +27,11 @@ export const documentToLinkField = <
|
|
|
27
27
|
return {
|
|
28
28
|
link_type: LinkType.Document,
|
|
29
29
|
id: prismicDocument.id,
|
|
30
|
-
uid: prismicDocument.uid
|
|
30
|
+
uid: prismicDocument.uid || undefined,
|
|
31
31
|
type: prismicDocument.type,
|
|
32
32
|
tags: prismicDocument.tags,
|
|
33
33
|
lang: prismicDocument.lang,
|
|
34
|
-
url: prismicDocument.url
|
|
34
|
+
url: prismicDocument.url == null ? undefined : prismicDocument.url,
|
|
35
35
|
slug: prismicDocument.slugs?.[0], // Slug field is not available with GraphQl
|
|
36
36
|
// The REST API does not include a `data` property if the data
|
|
37
37
|
// object is empty.
|
package/src/helpers/isFilled.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ColorField } from "../types/value/color";
|
|
2
|
+
import type { ContentRelationshipField } from "../types/value/contentRelationship";
|
|
2
3
|
import type { DateField } from "../types/value/date";
|
|
3
|
-
import type {
|
|
4
|
+
import type { AnyOEmbed, EmbedField } from "../types/value/embed";
|
|
4
5
|
import type { GeoPointField } from "../types/value/geoPoint";
|
|
5
6
|
import type { GroupField } from "../types/value/group";
|
|
6
|
-
import type {
|
|
7
|
+
import type { ImageField, ImageFieldImage } from "../types/value/image";
|
|
7
8
|
import type { IntegrationFields } from "../types/value/integrationFields";
|
|
8
9
|
import type { KeyTextField } from "../types/value/keyText";
|
|
9
10
|
import type { LinkField } from "../types/value/link";
|
|
10
11
|
import type { LinkToMediaField } from "../types/value/linkToMedia";
|
|
11
|
-
import type { ContentRelationshipField } from "../types/value/contentRelationship";
|
|
12
12
|
import type { NumberField } from "../types/value/number";
|
|
13
13
|
import type { RichTextField } from "../types/value/richText";
|
|
14
14
|
import type { SelectField } from "../types/value/select";
|
|
@@ -109,10 +109,9 @@ export const image = imageThumbnail as <
|
|
|
109
109
|
export const link = <
|
|
110
110
|
TypeEnum = string,
|
|
111
111
|
LangEnum = string,
|
|
112
|
-
DataInterface extends
|
|
113
|
-
string,
|
|
114
|
-
|
|
115
|
-
> = never,
|
|
112
|
+
DataInterface extends
|
|
113
|
+
| Record<string, AnyRegularField | GroupField | SliceZone>
|
|
114
|
+
| unknown = unknown,
|
|
116
115
|
>(
|
|
117
116
|
field: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined,
|
|
118
117
|
): field is LinkField<TypeEnum, LangEnum, DataInterface, "filled"> => {
|
|
@@ -140,10 +139,9 @@ export const linkToMedia = link as (
|
|
|
140
139
|
export const contentRelationship = link as <
|
|
141
140
|
TypeEnum = string,
|
|
142
141
|
LangEnum = string,
|
|
143
|
-
DataInterface extends
|
|
144
|
-
string,
|
|
145
|
-
|
|
146
|
-
> = never,
|
|
142
|
+
DataInterface extends
|
|
143
|
+
| Record<string, AnyRegularField | GroupField | SliceZone>
|
|
144
|
+
| unknown = unknown,
|
|
147
145
|
>(
|
|
148
146
|
field:
|
|
149
147
|
| ContentRelationshipField<TypeEnum, LangEnum, DataInterface>
|
package/src/index.ts
CHANGED
|
@@ -1,48 +1,65 @@
|
|
|
1
|
+
// Use for deprecations.
|
|
2
|
+
import type {
|
|
3
|
+
HTMLRichTextFunctionSerializer,
|
|
4
|
+
HTMLRichTextMapSerializer,
|
|
5
|
+
} from "./helpers/asHTML";
|
|
6
|
+
|
|
7
|
+
import { filter } from "./filter";
|
|
8
|
+
|
|
1
9
|
//=============================================================================
|
|
2
|
-
// Client -
|
|
10
|
+
// Client - Query content from Prismic.
|
|
3
11
|
//=============================================================================
|
|
4
12
|
|
|
5
13
|
// Primary Client API.
|
|
14
|
+
export { createClient, Client } from "./createClient";
|
|
15
|
+
|
|
16
|
+
// API endpoint helpers.
|
|
6
17
|
export { getRepositoryEndpoint } from "./getRepositoryEndpoint";
|
|
7
18
|
export { getRepositoryName } from "./getRepositoryName";
|
|
8
19
|
export { getGraphQLEndpoint } from "./getGraphQLEndpoint";
|
|
9
20
|
export { isRepositoryName } from "./isRepositoryName";
|
|
10
21
|
export { isRepositoryEndpoint } from "./isRepositoryEndpoint";
|
|
11
22
|
export { buildQueryURL } from "./buildQueryURL";
|
|
12
|
-
export { createClient, Client } from "./client";
|
|
13
23
|
|
|
14
|
-
//
|
|
15
|
-
export {
|
|
24
|
+
// Toolbar helpers.
|
|
25
|
+
export { getToolbarSrc } from "./getToolbarSrc";
|
|
16
26
|
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
// Query filters API.
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Renamed to `filter`
|
|
30
|
+
*/
|
|
31
|
+
// TODO: Remove when we remove support for deprecated `predicate` export.
|
|
32
|
+
const predicate = filter;
|
|
33
|
+
export { filter, predicate };
|
|
22
34
|
|
|
23
35
|
// A collection of well-known cookie names shared between Prismic libraries and systems.
|
|
24
36
|
export * as cookie from "./cookie";
|
|
25
37
|
|
|
26
|
-
// General types used
|
|
27
|
-
export type { CreateClient, ClientConfig } from "./client";
|
|
28
|
-
export type { QueryParams, BuildQueryURLArgs } from "./buildQueryURL";
|
|
38
|
+
// General types used to query content from Prismic. These are made public to allow users to better type their projects.
|
|
29
39
|
export type {
|
|
30
40
|
AbortSignalLike,
|
|
41
|
+
ClientConfig,
|
|
42
|
+
CreateClient,
|
|
31
43
|
FetchLike,
|
|
32
44
|
HttpRequestLike,
|
|
33
|
-
Ordering,
|
|
34
45
|
RequestInitLike,
|
|
35
46
|
ResponseLike,
|
|
47
|
+
} from "./createClient";
|
|
48
|
+
export type {
|
|
49
|
+
BuildQueryURLArgs,
|
|
50
|
+
Ordering,
|
|
51
|
+
QueryParams,
|
|
36
52
|
Route,
|
|
37
|
-
} from "./
|
|
53
|
+
} from "./buildQueryURL";
|
|
38
54
|
|
|
39
55
|
//=============================================================================
|
|
40
|
-
// Helpers -
|
|
56
|
+
// Helpers - Manipulate content from Prismic.
|
|
41
57
|
//=============================================================================
|
|
42
58
|
|
|
43
59
|
// Primary Helpers API.
|
|
44
60
|
export { asDate } from "./helpers/asDate";
|
|
45
61
|
export { asLink } from "./helpers/asLink";
|
|
62
|
+
export { asLinkAttrs } from "./helpers/asLinkAttrs";
|
|
46
63
|
export { asText } from "./helpers/asText";
|
|
47
64
|
export { asHTML } from "./helpers/asHTML";
|
|
48
65
|
export { asImageSrc } from "./helpers/asImageSrc";
|
|
@@ -56,16 +73,39 @@ export { documentToLinkField } from "./helpers/documentToLinkField";
|
|
|
56
73
|
// RichText element types.
|
|
57
74
|
export { Element } from "@prismicio/richtext";
|
|
58
75
|
|
|
76
|
+
export type { LinkResolverFunction } from "./helpers/asLink";
|
|
77
|
+
export type { AsLinkAttrsConfig } from "./helpers/asLinkAttrs";
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Renamed to `HTMLRichTextMapSerializer`
|
|
81
|
+
*/
|
|
82
|
+
type HTMLMapSerializer = HTMLRichTextMapSerializer;
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated Renamed to `HTMLRichTextFunctionSerializer`
|
|
85
|
+
*/
|
|
86
|
+
type HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;
|
|
59
87
|
export type {
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
HTMLRichTextMapSerializer,
|
|
89
|
+
HTMLRichTextFunctionSerializer,
|
|
62
90
|
HTMLMapSerializer,
|
|
63
|
-
|
|
91
|
+
HTMLFunctionSerializer,
|
|
92
|
+
};
|
|
93
|
+
export type { HTMLRichTextSerializer } from "./helpers/asHTML";
|
|
64
94
|
|
|
65
95
|
//=============================================================================
|
|
66
|
-
//
|
|
96
|
+
// Errors - Custom errors for Prismic APIs.
|
|
67
97
|
//=============================================================================
|
|
68
98
|
|
|
99
|
+
export { PrismicError } from "./errors/PrismicError";
|
|
100
|
+
export { ForbiddenError } from "./errors/ForbiddenError";
|
|
101
|
+
export { NotFoundError } from "./errors/NotFoundError";
|
|
102
|
+
export { ParsingError } from "./errors/ParsingError";
|
|
103
|
+
|
|
104
|
+
//=============================================================================
|
|
105
|
+
// Types - Types representing Prismic content, models, and API payloads.
|
|
106
|
+
//=============================================================================
|
|
107
|
+
|
|
108
|
+
// Values - Types representing Prismic content.
|
|
69
109
|
export { RichTextNodeType } from "./types/value/richText";
|
|
70
110
|
export { LinkType } from "./types/value/link";
|
|
71
111
|
export { OEmbedType } from "./types/value/embed";
|
|
@@ -167,10 +207,7 @@ export type { SharedSliceVariation } from "./types/value/sharedSliceVariation";
|
|
|
167
207
|
|
|
168
208
|
export type { FieldState, AnyRegularField } from "./types/value/types";
|
|
169
209
|
|
|
170
|
-
|
|
171
|
-
// Model - Types representing Prismic Custom Type and Shared Slice models.
|
|
172
|
-
//=============================================================================
|
|
173
|
-
|
|
210
|
+
// Models - Types representing Prismic content models.
|
|
174
211
|
export { CustomTypeModelFieldType } from "./types/model/types";
|
|
175
212
|
export { CustomTypeModelLinkSelectType } from "./types/model/link";
|
|
176
213
|
export { CustomTypeModelSliceType } from "./types/model/sliceZone";
|
|
@@ -234,10 +271,7 @@ export type {
|
|
|
234
271
|
CustomTypeModelFieldForGroup,
|
|
235
272
|
} from "./types/model/types";
|
|
236
273
|
|
|
237
|
-
//=============================================================================
|
|
238
274
|
// API - Types representing Prismic Rest API V2 responses.
|
|
239
|
-
//=============================================================================
|
|
240
|
-
|
|
241
275
|
export type { Query } from "./types/api/query";
|
|
242
276
|
|
|
243
277
|
export type { Ref } from "./types/api/ref";
|
|
@@ -253,10 +287,7 @@ export type {
|
|
|
253
287
|
|
|
254
288
|
export type { Tags } from "./types/api/tags";
|
|
255
289
|
|
|
256
|
-
//=============================================================================
|
|
257
290
|
// Webhook - Types representing Prismic webhooks.
|
|
258
|
-
//=============================================================================
|
|
259
|
-
|
|
260
291
|
export { WebhookType } from "./types/webhook/types";
|
|
261
292
|
|
|
262
293
|
export type { WebhookBody } from "./types/webhook/types";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { castArray } from "./castArray";
|
|
2
|
+
|
|
3
|
+
interface WithFilters {
|
|
4
|
+
filters?: string | string[];
|
|
5
|
+
}
|
|
6
|
+
|
|
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.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - Object to which filters will be append.
|
|
12
|
+
* @param objWithFilters - Object to append filters on the `filters`
|
|
13
|
+
* property.
|
|
14
|
+
* @param filters - One or more filters to append.
|
|
15
|
+
*
|
|
16
|
+
* @returns The object with the appended filters.
|
|
17
|
+
*/
|
|
18
|
+
export const appendFilters = <T extends WithFilters>(
|
|
19
|
+
objWithFilters: T = {} as T,
|
|
20
|
+
filters: string | string[],
|
|
21
|
+
): T & { filters: string[] } => {
|
|
22
|
+
return {
|
|
23
|
+
...objWithFilters,
|
|
24
|
+
filters: [...(objWithFilters.filters || []), ...castArray(filters)],
|
|
25
|
+
};
|
|
26
|
+
};
|
package/src/lib/castArray.ts
CHANGED
package/src/lib/castThunk.ts
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @returns `a` as a a thunk.
|
|
9
9
|
*/
|
|
10
|
-
export const castThunk = <A>(a: A | (() => A)): (() => A) =>
|
|
11
|
-
typeof a === "function" ? (a as () => A) : () => a;
|
|
10
|
+
export const castThunk = <A>(a: A | (() => A)): (() => A) => {
|
|
11
|
+
return typeof a === "function" ? (a as () => A) : () => a;
|
|
12
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { version } from "../../package.json";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* devMsg("missing-param");
|
|
10
|
+
* // => "https://prismic.dev/msg/client/v1.2.3/missing-param.md"
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
14
|
+
* the Git repository's `/messages` directory.
|
|
15
|
+
*
|
|
16
|
+
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
17
|
+
*/
|
|
18
|
+
export const devMsg = (slug: string): string => {
|
|
19
|
+
return `https://prismic.dev/msg/client/v${version}/${slug}`;
|
|
20
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** Core logic from https://github.com/component/escape-html
|
|
3
|
+
** Many thanks to @component
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const matchHtmlRegExp = /["'&<>]/;
|
|
7
|
+
|
|
8
|
+
export const escapeHTML = (string?: string | null): string => {
|
|
9
|
+
const str = "" + string;
|
|
10
|
+
const match = matchHtmlRegExp.exec(str);
|
|
11
|
+
|
|
12
|
+
if (!match) {
|
|
13
|
+
return str;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let escape;
|
|
17
|
+
let html = "";
|
|
18
|
+
let index = 0;
|
|
19
|
+
let lastIndex = 0;
|
|
20
|
+
|
|
21
|
+
for (index = match.index; index < str.length; index++) {
|
|
22
|
+
switch (str.charCodeAt(index)) {
|
|
23
|
+
case 34: // "
|
|
24
|
+
escape = """;
|
|
25
|
+
break;
|
|
26
|
+
case 38: // &
|
|
27
|
+
escape = "&";
|
|
28
|
+
break;
|
|
29
|
+
case 39: // '
|
|
30
|
+
escape = "'";
|
|
31
|
+
break;
|
|
32
|
+
case 60: // <
|
|
33
|
+
escape = "<";
|
|
34
|
+
break;
|
|
35
|
+
case 62: // >
|
|
36
|
+
escape = ">";
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (lastIndex !== index) {
|
|
43
|
+
html += str.substring(lastIndex, index);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
lastIndex = index + 1;
|
|
47
|
+
html += escape;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
|
51
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { filter } from "../filter";
|
|
2
|
+
|
|
3
|
+
import { castArray } from "./castArray";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a filter to filter content by document tags. All tags are required
|
|
7
|
+
* on the document.
|
|
8
|
+
*
|
|
9
|
+
* @param tags - Document tags to filter queried content.
|
|
10
|
+
*
|
|
11
|
+
* @returns A filter that can be used in a Prismic REST API V2 request.
|
|
12
|
+
*/
|
|
13
|
+
export const everyTagFilter = (tags: string | string[]): string => {
|
|
14
|
+
return filter.at("document.tags", castArray(tags));
|
|
15
|
+
};
|
package/src/lib/findRef.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
|
-
import { PrismicError } from "../PrismicError";
|
|
3
|
+
import { PrismicError } from "../errors/PrismicError";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Returns the first ref from a list that passes a
|
|
6
|
+
* Returns the first ref from a list that passes a filter (a function that
|
|
7
7
|
* returns true).
|
|
8
8
|
*
|
|
9
9
|
* @param refs - A list of refs to search.
|
|
10
|
-
* @param
|
|
10
|
+
* @param filter - A function that determines if a ref from the list matches
|
|
11
11
|
* the criteria.
|
|
12
12
|
*
|
|
13
13
|
* @returns The first matching ref.
|
|
14
14
|
* @throws If a matching ref cannot be found.
|
|
15
15
|
*/
|
|
16
|
-
export const findRef = (refs: Ref[],
|
|
17
|
-
const ref = refs.find((ref) =>
|
|
16
|
+
export const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {
|
|
17
|
+
const ref = refs.find((ref) => filter(ref));
|
|
18
18
|
|
|
19
19
|
if (!ref) {
|
|
20
20
|
throw new PrismicError("Ref could not be found.", undefined, undefined);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a URL is internal or external.
|
|
3
|
+
*
|
|
4
|
+
* @param url - The URL to check if internal or external.
|
|
5
|
+
*
|
|
6
|
+
* @returns `true` if `url` is internal, `false` otherwise.
|
|
7
|
+
*/
|
|
8
|
+
// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a "/" or "#"`.
|
|
9
|
+
export const isInternalURL = (url: string): boolean => {
|
|
10
|
+
const isInternal = /^(\/(?!\/)|#)/.test(url);
|
|
11
|
+
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
|
|
12
|
+
|
|
13
|
+
return isInternal && !isSpecialLink;
|
|
14
|
+
};
|