@prismicio/client 6.7.3 → 7.0.0-alpha.1
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 +25 -6
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +207 -130
- package/dist/buildQueryURL.js +25 -6
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/cookie.d.ts +5 -5
- package/dist/createClient.cjs +1142 -0
- package/dist/createClient.cjs.map +1 -0
- package/dist/{client.d.ts → createClient.d.ts} +980 -929
- package/dist/createClient.js +1142 -0
- package/dist/createClient.js.map +1 -0
- 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/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/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/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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +14 -0
- package/dist/helpers/asDate.cjs.map +1 -0
- package/dist/helpers/asDate.d.ts +16 -0
- package/dist/helpers/asDate.js +14 -0
- package/dist/helpers/asDate.js.map +1 -0
- package/dist/helpers/asHTML.cjs +80 -0
- package/dist/helpers/asHTML.cjs.map +1 -0
- package/dist/helpers/asHTML.d.ts +77 -0
- package/dist/helpers/asHTML.js +80 -0
- package/dist/helpers/asHTML.js.map +1 -0
- package/dist/helpers/asImagePixelDensitySrcSet.cjs +21 -0
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -0
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -0
- package/dist/helpers/asImagePixelDensitySrcSet.js +21 -0
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -0
- package/dist/helpers/asImageSrc.cjs +13 -0
- package/dist/helpers/asImageSrc.cjs.map +1 -0
- package/dist/helpers/asImageSrc.d.ts +27 -0
- package/dist/helpers/asImageSrc.js +13 -0
- package/dist/helpers/asImageSrc.js.map +1 -0
- package/dist/helpers/asImageWidthSrcSet.cjs +45 -0
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -0
- package/dist/helpers/asImageWidthSrcSet.d.ts +60 -0
- package/dist/helpers/asImageWidthSrcSet.js +45 -0
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -0
- package/dist/helpers/asLink.cjs +38 -0
- package/dist/helpers/asLink.cjs.map +1 -0
- package/dist/helpers/asLink.d.ts +34 -0
- package/dist/helpers/asLink.js +38 -0
- package/dist/helpers/asLink.js.map +1 -0
- 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 +12 -0
- package/dist/helpers/asText.cjs.map +1 -0
- package/dist/helpers/asText.d.ts +16 -0
- package/dist/helpers/asText.js +12 -0
- package/dist/helpers/asText.js.map +1 -0
- package/dist/helpers/documentToLinkField.cjs +26 -0
- package/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/helpers/documentToLinkField.d.ts +15 -0
- package/dist/helpers/documentToLinkField.js +26 -0
- package/dist/helpers/documentToLinkField.js.map +1 -0
- package/dist/helpers/isFilled.cjs +67 -0
- package/dist/helpers/isFilled.cjs.map +1 -0
- package/dist/helpers/isFilled.d.ts +172 -0
- package/dist/helpers/isFilled.js +67 -0
- package/dist/helpers/isFilled.js.map +1 -0
- package/dist/index.cjs +56 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +138 -88
- package/dist/index.js +50 -16
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +10 -10
- package/dist/isRepositoryName.d.ts +9 -9
- 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 +3 -1
- 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 +3 -1
- 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.map +1 -1
- package/dist/lib/findMasterRef.d.ts +10 -10
- package/dist/lib/findMasterRef.js.map +1 -1
- package/dist/lib/findRef.cjs +3 -3
- 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.map +1 -1
- package/dist/lib/findRefByID.d.ts +11 -11
- package/dist/lib/findRefByID.js.map +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 +1 -1
- 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.d.ts +8 -8
- package/dist/lib/serializerHelpers.cjs +54 -0
- package/dist/lib/serializerHelpers.cjs.map +1 -0
- package/dist/lib/serializerHelpers.d.ts +9 -0
- package/dist/lib/serializerHelpers.js +54 -0
- package/dist/lib/serializerHelpers.js.map +1 -0
- 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 -0
- package/dist/types/api/ref.d.ts +32 -0
- package/dist/types/api/release.d.ts +10 -0
- package/dist/types/api/repository.d.ts +100 -0
- package/dist/types/api/tags.d.ts +8 -0
- package/dist/types/model/boolean.d.ts +15 -0
- package/dist/types/model/color.d.ts +13 -0
- package/dist/types/model/contentRelationship.d.ts +18 -0
- package/dist/types/model/customType.d.ts +42 -0
- package/dist/types/model/date.d.ts +14 -0
- package/dist/types/model/embed.d.ts +13 -0
- package/dist/types/model/geoPoint.d.ts +12 -0
- package/dist/types/model/group.d.ts +15 -0
- package/dist/types/model/image.d.ts +31 -0
- package/dist/types/model/integrationFields.d.ts +14 -0
- package/dist/types/model/keyText.d.ts +13 -0
- package/dist/types/model/link.cjs +9 -0
- package/dist/types/model/link.cjs.map +1 -0
- package/dist/types/model/link.d.ts +27 -0
- package/dist/types/model/link.js +9 -0
- package/dist/types/model/link.js.map +1 -0
- package/dist/types/model/linkToMedia.d.ts +16 -0
- package/dist/types/model/number.d.ts +15 -0
- package/dist/types/model/range.d.ts +14 -0
- package/dist/types/model/richText.d.ts +35 -0
- package/dist/types/model/select.d.ts +18 -0
- package/dist/types/model/separator.d.ts +10 -0
- package/dist/types/model/sharedSlice.d.ts +16 -0
- package/dist/types/model/sharedSliceVariation.d.ts +19 -0
- package/dist/types/model/slice.cjs +8 -0
- package/dist/types/model/slice.cjs.map +1 -0
- package/dist/types/model/slice.d.ts +33 -0
- package/dist/types/model/slice.js +8 -0
- package/dist/types/model/slice.js.map +1 -0
- package/dist/types/model/sliceZone.cjs +8 -0
- package/dist/types/model/sliceZone.cjs.map +1 -0
- package/dist/types/model/sliceZone.d.ts +41 -0
- package/dist/types/model/sliceZone.js +8 -0
- package/dist/types/model/sliceZone.js.map +1 -0
- package/dist/types/model/timestamp.d.ts +14 -0
- package/dist/types/model/title.d.ts +7 -0
- package/dist/types/model/types.cjs +34 -0
- package/dist/types/model/types.cjs.map +1 -0
- package/dist/types/model/types.d.ts +62 -0
- package/dist/types/model/types.js +34 -0
- package/dist/types/model/types.js.map +1 -0
- package/dist/types/model/uid.d.ts +13 -0
- package/dist/types/value/boolean.d.ts +6 -0
- package/dist/types/value/color.d.ts +8 -0
- package/dist/types/value/contentRelationship.d.ts +29 -0
- package/dist/types/value/date.d.ts +8 -0
- package/dist/types/value/document.d.ts +113 -0
- package/dist/types/value/embed.cjs +10 -0
- package/dist/types/value/embed.cjs.map +1 -0
- package/dist/types/value/embed.d.ts +167 -0
- package/dist/types/value/embed.js +10 -0
- package/dist/types/value/embed.js.map +1 -0
- package/dist/types/value/geoPoint.d.ts +11 -0
- package/dist/types/value/group.d.ts +7 -0
- package/dist/types/value/image.d.ts +36 -0
- package/dist/types/value/integrationFields.d.ts +9 -0
- package/dist/types/value/keyText.d.ts +8 -0
- package/dist/types/value/link.cjs +10 -0
- package/dist/types/value/link.cjs.map +1 -0
- package/dist/types/value/link.d.ts +40 -0
- package/dist/types/value/link.js +10 -0
- package/dist/types/value/link.js.map +1 -0
- package/dist/types/value/linkToMedia.d.ts +20 -0
- package/dist/types/value/number.d.ts +8 -0
- package/dist/types/value/richText.cjs +25 -0
- package/dist/types/value/richText.cjs.map +1 -0
- package/dist/types/value/richText.d.ts +203 -0
- package/dist/types/value/richText.js +25 -0
- package/dist/types/value/richText.js.map +1 -0
- package/dist/types/value/select.d.ts +9 -0
- package/dist/types/value/sharedSlice.d.ts +11 -0
- package/dist/types/value/sharedSliceVariation.d.ts +7 -0
- package/dist/types/value/slice.d.ts +13 -0
- package/dist/types/value/sliceZone.d.ts +12 -0
- package/dist/types/value/timestamp.d.ts +8 -0
- package/dist/types/value/title.d.ts +12 -0
- package/dist/types/value/types.d.ts +40 -0
- package/dist/types/webhook/apiUpdate.d.ts +52 -0
- package/dist/types/webhook/testTrigger.d.ts +9 -0
- package/dist/types/webhook/types.cjs +8 -0
- package/dist/types/webhook/types.cjs.map +1 -0
- package/dist/types/webhook/types.d.ts +18 -0
- package/dist/types/webhook/types.js +8 -0
- package/dist/types/webhook/types.js.map +1 -0
- package/package.json +42 -36
- package/src/buildQueryURL.ts +179 -32
- package/src/{client.ts → createClient.ts} +248 -186
- 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 +48 -0
- package/src/helpers/asHTML.ts +249 -0
- package/src/helpers/asImagePixelDensitySrcSet.ts +96 -0
- package/src/helpers/asImageSrc.ts +41 -0
- package/src/helpers/asImageWidthSrcSet.ts +139 -0
- package/src/helpers/asLink.ts +118 -0
- package/src/helpers/asLinkAttrs.ts +127 -0
- package/src/helpers/asText.ts +29 -0
- package/src/helpers/documentToLinkField.ts +47 -0
- package/src/helpers/isFilled.ts +288 -0
- package/src/index.ts +277 -31
- 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/findMasterRef.ts +2 -2
- package/src/lib/findRef.ts +6 -9
- package/src/lib/findRefByID.ts +2 -2
- package/src/lib/findRefByLabel.ts +2 -5
- package/src/lib/getPreviewCookie.ts +1 -1
- package/src/lib/isInternalURL.ts +14 -0
- package/src/lib/serializerHelpers.ts +101 -0
- package/src/lib/someTagsFilter.ts +15 -0
- package/src/lib/typeFilter.ts +12 -0
- package/src/types/api/query.ts +50 -0
- package/src/types/api/ref.ts +36 -0
- package/src/types/api/release.ts +11 -0
- package/src/types/api/repository.ts +117 -0
- package/src/types/api/tags.ts +8 -0
- package/src/types/model/boolean.ts +16 -0
- package/src/types/model/color.ts +14 -0
- package/src/types/model/contentRelationship.ts +23 -0
- package/src/types/model/customType.ts +61 -0
- package/src/types/model/date.ts +15 -0
- package/src/types/model/embed.ts +14 -0
- package/src/types/model/geoPoint.ts +13 -0
- package/src/types/model/group.ts +24 -0
- package/src/types/model/image.ts +37 -0
- package/src/types/model/integrationFields.ts +15 -0
- package/src/types/model/keyText.ts +14 -0
- package/src/types/model/link.ts +31 -0
- package/src/types/model/linkToMedia.ts +18 -0
- package/src/types/model/number.ts +16 -0
- package/src/types/model/range.ts +15 -0
- package/src/types/model/richText.ts +40 -0
- package/src/types/model/select.ts +22 -0
- package/src/types/model/separator.ts +11 -0
- package/src/types/model/sharedSlice.ts +20 -0
- package/src/types/model/sharedSliceVariation.ts +30 -0
- package/src/types/model/slice.ts +50 -0
- package/src/types/model/sliceZone.ts +60 -0
- package/src/types/model/timestamp.ts +15 -0
- package/src/types/model/title.ts +8 -0
- package/src/types/model/types.ts +87 -0
- package/src/types/model/uid.ts +14 -0
- package/src/types/value/boolean.ts +6 -0
- package/src/types/value/color.ts +10 -0
- package/src/types/value/contentRelationship.ts +47 -0
- package/src/types/value/date.ts +10 -0
- package/src/types/value/document.ts +143 -0
- package/src/types/value/embed.ts +196 -0
- package/src/types/value/geoPoint.ts +15 -0
- package/src/types/value/group.ts +14 -0
- package/src/types/value/image.ts +67 -0
- package/src/types/value/integrationFields.ts +13 -0
- package/src/types/value/keyText.ts +10 -0
- package/src/types/value/link.ts +59 -0
- package/src/types/value/linkToMedia.ts +26 -0
- package/src/types/value/number.ts +10 -0
- package/src/types/value/richText.ts +287 -0
- package/src/types/value/select.ts +13 -0
- package/src/types/value/sharedSlice.ts +15 -0
- package/src/types/value/sharedSliceVariation.ts +18 -0
- package/src/types/value/slice.ts +24 -0
- package/src/types/value/sliceZone.ts +17 -0
- package/src/types/value/timestamp.ts +13 -0
- package/src/types/value/title.ts +32 -0
- package/src/types/value/types.ts +58 -0
- package/src/types/webhook/apiUpdate.ts +56 -0
- package/src/types/webhook/testTrigger.ts +10 -0
- package/src/types/webhook/types.ts +21 -0
- 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 -436
- package/dist/client.cjs.map +0 -1
- package/dist/client.js +0 -419
- 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/lib/orElseThrow.d.ts +0 -11
- 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.d.ts +0 -156
- package/src/lib/appendPredicates.ts +0 -29
- package/src/lib/orElseThrow.ts +0 -17
- package/src/predicate.ts +0 -359
- package/src/types.ts +0 -191
- /package/dist/{ForbiddenError.cjs → errors/ForbiddenError.cjs} +0 -0
- /package/dist/{ForbiddenError.js → errors/ForbiddenError.js} +0 -0
- /package/dist/{NotFoundError.cjs → errors/NotFoundError.cjs} +0 -0
- /package/dist/{NotFoundError.js → errors/NotFoundError.js} +0 -0
- /package/dist/{ParsingError.cjs → errors/ParsingError.cjs} +0 -0
- /package/dist/{ParsingError.js → errors/ParsingError.js} +0 -0
- /package/dist/{PrismicError.cjs → errors/PrismicError.cjs} +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
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as prismicH from "@prismicio/helpers";
|
|
3
|
-
|
|
4
|
-
import { appendPredicates } from "./lib/appendPredicates";
|
|
5
|
-
import { castArray } from "./lib/castArray";
|
|
1
|
+
import { appendFilters } from "./lib/appendFilters";
|
|
6
2
|
import { castThunk } from "./lib/castThunk";
|
|
3
|
+
import { everyTagFilter } from "./lib/everyTagFilter";
|
|
7
4
|
import { findMasterRef } from "./lib/findMasterRef";
|
|
8
5
|
import { findRefByID } from "./lib/findRefByID";
|
|
9
6
|
import { findRefByLabel } from "./lib/findRefByLabel";
|
|
10
7
|
import { getPreviewCookie } from "./lib/getPreviewCookie";
|
|
11
8
|
import { minifyGraphQLQuery } from "./lib/minifyGraphQLQuery";
|
|
9
|
+
import { someTagsFilter } from "./lib/someTagsFilter";
|
|
10
|
+
import { typeFilter } from "./lib/typeFilter";
|
|
11
|
+
|
|
12
|
+
import type { Query } from "./types/api/query";
|
|
13
|
+
import type { Ref } from "./types/api/ref";
|
|
14
|
+
import type { Form, Repository } from "./types/api/repository";
|
|
15
|
+
import type { PrismicDocument } from "./types/value/document";
|
|
16
|
+
|
|
17
|
+
import { ForbiddenError } from "./errors/ForbiddenError";
|
|
18
|
+
import { NotFoundError } from "./errors/NotFoundError";
|
|
19
|
+
import { ParsingError } from "./errors/ParsingError";
|
|
20
|
+
import { PrismicError } from "./errors/PrismicError";
|
|
21
|
+
|
|
22
|
+
import { LinkResolverFunction, asLink } from "./helpers/asLink";
|
|
12
23
|
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
FetchLike,
|
|
16
|
-
HttpRequestLike,
|
|
17
|
-
ExtractDocumentType,
|
|
18
|
-
} from "./types";
|
|
19
|
-
import { ForbiddenError } from "./ForbiddenError";
|
|
20
|
-
import { NotFoundError } from "./NotFoundError";
|
|
21
|
-
import { ParsingError } from "./ParsingError";
|
|
22
|
-
import { PrismicError } from "./PrismicError";
|
|
23
|
-
import { buildQueryURL, BuildQueryURLArgs } from "./buildQueryURL";
|
|
24
|
+
import { BuildQueryURLArgs, buildQueryURL } from "./buildQueryURL";
|
|
25
|
+
import { filter } from "./filter";
|
|
24
26
|
import { getRepositoryEndpoint } from "./getRepositoryEndpoint";
|
|
25
27
|
import { isRepositoryEndpoint } from "./isRepositoryEndpoint";
|
|
26
|
-
import { predicate } from "./predicate";
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* The largest page size allowed by the Prismic REST API V2. This value is used
|
|
@@ -48,6 +49,98 @@ export const REPOSITORY_CACHE_TTL = 5000;
|
|
|
48
49
|
*/
|
|
49
50
|
export const GET_ALL_QUERY_DELAY = 500;
|
|
50
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Extracts one or more Prismic document types that match a given Prismic
|
|
54
|
+
* document type. If no matches are found, no extraction is performed and the
|
|
55
|
+
* union of all provided Prismic document types are returned.
|
|
56
|
+
*
|
|
57
|
+
* @typeParam TDocuments - Prismic document types from which to extract.
|
|
58
|
+
* @typeParam TDocumentType - Type(s) to match `TDocuments` against.
|
|
59
|
+
*/
|
|
60
|
+
type ExtractDocumentType<
|
|
61
|
+
TDocuments extends PrismicDocument,
|
|
62
|
+
TDocumentType extends TDocuments["type"],
|
|
63
|
+
> = Extract<TDocuments, { type: TDocumentType }> extends never
|
|
64
|
+
? TDocuments
|
|
65
|
+
: Extract<TDocuments, { type: TDocumentType }>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A universal API to make network requests. A subset of the `fetch()` API.
|
|
69
|
+
*
|
|
70
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
|
|
71
|
+
*/
|
|
72
|
+
export type FetchLike = (
|
|
73
|
+
input: string,
|
|
74
|
+
init?: RequestInitLike,
|
|
75
|
+
) => Promise<ResponseLike>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* An object that allows you to abort a `fetch()` request if needed via an
|
|
79
|
+
* `AbortController` object
|
|
80
|
+
*
|
|
81
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
82
|
+
*/
|
|
83
|
+
// `any` is used often here to ensure this type is universally valid among
|
|
84
|
+
// different AbortSignal implementations. The types of each property are not
|
|
85
|
+
// important to validate since it is blindly passed to a given `fetch()`
|
|
86
|
+
// function.
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
export type AbortSignalLike = any;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The minimum required properties from RequestInit.
|
|
92
|
+
*/
|
|
93
|
+
export interface RequestInitLike {
|
|
94
|
+
headers?: Record<string, string>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* An object that allows you to abort a `fetch()` request if needed via an
|
|
98
|
+
* `AbortController` object
|
|
99
|
+
*
|
|
100
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
101
|
+
*/
|
|
102
|
+
// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`
|
|
103
|
+
// for backwards compatibility (the type is exported) and to signal to
|
|
104
|
+
// other readers that this should be an AbortSignal-like object.
|
|
105
|
+
signal?: AbortSignalLike;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The minimum required properties from Response.
|
|
110
|
+
*/
|
|
111
|
+
export interface ResponseLike {
|
|
112
|
+
status: number;
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
|
+
json(): Promise<any>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The minimum required properties to treat as an HTTP Request for automatic
|
|
119
|
+
* Prismic preview support.
|
|
120
|
+
*/
|
|
121
|
+
export type HttpRequestLike =
|
|
122
|
+
| /**
|
|
123
|
+
* Web API Request
|
|
124
|
+
*
|
|
125
|
+
* @see http://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
126
|
+
*/
|
|
127
|
+
{
|
|
128
|
+
headers?: {
|
|
129
|
+
get(name: string): string | null;
|
|
130
|
+
};
|
|
131
|
+
url?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Express-style Request
|
|
136
|
+
*/
|
|
137
|
+
| {
|
|
138
|
+
headers?: {
|
|
139
|
+
cookie?: string;
|
|
140
|
+
};
|
|
141
|
+
query?: Record<string, unknown>;
|
|
142
|
+
};
|
|
143
|
+
|
|
51
144
|
/**
|
|
52
145
|
* Modes for client ref management.
|
|
53
146
|
*/
|
|
@@ -135,7 +228,7 @@ export type ClientConfig = {
|
|
|
135
228
|
* A list of Route Resolver objects that define how a document's `url` field
|
|
136
229
|
* is resolved.
|
|
137
230
|
*
|
|
138
|
-
* {@link https://prismic.io/docs/
|
|
231
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
139
232
|
*/
|
|
140
233
|
routes?: NonNullable<BuildQueryURLArgs["routes"]>;
|
|
141
234
|
|
|
@@ -145,7 +238,7 @@ export type ClientConfig = {
|
|
|
145
238
|
* link is a Link or Content Relationship field whose linked document has been
|
|
146
239
|
* unpublished or deleted.
|
|
147
240
|
*
|
|
148
|
-
* {@link https://prismic.io/docs/
|
|
241
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
149
242
|
*/
|
|
150
243
|
brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
|
|
151
244
|
|
|
@@ -199,7 +292,7 @@ type ResolvePreviewArgs<LinkResolverReturnType> = {
|
|
|
199
292
|
/**
|
|
200
293
|
* A function that maps a Prismic document to a URL within your app.
|
|
201
294
|
*/
|
|
202
|
-
linkResolver?:
|
|
295
|
+
linkResolver?: LinkResolverFunction<LinkResolverReturnType>;
|
|
203
296
|
|
|
204
297
|
/**
|
|
205
298
|
* A fallback URL if the Link Resolver does not return a value.
|
|
@@ -219,43 +312,20 @@ type ResolvePreviewArgs<LinkResolverReturnType> = {
|
|
|
219
312
|
};
|
|
220
313
|
|
|
221
314
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @param documentType - The document type to filter queried content.
|
|
225
|
-
*
|
|
226
|
-
* @returns A predicate that can be used in a Prismic REST API V2 request.
|
|
227
|
-
*/
|
|
228
|
-
const typePredicate = (documentType: string): string =>
|
|
229
|
-
predicate.at("document.type", documentType);
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Creates a predicate to filter content by document tags. All tags are required
|
|
233
|
-
* on the document.
|
|
234
|
-
*
|
|
235
|
-
* @param tags - Document tags to filter queried content.
|
|
236
|
-
*
|
|
237
|
-
* @returns A predicate that can be used in a Prismic REST API V2 request.
|
|
238
|
-
*/
|
|
239
|
-
const everyTagPredicate = (tags: string | string[]): string =>
|
|
240
|
-
predicate.at("document.tags", castArray(tags));
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Creates a predicate to filter content by document tags. At least one matching
|
|
244
|
-
* tag is required on the document.
|
|
245
|
-
*
|
|
246
|
-
* @param tags - Document tags to filter queried content.
|
|
247
|
-
*
|
|
248
|
-
* @returns A predicate that can be used in a Prismic REST API V2 request.
|
|
315
|
+
* The result of a `fetch()` job.
|
|
249
316
|
*/
|
|
250
|
-
|
|
251
|
-
|
|
317
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
318
|
+
type FetchJobResult<TJSON = any> = {
|
|
319
|
+
status: number;
|
|
320
|
+
json: TJSON;
|
|
321
|
+
};
|
|
252
322
|
|
|
253
323
|
/**
|
|
254
324
|
* Type definitions for the `createClient()` function. May be augmented by
|
|
255
325
|
* third-party libraries.
|
|
256
326
|
*/
|
|
257
327
|
export interface CreateClient {
|
|
258
|
-
<TDocuments extends
|
|
328
|
+
<TDocuments extends PrismicDocument>(
|
|
259
329
|
...args: ConstructorParameters<typeof Client>
|
|
260
330
|
): Client<TDocuments>;
|
|
261
331
|
}
|
|
@@ -282,9 +352,7 @@ export interface CreateClient {
|
|
|
282
352
|
*
|
|
283
353
|
* @returns A client that can query content from the repository.
|
|
284
354
|
*/
|
|
285
|
-
export const createClient: CreateClient = <
|
|
286
|
-
TDocuments extends prismicT.PrismicDocument,
|
|
287
|
-
>(
|
|
355
|
+
export const createClient: CreateClient = <TDocuments extends PrismicDocument>(
|
|
288
356
|
repositoryNameOrEndpoint: string,
|
|
289
357
|
options?: ClientConfig,
|
|
290
358
|
) => new Client<TDocuments>(repositoryNameOrEndpoint, options);
|
|
@@ -299,9 +367,7 @@ export const createClient: CreateClient = <
|
|
|
299
367
|
* @typeParam TDocuments - Document types that are registered for the Prismic
|
|
300
368
|
* repository. Query methods will automatically be typed based on this type.
|
|
301
369
|
*/
|
|
302
|
-
export class Client<
|
|
303
|
-
TDocuments extends prismicT.PrismicDocument = prismicT.PrismicDocument,
|
|
304
|
-
> {
|
|
370
|
+
export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
305
371
|
/**
|
|
306
372
|
* The Prismic REST API V2 endpoint for the repository (use
|
|
307
373
|
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
@@ -320,7 +386,7 @@ export class Client<
|
|
|
320
386
|
* A list of Route Resolver objects that define how a document's `url` field
|
|
321
387
|
* is resolved.
|
|
322
388
|
*
|
|
323
|
-
* {@link https://prismic.io/docs/
|
|
389
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
324
390
|
*/
|
|
325
391
|
routes?: NonNullable<BuildQueryURLArgs["routes"]>;
|
|
326
392
|
|
|
@@ -330,7 +396,7 @@ export class Client<
|
|
|
330
396
|
* link is a Link or Content Relationship field whose linked document has been
|
|
331
397
|
* unpublished or deleted.
|
|
332
398
|
*
|
|
333
|
-
* {@link https://prismic.io/docs/
|
|
399
|
+
* {@link https://prismic.io/docs/route-resolver}
|
|
334
400
|
*/
|
|
335
401
|
brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
|
|
336
402
|
|
|
@@ -362,13 +428,21 @@ export class Client<
|
|
|
362
428
|
/**
|
|
363
429
|
* Cached repository value.
|
|
364
430
|
*/
|
|
365
|
-
private cachedRepository:
|
|
431
|
+
private cachedRepository: Repository | undefined;
|
|
366
432
|
|
|
367
433
|
/**
|
|
368
434
|
* Timestamp at which the cached repository data is considered stale.
|
|
369
435
|
*/
|
|
370
436
|
private cachedRepositoryExpiration = 0;
|
|
371
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Active `fetch()` jobs keyed by URL and AbortSignal (if it exists).
|
|
440
|
+
*/
|
|
441
|
+
private fetchJobs: Record<
|
|
442
|
+
string,
|
|
443
|
+
Map<AbortSignalLike | undefined, Promise<FetchJobResult>>
|
|
444
|
+
> = {};
|
|
445
|
+
|
|
372
446
|
/**
|
|
373
447
|
* Creates a Prismic client that can be used to query a repository.
|
|
374
448
|
*
|
|
@@ -490,32 +564,6 @@ export class Client<
|
|
|
490
564
|
this.refState.autoPreviewsEnabled = false;
|
|
491
565
|
}
|
|
492
566
|
|
|
493
|
-
/**
|
|
494
|
-
* Queries content from the Prismic repository.
|
|
495
|
-
*
|
|
496
|
-
* @deprecated Use `get` instead.
|
|
497
|
-
* @example
|
|
498
|
-
*
|
|
499
|
-
* ```ts
|
|
500
|
-
* const response = await client.query(
|
|
501
|
-
* prismic.predicate.at("document.type", "page"),
|
|
502
|
-
* );
|
|
503
|
-
* ```
|
|
504
|
-
*
|
|
505
|
-
* @typeParam TDocument - Type of Prismic documents returned.
|
|
506
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
507
|
-
*
|
|
508
|
-
* @returns A paginated response containing the result of the query.
|
|
509
|
-
*/
|
|
510
|
-
async query<TDocument extends TDocuments>(
|
|
511
|
-
predicates: NonNullable<BuildQueryURLArgs["predicates"]>,
|
|
512
|
-
params?: Partial<Omit<BuildQueryURLArgs, "predicates">> & FetchParams,
|
|
513
|
-
): Promise<prismicT.Query<TDocument>> {
|
|
514
|
-
const url = await this.buildQueryURL({ ...params, predicates });
|
|
515
|
-
|
|
516
|
-
return await this.fetch<prismicT.Query<TDocument>>(url, params);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
567
|
/**
|
|
520
568
|
* Queries content from the Prismic repository.
|
|
521
569
|
*
|
|
@@ -532,10 +580,10 @@ export class Client<
|
|
|
532
580
|
*/
|
|
533
581
|
async get<TDocument extends TDocuments>(
|
|
534
582
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
535
|
-
): Promise<
|
|
583
|
+
): Promise<Query<TDocument>> {
|
|
536
584
|
const url = await this.buildQueryURL(params);
|
|
537
585
|
|
|
538
|
-
return await this.fetch<
|
|
586
|
+
return await this.fetch<Query<TDocument>>(url, params);
|
|
539
587
|
}
|
|
540
588
|
|
|
541
589
|
/**
|
|
@@ -557,10 +605,11 @@ export class Client<
|
|
|
557
605
|
): Promise<TDocument> {
|
|
558
606
|
const actualParams = { ...params };
|
|
559
607
|
if (!(params && params.page) && !params?.pageSize) {
|
|
560
|
-
actualParams.pageSize =
|
|
608
|
+
actualParams.pageSize =
|
|
609
|
+
this.defaultParams?.pageSize == null ? 1 : this.defaultParams?.pageSize;
|
|
561
610
|
}
|
|
562
611
|
const url = await this.buildQueryURL(actualParams);
|
|
563
|
-
const result = await this.fetch<
|
|
612
|
+
const result = await this.fetch<Query<TDocument>>(url, params);
|
|
564
613
|
|
|
565
614
|
const firstResult = result.results[0];
|
|
566
615
|
|
|
@@ -574,10 +623,10 @@ export class Client<
|
|
|
574
623
|
/**
|
|
575
624
|
* **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
|
|
576
625
|
* require more resources than other methods. Prefer using other methods that
|
|
577
|
-
* filter by
|
|
626
|
+
* filter by filters such as `getAllByType`.
|
|
578
627
|
*
|
|
579
628
|
* Queries content from the Prismic repository and returns all matching
|
|
580
|
-
* content. If no
|
|
629
|
+
* content. If no filters are provided, all documents will be fetched.
|
|
581
630
|
*
|
|
582
631
|
* This method may make multiple network requests to query all matching
|
|
583
632
|
* content.
|
|
@@ -608,7 +657,7 @@ export class Client<
|
|
|
608
657
|
};
|
|
609
658
|
|
|
610
659
|
const documents: TDocument[] = [];
|
|
611
|
-
let latestResult:
|
|
660
|
+
let latestResult: Query<TDocument> | undefined;
|
|
612
661
|
|
|
613
662
|
while (
|
|
614
663
|
(!latestResult || latestResult.next_page) &&
|
|
@@ -653,7 +702,7 @@ export class Client<
|
|
|
653
702
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
654
703
|
): Promise<TDocument> {
|
|
655
704
|
return await this.getFirst<TDocument>(
|
|
656
|
-
|
|
705
|
+
appendFilters(params, filter.at("document.id", id)),
|
|
657
706
|
);
|
|
658
707
|
}
|
|
659
708
|
|
|
@@ -684,9 +733,9 @@ export class Client<
|
|
|
684
733
|
async getByIDs<TDocument extends TDocuments>(
|
|
685
734
|
ids: string[],
|
|
686
735
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
687
|
-
): Promise<
|
|
736
|
+
): Promise<Query<TDocument>> {
|
|
688
737
|
return await this.get<TDocument>(
|
|
689
|
-
|
|
738
|
+
appendFilters(params, filter.in("document.id", ids)),
|
|
690
739
|
);
|
|
691
740
|
}
|
|
692
741
|
|
|
@@ -721,7 +770,7 @@ export class Client<
|
|
|
721
770
|
params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams,
|
|
722
771
|
): Promise<TDocument[]> {
|
|
723
772
|
return await this.dangerouslyGetAll<TDocument>(
|
|
724
|
-
|
|
773
|
+
appendFilters(params, filter.in("document.id", ids)),
|
|
725
774
|
);
|
|
726
775
|
}
|
|
727
776
|
|
|
@@ -757,9 +806,9 @@ export class Client<
|
|
|
757
806
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
758
807
|
): Promise<ExtractDocumentType<TDocument, TDocumentType>> {
|
|
759
808
|
return await this.getFirst<ExtractDocumentType<TDocument, TDocumentType>>(
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
809
|
+
appendFilters(params, [
|
|
810
|
+
typeFilter(documentType),
|
|
811
|
+
filter.at(`my.${documentType}.uid`, uid),
|
|
763
812
|
]),
|
|
764
813
|
);
|
|
765
814
|
}
|
|
@@ -797,11 +846,11 @@ export class Client<
|
|
|
797
846
|
documentType: TDocumentType,
|
|
798
847
|
uids: string[],
|
|
799
848
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
800
|
-
): Promise<
|
|
849
|
+
): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>> {
|
|
801
850
|
return await this.get<ExtractDocumentType<TDocument, TDocumentType>>(
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
851
|
+
appendFilters(params, [
|
|
852
|
+
typeFilter(documentType),
|
|
853
|
+
filter.in(`my.${documentType}.uid`, uids),
|
|
805
854
|
]),
|
|
806
855
|
);
|
|
807
856
|
}
|
|
@@ -845,9 +894,9 @@ export class Client<
|
|
|
845
894
|
return await this.dangerouslyGetAll<
|
|
846
895
|
ExtractDocumentType<TDocument, TDocumentType>
|
|
847
896
|
>(
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
897
|
+
appendFilters(params, [
|
|
898
|
+
typeFilter(documentType),
|
|
899
|
+
filter.in(`my.${documentType}.uid`, uids),
|
|
851
900
|
]),
|
|
852
901
|
);
|
|
853
902
|
}
|
|
@@ -882,7 +931,7 @@ export class Client<
|
|
|
882
931
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
883
932
|
): Promise<ExtractDocumentType<TDocument, TDocumentType>> {
|
|
884
933
|
return await this.getFirst<ExtractDocumentType<TDocument, TDocumentType>>(
|
|
885
|
-
|
|
934
|
+
appendFilters(params, typeFilter(documentType)),
|
|
886
935
|
);
|
|
887
936
|
}
|
|
888
937
|
|
|
@@ -910,9 +959,9 @@ export class Client<
|
|
|
910
959
|
>(
|
|
911
960
|
documentType: TDocumentType,
|
|
912
961
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
913
|
-
): Promise<
|
|
962
|
+
): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>> {
|
|
914
963
|
return await this.get<ExtractDocumentType<TDocument, TDocumentType>>(
|
|
915
|
-
|
|
964
|
+
appendFilters(params, typeFilter(documentType)),
|
|
916
965
|
);
|
|
917
966
|
}
|
|
918
967
|
|
|
@@ -946,7 +995,7 @@ export class Client<
|
|
|
946
995
|
): Promise<ExtractDocumentType<TDocument, TDocumentType>[]> {
|
|
947
996
|
return await this.dangerouslyGetAll<
|
|
948
997
|
ExtractDocumentType<TDocument, TDocumentType>
|
|
949
|
-
>(
|
|
998
|
+
>(appendFilters(params, typeFilter(documentType)));
|
|
950
999
|
}
|
|
951
1000
|
|
|
952
1001
|
/**
|
|
@@ -970,9 +1019,9 @@ export class Client<
|
|
|
970
1019
|
async getByTag<TDocument extends TDocuments>(
|
|
971
1020
|
tag: string,
|
|
972
1021
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
973
|
-
): Promise<
|
|
1022
|
+
): Promise<Query<TDocument>> {
|
|
974
1023
|
return await this.get<TDocument>(
|
|
975
|
-
|
|
1024
|
+
appendFilters(params, someTagsFilter(tag)),
|
|
976
1025
|
);
|
|
977
1026
|
}
|
|
978
1027
|
|
|
@@ -1001,7 +1050,7 @@ export class Client<
|
|
|
1001
1050
|
FetchParams,
|
|
1002
1051
|
): Promise<TDocument[]> {
|
|
1003
1052
|
return await this.dangerouslyGetAll<TDocument>(
|
|
1004
|
-
|
|
1053
|
+
appendFilters(params, someTagsFilter(tag)),
|
|
1005
1054
|
);
|
|
1006
1055
|
}
|
|
1007
1056
|
|
|
@@ -1024,9 +1073,9 @@ export class Client<
|
|
|
1024
1073
|
async getByEveryTag<TDocument extends TDocuments>(
|
|
1025
1074
|
tags: string[],
|
|
1026
1075
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
1027
|
-
): Promise<
|
|
1076
|
+
): Promise<Query<TDocument>> {
|
|
1028
1077
|
return await this.get<TDocument>(
|
|
1029
|
-
|
|
1078
|
+
appendFilters(params, everyTagFilter(tags)),
|
|
1030
1079
|
);
|
|
1031
1080
|
}
|
|
1032
1081
|
|
|
@@ -1056,7 +1105,7 @@ export class Client<
|
|
|
1056
1105
|
FetchParams,
|
|
1057
1106
|
): Promise<TDocument[]> {
|
|
1058
1107
|
return await this.dangerouslyGetAll<TDocument>(
|
|
1059
|
-
|
|
1108
|
+
appendFilters(params, everyTagFilter(tags)),
|
|
1060
1109
|
);
|
|
1061
1110
|
}
|
|
1062
1111
|
|
|
@@ -1081,9 +1130,9 @@ export class Client<
|
|
|
1081
1130
|
async getBySomeTags<TDocument extends TDocuments>(
|
|
1082
1131
|
tags: string[],
|
|
1083
1132
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
1084
|
-
): Promise<
|
|
1133
|
+
): Promise<Query<TDocument>> {
|
|
1085
1134
|
return await this.get<TDocument>(
|
|
1086
|
-
|
|
1135
|
+
appendFilters(params, someTagsFilter(tags)),
|
|
1087
1136
|
);
|
|
1088
1137
|
}
|
|
1089
1138
|
|
|
@@ -1114,7 +1163,7 @@ export class Client<
|
|
|
1114
1163
|
FetchParams,
|
|
1115
1164
|
): Promise<TDocument[]> {
|
|
1116
1165
|
return await this.dangerouslyGetAll<TDocument>(
|
|
1117
|
-
|
|
1166
|
+
appendFilters(params, someTagsFilter(tags)),
|
|
1118
1167
|
);
|
|
1119
1168
|
}
|
|
1120
1169
|
|
|
@@ -1124,9 +1173,9 @@ export class Client<
|
|
|
1124
1173
|
*
|
|
1125
1174
|
* @returns Repository metadata.
|
|
1126
1175
|
*/
|
|
1127
|
-
async getRepository(params?: FetchParams): Promise<
|
|
1176
|
+
async getRepository(params?: FetchParams): Promise<Repository> {
|
|
1128
1177
|
// TODO: Restore when Authorization header support works in browsers with CORS.
|
|
1129
|
-
// return await this.fetch<
|
|
1178
|
+
// return await this.fetch<Repository>(this.endpoint);
|
|
1130
1179
|
|
|
1131
1180
|
const url = new URL(this.endpoint);
|
|
1132
1181
|
|
|
@@ -1134,7 +1183,7 @@ export class Client<
|
|
|
1134
1183
|
url.searchParams.set("access_token", this.accessToken);
|
|
1135
1184
|
}
|
|
1136
1185
|
|
|
1137
|
-
return await this.fetch<
|
|
1186
|
+
return await this.fetch<Repository>(url.toString(), params);
|
|
1138
1187
|
}
|
|
1139
1188
|
|
|
1140
1189
|
/**
|
|
@@ -1146,7 +1195,7 @@ export class Client<
|
|
|
1146
1195
|
*
|
|
1147
1196
|
* @returns A list of all refs for the Prismic repository.
|
|
1148
1197
|
*/
|
|
1149
|
-
async getRefs(params?: FetchParams): Promise<
|
|
1198
|
+
async getRefs(params?: FetchParams): Promise<Ref[]> {
|
|
1150
1199
|
const repository = await this.getRepository(params);
|
|
1151
1200
|
|
|
1152
1201
|
return repository.refs;
|
|
@@ -1159,7 +1208,7 @@ export class Client<
|
|
|
1159
1208
|
*
|
|
1160
1209
|
* @returns The ref with a matching ID, if it exists.
|
|
1161
1210
|
*/
|
|
1162
|
-
async getRefByID(id: string, params?: FetchParams): Promise<
|
|
1211
|
+
async getRefByID(id: string, params?: FetchParams): Promise<Ref> {
|
|
1163
1212
|
const refs = await this.getRefs(params);
|
|
1164
1213
|
|
|
1165
1214
|
return findRefByID(refs, id);
|
|
@@ -1172,10 +1221,7 @@ export class Client<
|
|
|
1172
1221
|
*
|
|
1173
1222
|
* @returns The ref with a matching label, if it exists.
|
|
1174
1223
|
*/
|
|
1175
|
-
async getRefByLabel(
|
|
1176
|
-
label: string,
|
|
1177
|
-
params?: FetchParams,
|
|
1178
|
-
): Promise<prismicT.Ref> {
|
|
1224
|
+
async getRefByLabel(label: string, params?: FetchParams): Promise<Ref> {
|
|
1179
1225
|
const refs = await this.getRefs(params);
|
|
1180
1226
|
|
|
1181
1227
|
return findRefByLabel(refs, label);
|
|
@@ -1187,7 +1233,7 @@ export class Client<
|
|
|
1187
1233
|
*
|
|
1188
1234
|
* @returns The repository's master ref.
|
|
1189
1235
|
*/
|
|
1190
|
-
async getMasterRef(params?: FetchParams): Promise<
|
|
1236
|
+
async getMasterRef(params?: FetchParams): Promise<Ref> {
|
|
1191
1237
|
const refs = await this.getRefs(params);
|
|
1192
1238
|
|
|
1193
1239
|
return findMasterRef(refs);
|
|
@@ -1199,7 +1245,7 @@ export class Client<
|
|
|
1199
1245
|
*
|
|
1200
1246
|
* @returns A list of all Releases for the Prismic repository.
|
|
1201
1247
|
*/
|
|
1202
|
-
async getReleases(params?: FetchParams): Promise<
|
|
1248
|
+
async getReleases(params?: FetchParams): Promise<Ref[]> {
|
|
1203
1249
|
const refs = await this.getRefs(params);
|
|
1204
1250
|
|
|
1205
1251
|
return refs.filter((ref) => !ref.isMasterRef);
|
|
@@ -1212,10 +1258,7 @@ export class Client<
|
|
|
1212
1258
|
*
|
|
1213
1259
|
* @returns The Release with a matching ID, if it exists.
|
|
1214
1260
|
*/
|
|
1215
|
-
async getReleaseByID(
|
|
1216
|
-
id: string,
|
|
1217
|
-
params?: FetchParams,
|
|
1218
|
-
): Promise<prismicT.Ref> {
|
|
1261
|
+
async getReleaseByID(id: string, params?: FetchParams): Promise<Ref> {
|
|
1219
1262
|
const releases = await this.getReleases(params);
|
|
1220
1263
|
|
|
1221
1264
|
return findRefByID(releases, id);
|
|
@@ -1228,10 +1271,7 @@ export class Client<
|
|
|
1228
1271
|
*
|
|
1229
1272
|
* @returns The ref with a matching label, if it exists.
|
|
1230
1273
|
*/
|
|
1231
|
-
async getReleaseByLabel(
|
|
1232
|
-
label: string,
|
|
1233
|
-
params?: FetchParams,
|
|
1234
|
-
): Promise<prismicT.Ref> {
|
|
1274
|
+
async getReleaseByLabel(label: string, params?: FetchParams): Promise<Ref> {
|
|
1235
1275
|
const releases = await this.getReleases(params);
|
|
1236
1276
|
|
|
1237
1277
|
return findRefByLabel(releases, label);
|
|
@@ -1343,7 +1383,7 @@ export class Client<
|
|
|
1343
1383
|
lang: "*",
|
|
1344
1384
|
});
|
|
1345
1385
|
|
|
1346
|
-
const url =
|
|
1386
|
+
const url = asLink(document, args.linkResolver);
|
|
1347
1387
|
|
|
1348
1388
|
if (typeof url === "string") {
|
|
1349
1389
|
return url;
|
|
@@ -1444,12 +1484,6 @@ export class Client<
|
|
|
1444
1484
|
};
|
|
1445
1485
|
}
|
|
1446
1486
|
|
|
1447
|
-
/**
|
|
1448
|
-
* @deprecated Renamed to `graphQLFetch()` (note the capitalization of "QL").
|
|
1449
|
-
*/
|
|
1450
|
-
// TODO: Remove in v7
|
|
1451
|
-
graphqlFetch = this.graphQLFetch.bind(this);
|
|
1452
|
-
|
|
1453
1487
|
/**
|
|
1454
1488
|
* A `fetch()` function to be used with GraphQL clients configured for
|
|
1455
1489
|
* Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
|
|
@@ -1459,11 +1493,11 @@ export class Client<
|
|
|
1459
1493
|
* @example
|
|
1460
1494
|
*
|
|
1461
1495
|
* ```ts
|
|
1462
|
-
* const
|
|
1496
|
+
* const graphQLClient = new ApolloClient({
|
|
1463
1497
|
* link: new HttpLink({
|
|
1464
1498
|
* uri: prismic.getGraphQLEndpoint(repositoryName),
|
|
1465
|
-
* // Provide `client.
|
|
1466
|
-
* fetch: client.
|
|
1499
|
+
* // Provide `client.graphQLFetch` as the fetch implementation.
|
|
1500
|
+
* fetch: client.graphQLFetch,
|
|
1467
1501
|
* // Using GET is required.
|
|
1468
1502
|
* useGETForQueries: true,
|
|
1469
1503
|
* }),
|
|
@@ -1551,9 +1585,7 @@ export class Client<
|
|
|
1551
1585
|
*
|
|
1552
1586
|
* @returns Cached repository metadata.
|
|
1553
1587
|
*/
|
|
1554
|
-
private async getCachedRepository(
|
|
1555
|
-
params?: FetchParams,
|
|
1556
|
-
): Promise<prismicT.Repository> {
|
|
1588
|
+
private async getCachedRepository(params?: FetchParams): Promise<Repository> {
|
|
1557
1589
|
if (
|
|
1558
1590
|
!this.cachedRepository ||
|
|
1559
1591
|
Date.now() >= this.cachedRepositoryExpiration
|
|
@@ -1577,7 +1609,7 @@ export class Client<
|
|
|
1577
1609
|
private async getCachedRepositoryForm(
|
|
1578
1610
|
name: string,
|
|
1579
1611
|
params?: FetchParams,
|
|
1580
|
-
): Promise<
|
|
1612
|
+
): Promise<Form> {
|
|
1581
1613
|
const cachedRepository = await this.getCachedRepository(params);
|
|
1582
1614
|
const form = cachedRepository.forms[name];
|
|
1583
1615
|
|
|
@@ -1677,51 +1709,71 @@ export class Client<
|
|
|
1677
1709
|
*/
|
|
1678
1710
|
private async fetch<T = unknown>(
|
|
1679
1711
|
url: string,
|
|
1680
|
-
// TODO: Change to `params` when Authorization header support works in browsers with CORS.
|
|
1681
|
-
// _params?: Partial<BuildQueryURLArgs>,
|
|
1682
1712
|
params: FetchParams = {},
|
|
1683
1713
|
): Promise<T> {
|
|
1684
|
-
|
|
1685
|
-
// const accessToken = (params && params.accessToken) || this.accessToken;
|
|
1686
|
-
// const options = accessToken
|
|
1687
|
-
// ? { headers: { Authorization: `Token ${accessToken}` } }
|
|
1688
|
-
// : {};
|
|
1714
|
+
let job: Promise<FetchJobResult>;
|
|
1689
1715
|
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1716
|
+
// `fetchJobs` is keyed twice: first by the URL and again by is
|
|
1717
|
+
// signal, if one exists.
|
|
1718
|
+
//
|
|
1719
|
+
// Using two keys allows us to reuse fetch requests for
|
|
1720
|
+
// equivalent URLs, but eject when we detect unique signals.
|
|
1721
|
+
if (this.fetchJobs[url] && this.fetchJobs[url].has(params.signal)) {
|
|
1722
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1723
|
+
job = this.fetchJobs[url].get(params.signal)!;
|
|
1724
|
+
} else {
|
|
1725
|
+
this.fetchJobs[url] = this.fetchJobs[url] || new Map();
|
|
1726
|
+
|
|
1727
|
+
job = this.fetchFn(url, {
|
|
1728
|
+
signal: params.signal,
|
|
1729
|
+
})
|
|
1730
|
+
.then(async (res) => {
|
|
1731
|
+
// We can assume Prismic REST API responses
|
|
1732
|
+
// will have a `application/json`
|
|
1733
|
+
// Content Type. If not, this will
|
|
1734
|
+
// throw, signaling an invalid
|
|
1735
|
+
// response.
|
|
1736
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1737
|
+
let json: any = undefined;
|
|
1738
|
+
try {
|
|
1739
|
+
json = await res.json();
|
|
1740
|
+
} catch {
|
|
1741
|
+
// noop
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
return {
|
|
1745
|
+
status: res.status,
|
|
1746
|
+
json,
|
|
1747
|
+
};
|
|
1748
|
+
})
|
|
1749
|
+
.finally(() => {
|
|
1750
|
+
this.fetchJobs[url].delete(params.signal);
|
|
1751
|
+
|
|
1752
|
+
if (this.fetchJobs[url].size === 0) {
|
|
1753
|
+
delete this.fetchJobs[url];
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1757
|
+
this.fetchJobs[url].set(params.signal, job);
|
|
1758
|
+
}
|
|
1693
1759
|
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
// Content Type. If not, this will throw, signaling an invalid response.
|
|
1699
|
-
json = await res.json();
|
|
1700
|
-
} catch {
|
|
1701
|
-
// Not Found (this response has an empty body and throws on `.json()`)
|
|
1702
|
-
// - Incorrect repository name
|
|
1703
|
-
if (res.status === 404) {
|
|
1704
|
-
throw new NotFoundError(
|
|
1705
|
-
`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`,
|
|
1706
|
-
url,
|
|
1707
|
-
undefined,
|
|
1708
|
-
);
|
|
1709
|
-
} else {
|
|
1710
|
-
throw new PrismicError(undefined, url, undefined);
|
|
1711
|
-
}
|
|
1760
|
+
const res = await job;
|
|
1761
|
+
|
|
1762
|
+
if (res.status !== 404 && res.json == null) {
|
|
1763
|
+
throw new PrismicError(undefined, url, res.json);
|
|
1712
1764
|
}
|
|
1713
1765
|
|
|
1714
1766
|
switch (res.status) {
|
|
1715
1767
|
// Successful
|
|
1716
1768
|
case 200: {
|
|
1717
|
-
return json;
|
|
1769
|
+
return res.json;
|
|
1718
1770
|
}
|
|
1719
1771
|
|
|
1720
1772
|
// Bad Request
|
|
1721
|
-
// - Invalid
|
|
1773
|
+
// - Invalid filter syntax
|
|
1722
1774
|
// - Ref not provided (ignored)
|
|
1723
1775
|
case 400: {
|
|
1724
|
-
throw new ParsingError(json.message, url, json);
|
|
1776
|
+
throw new ParsingError(res.json.message, url, res.json);
|
|
1725
1777
|
}
|
|
1726
1778
|
|
|
1727
1779
|
// Unauthorized
|
|
@@ -1733,13 +1785,23 @@ export class Client<
|
|
|
1733
1785
|
// - Incorrect access token for query endpoint
|
|
1734
1786
|
case 403: {
|
|
1735
1787
|
throw new ForbiddenError(
|
|
1736
|
-
"error" in json ? json.error : json.message,
|
|
1788
|
+
"error" in res.json ? res.json.error : res.json.message,
|
|
1789
|
+
url,
|
|
1790
|
+
res.json,
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
// Not Found (this response has an empty body)
|
|
1795
|
+
// - Incorrect repository name
|
|
1796
|
+
case 404: {
|
|
1797
|
+
throw new NotFoundError(
|
|
1798
|
+
`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`,
|
|
1737
1799
|
url,
|
|
1738
|
-
|
|
1800
|
+
undefined,
|
|
1739
1801
|
);
|
|
1740
1802
|
}
|
|
1741
1803
|
}
|
|
1742
1804
|
|
|
1743
|
-
throw new PrismicError(undefined, url, json);
|
|
1805
|
+
throw new PrismicError(undefined, url, res.json);
|
|
1744
1806
|
}
|
|
1745
1807
|
}
|