@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
package/dist/predicate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"predicate.js","sources":["../../src/predicate.ts"],"sourcesContent":["/**\n * Formats the value of a predicate element to a stringified version accepted by\n * the Prismic REST API.\n *\n * @param value - Value to format.\n *\n * @returns `value` formatted for the Prismic REST API.\n */\nconst formatValue = (\n\tvalue:\n\t\t| string\n\t\t| number\n\t\t| Date\n\t\t| unknown\n\t\t| (string | number | Date | unknown)[],\n): string => {\n\tif (Array.isArray(value)) {\n\t\treturn `[${value.map(formatValue).join(\", \")}]`;\n\t}\n\n\tif (typeof value === \"string\") {\n\t\treturn `\"${value}\"`;\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn `${value.getTime()}`;\n\t}\n\n\treturn `${value}`;\n};\n\n/**\n * Creates a predicate builder function for predicates with a path and\n * arguments.\n *\n * @typeParam Args - Arguments for the predicate.\n * @param name - Name of the predicate used in the resulting string.\n *\n * @returns Predicate builder function for the given name.\n */\nconst pathWithArgsPredicate = <Args extends unknown[]>(name: string) => {\n\t/**\n\t * @param path - Path to the value to be compared.\n\t */\n\tconst fn = (path: string, ...args: Args): string => {\n\t\tconst formattedArgs = args.map(formatValue).join(\", \");\n\t\tconst joiner = path && args.length ? \", \" : \"\";\n\n\t\treturn `[${name}(${path}${joiner}${formattedArgs})]`;\n\t};\n\n\treturn fn;\n};\n\n/**\n * Creates a predicate builder function for predicates with only a path.\n *\n * @param name - Name of the predicate used in the resulting string.\n *\n * @returns Predicate builder function for the given name.\n */\nconst pathPredicate = (name: string) => {\n\tconst predicateFn = pathWithArgsPredicate(name);\n\n\t/**\n\t * @param path - Path for the predicate.\n\t */\n\tconst fn = (path: string): string => {\n\t\treturn predicateFn(path);\n\t};\n\n\treturn fn;\n};\n\n/**\n * Creates a predicate builder function for predicates with only arguments and\n * no path.\n *\n * @param name - Name of the predicate used in the resulting string.\n *\n * @returns Predicate builder function for the given name.\n */\nconst argsPredicate = <Args extends unknown[]>(name: string) => {\n\tconst predicateFn = pathWithArgsPredicate<Args>(name);\n\n\t/**\n\t * @param args - Arguments for the predicate.\n\t */\n\tconst fn = (...args: Args): string => {\n\t\treturn predicateFn(\"\", ...args);\n\t};\n\n\treturn fn;\n};\n\nexport const predicate = {\n\t/**\n\t * The `at` predicate checks that the path matches the described value\n\t * exactly. It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#at}\n\t */\n\tat: pathWithArgsPredicate<\n\t\t[value: string | number | boolean | Date | string[]]\n\t>(\"at\"),\n\n\t/**\n\t * The `not` predicate checks that the path doesn't match the provided value\n\t * exactly. It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#not}\n\t */\n\tnot: pathWithArgsPredicate<\n\t\t[value: string | number | boolean | Date | string[]]\n\t>(\"not\"),\n\n\t/**\n\t * The `any` predicate takes an array of values. It works exactly the same way\n\t * as the `at` operator, but checks whether the fragment matches any of the\n\t * values in the array.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#any}\n\t */\n\tany: pathWithArgsPredicate<[values: (string | number | boolean | Date)[]]>(\n\t\t\"any\",\n\t),\n\n\t/**\n\t * The `in` predicate is used specifically to retrieve an array of documents\n\t * by their IDs or UIDs. This predicate is much more efficient at this than\n\t * the any predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#in}\n\t */\n\tin: pathWithArgsPredicate<[values: string[]]>(\"in\"),\n\n\t/**\n\t * The `fulltext` predicate provides two capabilities:\n\t *\n\t * 1. Checking if a certain string is anywhere inside a document (this is what\n\t * you should use to make your project's search engine feature)\n\t * 2. Checking if the string is contained inside a specific custom type’s Rich\n\t * Text or Key Text fragment.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#fulltext}\n\t */\n\tfulltext: pathWithArgsPredicate<[searchTerms: string]>(\"fulltext\"),\n\n\t/**\n\t * The `has` predicate checks whether a fragment has a value. It will return\n\t * all the documents of the specified type that contain a value for the\n\t * specified field.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#has}\n\t */\n\thas: pathPredicate(\"has\"),\n\n\t/**\n\t * The `missing` predicate checks if a fragment doesn't have a value. It will\n\t * return all the documents of the specified type that do not contain a value\n\t * for the specified field.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#missing}\n\t */\n\tmissing: pathPredicate(\"missing\"),\n\n\t/**\n\t * The `similar` predicate takes the ID of a document, and returns a list of\n\t * documents with similar content. This allows you to build an automated\n\t * content discovery feature (for example, a \"Related posts\" section).\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#similar}\n\t */\n\tsimilar: argsPredicate<[id: string, value: number]>(\"similar\"),\n\n\t/**\n\t * The `geopoint.near` predicate checks that the value in the path is within\n\t * the radius of the given coordinates.\n\t *\n\t * This predicate will only work for a GeoPoint field.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#near}\n\t */\n\tgeopointNear:\n\t\tpathWithArgsPredicate<\n\t\t\t[latitude: number, longitude: number, radius: number]\n\t\t>(\"geopoint.near\"),\n\n\t/**\n\t * The `number.lt` predicate checks that the value in the number field is less\n\t * than the value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#lt-less-than}\n\t */\n\tnumberLessThan: pathWithArgsPredicate<[value: number]>(\"number.lt\"),\n\n\t/**\n\t * The `number.gt` predicate checks that the value in the number field is\n\t * greater than the value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#gt-greater-than}\n\t */\n\tnumberGreaterThan: pathWithArgsPredicate<[value: number]>(\"number.gt\"),\n\n\t/**\n\t * The `number.inRange` predicate checks that the value in the path is within\n\t * the two values passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#inrange}\n\t */\n\tnumberInRange:\n\t\tpathWithArgsPredicate<[lowerLimit: number, upperLimit: number]>(\n\t\t\t\"number.inRange\",\n\t\t),\n\n\t/**\n\t * The `date.after` predicate checks that the value in the path is after the\n\t * date value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#after}\n\t */\n\tdateAfter:\n\t\tpathWithArgsPredicate<[date: string | number | Date]>(\"date.after\"),\n\n\t/**\n\t * The `date.before` predicate checks that the value in the path is before the\n\t * date value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#before}\n\t */\n\tdateBefore:\n\t\tpathWithArgsPredicate<[date: string | number | Date]>(\"date.before\"),\n\n\t/**\n\t * The `date.between` predicate checks that the value in the path is within\n\t * the date values passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#between}\n\t */\n\tdateBetween:\n\t\tpathWithArgsPredicate<\n\t\t\t[startDate: string | number | Date, endDate: string | number | Date]\n\t\t>(\"date.between\"),\n\n\t/**\n\t * The `date.day-of-month` predicate checks that the value in the path is\n\t * equal to the day of the month passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonth}\n\t */\n\tdateDayOfMonth: pathWithArgsPredicate<[day: number]>(\"date.day-of-month\"),\n\n\t/**\n\t * The `date.day-of-month-after` predicate checks that the value in the path\n\t * is after the day of the month passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonthafter}\n\t */\n\tdateDayOfMonthAfter: pathWithArgsPredicate<[day: number]>(\n\t\t\"date.day-of-month-after\",\n\t),\n\n\t/**\n\t * The `date.day-of-month-before` predicate checks that the value in the path\n\t * is before the day of the month passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonthbefore}\n\t */\n\tdateDayOfMonthBefore: pathWithArgsPredicate<[day: number]>(\n\t\t\"date.day-of-month-before\",\n\t),\n\n\t/**\n\t * The `date.day-of-week` predicate checks that the value in the path is equal\n\t * to the day of the week passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweek}\n\t */\n\tdateDayOfWeek:\n\t\tpathWithArgsPredicate<[day: string | number]>(\"date.day-of-week\"),\n\n\t/**\n\t * The `date.day-of-week-after` predicate checks that the value in the path is\n\t * after the day of the week passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweekafter}\n\t */\n\tdateDayOfWeekAfter: pathWithArgsPredicate<[day: string | number]>(\n\t\t\"date.day-of-week-after\",\n\t),\n\n\t/**\n\t * The date.day-of-week-before predicate checks that the value in the path is\n\t * before the day of the week passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweekbefore}\n\t */\n\tdateDayOfWeekBefore: pathWithArgsPredicate<[day: string | number]>(\n\t\t\"date.day-of-week-before\",\n\t),\n\n\t/**\n\t * The `date.month` predicate checks that the value in the path occurs in the\n\t * month value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#month}\n\t */\n\tdateMonth: pathWithArgsPredicate<[month: string | number]>(\"date.month\"),\n\n\t/**\n\t * The `date.month-after` predicate checks that the value in the path occurs\n\t * in any month after the value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#monthafter}\n\t */\n\tdateMonthAfter:\n\t\tpathWithArgsPredicate<[month: string | number]>(\"date.month-after\"),\n\n\t/**\n\t * The `date.month-before` predicate checks that the value in the path occurs\n\t * in any month before the value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#monthbefore}\n\t */\n\tdateMonthBefore:\n\t\tpathWithArgsPredicate<[month: string | number]>(\"date.month-before\"),\n\n\t/**\n\t * The `date.year` predicate checks that the value in the path occurs in the\n\t * year value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#year}\n\t */\n\tdateYear: pathWithArgsPredicate<[year: number]>(\"date.year\"),\n\n\t/**\n\t * The `date.hour` predicate checks that the value in the path occurs within\n\t * the hour value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hour}\n\t */\n\tdateHour: pathWithArgsPredicate<[hour: number]>(\"date.hour\"),\n\n\t/**\n\t * The `date.hour-after` predicate checks that the value in the path occurs\n\t * after the hour value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hourafter}\n\t */\n\tdateHourAfter: pathWithArgsPredicate<[hour: number]>(\"date.hour-after\"),\n\n\t/**\n\t * The `date.hour-before` predicate checks that the value in the path occurs\n\t * before the hour value passed into the predicate.\n\t *\n\t * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hourbefore}\n\t */\n\tdateHourBefore: pathWithArgsPredicate<[hour: number]>(\"date.hour-before\"),\n};\n"],"names":[],"mappings":"AAQA,MAAM,cAAc,CACnB,UAMW;AACP,MAAA,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,IAAI,MAAM,IAAI,WAAW,EAAE,KAAK,IAAI;AAAA,EAC3C;AAEG,MAAA,OAAO,UAAU,UAAU;AAC9B,WAAO,IAAI;AAAA,EACX;AAED,MAAI,iBAAiB,MAAM;AACnB,WAAA,GAAG,MAAM,QAAO;AAAA,EACvB;AAED,SAAO,GAAG;AACX;AAWA,MAAM,wBAAwB,CAAyB,SAAgB;AAIhE,QAAA,KAAK,CAAC,SAAiB,SAAsB;AAClD,UAAM,gBAAgB,KAAK,IAAI,WAAW,EAAE,KAAK,IAAI;AACrD,UAAM,SAAS,QAAQ,KAAK,SAAS,OAAO;AAErC,WAAA,IAAI,QAAQ,OAAO,SAAS;AAAA,EAAA;AAG7B,SAAA;AACR;AASA,MAAM,gBAAgB,CAAC,SAAgB;AAChC,QAAA,cAAc,sBAAsB,IAAI;AAKxC,QAAA,KAAK,CAAC,SAAwB;AACnC,WAAO,YAAY,IAAI;AAAA,EAAA;AAGjB,SAAA;AACR;AAUA,MAAM,gBAAgB,CAAyB,SAAgB;AACxD,QAAA,cAAc,sBAA4B,IAAI;AAK9C,QAAA,KAAK,IAAI,SAAsB;AAC7B,WAAA,YAAY,IAAI,GAAG,IAAI;AAAA,EAAA;AAGxB,SAAA;AACR;AAEO,MAAM,YAAY;AAAA,EAOxB,IAAI,sBAEF,IAAI;AAAA,EAQN,KAAK,sBAEH,KAAK;AAAA,EASP,KAAK,sBACJ,KAAK;AAAA,EAUN,IAAI,sBAA0C,IAAI;AAAA,EAYlD,UAAU,sBAA6C,UAAU;AAAA,EASjE,KAAK,cAAc,KAAK;AAAA,EASxB,SAAS,cAAc,SAAS;AAAA,EAShC,SAAS,cAA2C,SAAS;AAAA,EAU7D,cACC,sBAEE,eAAe;AAAA,EAQlB,gBAAgB,sBAAuC,WAAW;AAAA,EAQlE,mBAAmB,sBAAuC,WAAW;AAAA,EAQrE,eACC,sBACC,gBAAgB;AAAA,EASlB,WACC,sBAAsD,YAAY;AAAA,EAQnE,YACC,sBAAsD,aAAa;AAAA,EAQpE,aACC,sBAEE,cAAc;AAAA,EAQjB,gBAAgB,sBAAqC,mBAAmB;AAAA,EAQxE,qBAAqB,sBACpB,yBAAyB;AAAA,EAS1B,sBAAsB,sBACrB,0BAA0B;AAAA,EAS3B,eACC,sBAA8C,kBAAkB;AAAA,EAQjE,oBAAoB,sBACnB,wBAAwB;AAAA,EASzB,qBAAqB,sBACpB,yBAAyB;AAAA,EAS1B,WAAW,sBAAgD,YAAY;AAAA,EAQvE,gBACC,sBAAgD,kBAAkB;AAAA,EAQnE,iBACC,sBAAgD,mBAAmB;AAAA,EAQpE,UAAU,sBAAsC,WAAW;AAAA,EAQ3D,UAAU,sBAAsC,WAAW;AAAA,EAQ3D,eAAe,sBAAsC,iBAAiB;AAAA,EAQtE,gBAAgB,sBAAsC,kBAAkB;;"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import * as prismicT from "@prismicio/types";
|
|
2
|
-
/**
|
|
3
|
-
* Create a union of the given object's values, and optionally specify which
|
|
4
|
-
* keys to get the values from.
|
|
5
|
-
*
|
|
6
|
-
* Taken from the `type-fest` package.
|
|
7
|
-
*
|
|
8
|
-
* See:
|
|
9
|
-
* https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/value-of.d.ts
|
|
10
|
-
*/
|
|
11
|
-
export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
12
|
-
/**
|
|
13
|
-
* Functions like TypeScript's native `Extract` utility type with added support
|
|
14
|
-
* to fall back to a value if the resulting union is `never`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* ExtractOrFallback<"a" | "b", "a">; // => "a"
|
|
20
|
-
* ExtractOrFallback<"a" | "b", "c">; // => "a" | "b"
|
|
21
|
-
* ExtractOrFallback<"a" | "b", "c", "foo">; // => "foo"
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @typeParam T - The union from which values will be extracted.
|
|
25
|
-
* @typeParam U - The extraction condition.
|
|
26
|
-
* @typeParam Fallback - The value to return if the resulting union is `never`.
|
|
27
|
-
* Defaults to `T`.
|
|
28
|
-
*/
|
|
29
|
-
type ExtractOrFallback<T, U, Fallback = T> = Extract<T, U> extends never ? Fallback : Extract<T, U>;
|
|
30
|
-
/**
|
|
31
|
-
* Extracts one or more Prismic document types that match a given Prismic
|
|
32
|
-
* document type. If no matches are found, no extraction is performed and the
|
|
33
|
-
* union of all provided Prismic document types are returned.
|
|
34
|
-
*
|
|
35
|
-
* @typeParam TDocuments - Prismic document types from which to extract.
|
|
36
|
-
* @typeParam TDocumentType - Type(s) to match `TDocuments` against.
|
|
37
|
-
*/
|
|
38
|
-
export type ExtractDocumentType<TDocuments extends prismicT.PrismicDocument, TDocumentType extends TDocuments["type"]> = ExtractOrFallback<TDocuments, {
|
|
39
|
-
type: TDocumentType;
|
|
40
|
-
}>;
|
|
41
|
-
/**
|
|
42
|
-
* A universal API to make network requests. A subset of the `fetch()` API.
|
|
43
|
-
*
|
|
44
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
|
|
45
|
-
*/
|
|
46
|
-
export type FetchLike = (input: string, init?: RequestInitLike) => Promise<ResponseLike>;
|
|
47
|
-
/**
|
|
48
|
-
* An object that allows you to abort a `fetch()` request if needed via an
|
|
49
|
-
* `AbortController` object
|
|
50
|
-
*
|
|
51
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
52
|
-
*/
|
|
53
|
-
export type AbortSignalLike = any;
|
|
54
|
-
/**
|
|
55
|
-
* The minimum required properties from RequestInit.
|
|
56
|
-
*/
|
|
57
|
-
export interface RequestInitLike {
|
|
58
|
-
headers?: Record<string, string>;
|
|
59
|
-
/**
|
|
60
|
-
* An object that allows you to abort a `fetch()` request if needed via an
|
|
61
|
-
* `AbortController` object
|
|
62
|
-
*
|
|
63
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
64
|
-
*/
|
|
65
|
-
signal?: AbortSignalLike;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* The minimum required properties from Response.
|
|
69
|
-
*/
|
|
70
|
-
export interface ResponseLike {
|
|
71
|
-
status: number;
|
|
72
|
-
json(): Promise<any>;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* The minimum required properties to treat as an HTTP Request for automatic
|
|
76
|
-
* Prismic preview support.
|
|
77
|
-
*/
|
|
78
|
-
export type HttpRequestLike = /**
|
|
79
|
-
* Web API Request
|
|
80
|
-
*
|
|
81
|
-
* @see http://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
82
|
-
*/ {
|
|
83
|
-
headers?: {
|
|
84
|
-
get(name: string): string | null;
|
|
85
|
-
};
|
|
86
|
-
url?: string;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Express-style Request
|
|
90
|
-
*/
|
|
91
|
-
| {
|
|
92
|
-
headers?: {
|
|
93
|
-
cookie?: string;
|
|
94
|
-
};
|
|
95
|
-
query?: Record<string, unknown>;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* An `orderings` parameter that orders the results by the specified field.
|
|
99
|
-
*
|
|
100
|
-
* {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#orderings}
|
|
101
|
-
*/
|
|
102
|
-
export interface Ordering {
|
|
103
|
-
field: string;
|
|
104
|
-
direction?: "asc" | "desc";
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* A `routes` parameter that determines how a document's URL field is resolved.
|
|
108
|
-
*
|
|
109
|
-
* @example With a document's UID field.
|
|
110
|
-
*
|
|
111
|
-
* ```ts
|
|
112
|
-
* {
|
|
113
|
-
* "type": "page",
|
|
114
|
-
* "path": "/:uid"
|
|
115
|
-
* }
|
|
116
|
-
* ```
|
|
117
|
-
*
|
|
118
|
-
* @example With a Content Relationship `parent` field.
|
|
119
|
-
*
|
|
120
|
-
* ```ts
|
|
121
|
-
* {
|
|
122
|
-
* "type": "page",
|
|
123
|
-
* "path": "/:parent?/:uid",
|
|
124
|
-
* "resolvers": {
|
|
125
|
-
* "parent": "parent"
|
|
126
|
-
* }
|
|
127
|
-
* }
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
* {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
131
|
-
*/
|
|
132
|
-
export interface Route {
|
|
133
|
-
/**
|
|
134
|
-
* The Custom Type of the document.
|
|
135
|
-
*/
|
|
136
|
-
type: string;
|
|
137
|
-
/**
|
|
138
|
-
* A specific UID to which this route definition is scoped. The route is only
|
|
139
|
-
* defined for the document whose UID matches the given UID.
|
|
140
|
-
*/
|
|
141
|
-
uid?: string;
|
|
142
|
-
/**
|
|
143
|
-
* A specific language to which this route definition is scoped. The route is
|
|
144
|
-
* only defined for documents whose language matches the given language.
|
|
145
|
-
*/
|
|
146
|
-
lang?: string;
|
|
147
|
-
/**
|
|
148
|
-
* The resolved path of the document with optional placeholders.
|
|
149
|
-
*/
|
|
150
|
-
path: string;
|
|
151
|
-
/**
|
|
152
|
-
* An object that lists the API IDs of the Content Relationships in the route.
|
|
153
|
-
*/
|
|
154
|
-
resolvers?: Record<string, string>;
|
|
155
|
-
}
|
|
156
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { castArray } from "./castArray";
|
|
2
|
-
|
|
3
|
-
interface WithPredicates {
|
|
4
|
-
predicates?: string | string[];
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Adds one or more predicates to an object with a `predicates` property.
|
|
9
|
-
* Appended predicates are added to the end of the existing list.
|
|
10
|
-
*
|
|
11
|
-
* @typeParam T - Object to which predicates will be append.
|
|
12
|
-
* @param objWithPredicates - Object to append predicates on the `predicates`
|
|
13
|
-
* property.
|
|
14
|
-
* @param predicates - One or more predicates to append.
|
|
15
|
-
*
|
|
16
|
-
* @returns The object with the appended predicates.
|
|
17
|
-
*/
|
|
18
|
-
export const appendPredicates = <T extends WithPredicates>(
|
|
19
|
-
objWithPredicates: T = {} as T,
|
|
20
|
-
predicates: string | string[],
|
|
21
|
-
) => {
|
|
22
|
-
return {
|
|
23
|
-
...objWithPredicates,
|
|
24
|
-
predicates: [
|
|
25
|
-
...(objWithPredicates.predicates || []),
|
|
26
|
-
...castArray(predicates),
|
|
27
|
-
],
|
|
28
|
-
};
|
|
29
|
-
};
|
package/src/lib/orElseThrow.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throws an error if a given value is nullish.
|
|
3
|
-
*
|
|
4
|
-
* @typeParam Nullable - Value to check.
|
|
5
|
-
* @param a -Nullable value to check.
|
|
6
|
-
* @param error - Error to throw if `a` is nullish.
|
|
7
|
-
*
|
|
8
|
-
* @returns `a`, whose type is narrowed to be non-nullable.
|
|
9
|
-
* @throws Throws the given error if `a` is nullish.
|
|
10
|
-
*/
|
|
11
|
-
export const orElseThrow = <T>(a: T | null | undefined, error: Error): T => {
|
|
12
|
-
if (a == null) {
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return a;
|
|
17
|
-
};
|
package/src/predicate.ts
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formats the value of a predicate element to a stringified version accepted by
|
|
3
|
-
* the Prismic REST API.
|
|
4
|
-
*
|
|
5
|
-
* @param value - Value to format.
|
|
6
|
-
*
|
|
7
|
-
* @returns `value` formatted for the Prismic REST API.
|
|
8
|
-
*/
|
|
9
|
-
const formatValue = (
|
|
10
|
-
value:
|
|
11
|
-
| string
|
|
12
|
-
| number
|
|
13
|
-
| Date
|
|
14
|
-
| unknown
|
|
15
|
-
| (string | number | Date | unknown)[],
|
|
16
|
-
): string => {
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
return `[${value.map(formatValue).join(", ")}]`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (typeof value === "string") {
|
|
22
|
-
return `"${value}"`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (value instanceof Date) {
|
|
26
|
-
return `${value.getTime()}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return `${value}`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a predicate builder function for predicates with a path and
|
|
34
|
-
* arguments.
|
|
35
|
-
*
|
|
36
|
-
* @typeParam Args - Arguments for the predicate.
|
|
37
|
-
* @param name - Name of the predicate used in the resulting string.
|
|
38
|
-
*
|
|
39
|
-
* @returns Predicate builder function for the given name.
|
|
40
|
-
*/
|
|
41
|
-
const pathWithArgsPredicate = <Args extends unknown[]>(name: string) => {
|
|
42
|
-
/**
|
|
43
|
-
* @param path - Path to the value to be compared.
|
|
44
|
-
*/
|
|
45
|
-
const fn = (path: string, ...args: Args): string => {
|
|
46
|
-
const formattedArgs = args.map(formatValue).join(", ");
|
|
47
|
-
const joiner = path && args.length ? ", " : "";
|
|
48
|
-
|
|
49
|
-
return `[${name}(${path}${joiner}${formattedArgs})]`;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return fn;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Creates a predicate builder function for predicates with only a path.
|
|
57
|
-
*
|
|
58
|
-
* @param name - Name of the predicate used in the resulting string.
|
|
59
|
-
*
|
|
60
|
-
* @returns Predicate builder function for the given name.
|
|
61
|
-
*/
|
|
62
|
-
const pathPredicate = (name: string) => {
|
|
63
|
-
const predicateFn = pathWithArgsPredicate(name);
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param path - Path for the predicate.
|
|
67
|
-
*/
|
|
68
|
-
const fn = (path: string): string => {
|
|
69
|
-
return predicateFn(path);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return fn;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Creates a predicate builder function for predicates with only arguments and
|
|
77
|
-
* no path.
|
|
78
|
-
*
|
|
79
|
-
* @param name - Name of the predicate used in the resulting string.
|
|
80
|
-
*
|
|
81
|
-
* @returns Predicate builder function for the given name.
|
|
82
|
-
*/
|
|
83
|
-
const argsPredicate = <Args extends unknown[]>(name: string) => {
|
|
84
|
-
const predicateFn = pathWithArgsPredicate<Args>(name);
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @param args - Arguments for the predicate.
|
|
88
|
-
*/
|
|
89
|
-
const fn = (...args: Args): string => {
|
|
90
|
-
return predicateFn("", ...args);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return fn;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const predicate = {
|
|
97
|
-
/**
|
|
98
|
-
* The `at` predicate checks that the path matches the described value
|
|
99
|
-
* exactly. It takes a single value for a field or an array (only for tags).
|
|
100
|
-
*
|
|
101
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#at}
|
|
102
|
-
*/
|
|
103
|
-
at: pathWithArgsPredicate<
|
|
104
|
-
[value: string | number | boolean | Date | string[]]
|
|
105
|
-
>("at"),
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* The `not` predicate checks that the path doesn't match the provided value
|
|
109
|
-
* exactly. It takes a single value for a field or an array (only for tags).
|
|
110
|
-
*
|
|
111
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#not}
|
|
112
|
-
*/
|
|
113
|
-
not: pathWithArgsPredicate<
|
|
114
|
-
[value: string | number | boolean | Date | string[]]
|
|
115
|
-
>("not"),
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The `any` predicate takes an array of values. It works exactly the same way
|
|
119
|
-
* as the `at` operator, but checks whether the fragment matches any of the
|
|
120
|
-
* values in the array.
|
|
121
|
-
*
|
|
122
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#any}
|
|
123
|
-
*/
|
|
124
|
-
any: pathWithArgsPredicate<[values: (string | number | boolean | Date)[]]>(
|
|
125
|
-
"any",
|
|
126
|
-
),
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The `in` predicate is used specifically to retrieve an array of documents
|
|
130
|
-
* by their IDs or UIDs. This predicate is much more efficient at this than
|
|
131
|
-
* the any predicate.
|
|
132
|
-
*
|
|
133
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#in}
|
|
134
|
-
*/
|
|
135
|
-
in: pathWithArgsPredicate<[values: string[]]>("in"),
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* The `fulltext` predicate provides two capabilities:
|
|
139
|
-
*
|
|
140
|
-
* 1. Checking if a certain string is anywhere inside a document (this is what
|
|
141
|
-
* you should use to make your project's search engine feature)
|
|
142
|
-
* 2. Checking if the string is contained inside a specific custom type’s Rich
|
|
143
|
-
* Text or Key Text fragment.
|
|
144
|
-
*
|
|
145
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#fulltext}
|
|
146
|
-
*/
|
|
147
|
-
fulltext: pathWithArgsPredicate<[searchTerms: string]>("fulltext"),
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* The `has` predicate checks whether a fragment has a value. It will return
|
|
151
|
-
* all the documents of the specified type that contain a value for the
|
|
152
|
-
* specified field.
|
|
153
|
-
*
|
|
154
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#has}
|
|
155
|
-
*/
|
|
156
|
-
has: pathPredicate("has"),
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* The `missing` predicate checks if a fragment doesn't have a value. It will
|
|
160
|
-
* return all the documents of the specified type that do not contain a value
|
|
161
|
-
* for the specified field.
|
|
162
|
-
*
|
|
163
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#missing}
|
|
164
|
-
*/
|
|
165
|
-
missing: pathPredicate("missing"),
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The `similar` predicate takes the ID of a document, and returns a list of
|
|
169
|
-
* documents with similar content. This allows you to build an automated
|
|
170
|
-
* content discovery feature (for example, a "Related posts" section).
|
|
171
|
-
*
|
|
172
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#similar}
|
|
173
|
-
*/
|
|
174
|
-
similar: argsPredicate<[id: string, value: number]>("similar"),
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* The `geopoint.near` predicate checks that the value in the path is within
|
|
178
|
-
* the radius of the given coordinates.
|
|
179
|
-
*
|
|
180
|
-
* This predicate will only work for a GeoPoint field.
|
|
181
|
-
*
|
|
182
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#near}
|
|
183
|
-
*/
|
|
184
|
-
geopointNear:
|
|
185
|
-
pathWithArgsPredicate<
|
|
186
|
-
[latitude: number, longitude: number, radius: number]
|
|
187
|
-
>("geopoint.near"),
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* The `number.lt` predicate checks that the value in the number field is less
|
|
191
|
-
* than the value passed into the predicate.
|
|
192
|
-
*
|
|
193
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#lt-less-than}
|
|
194
|
-
*/
|
|
195
|
-
numberLessThan: pathWithArgsPredicate<[value: number]>("number.lt"),
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* The `number.gt` predicate checks that the value in the number field is
|
|
199
|
-
* greater than the value passed into the predicate.
|
|
200
|
-
*
|
|
201
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#gt-greater-than}
|
|
202
|
-
*/
|
|
203
|
-
numberGreaterThan: pathWithArgsPredicate<[value: number]>("number.gt"),
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* The `number.inRange` predicate checks that the value in the path is within
|
|
207
|
-
* the two values passed into the predicate.
|
|
208
|
-
*
|
|
209
|
-
* {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#inrange}
|
|
210
|
-
*/
|
|
211
|
-
numberInRange:
|
|
212
|
-
pathWithArgsPredicate<[lowerLimit: number, upperLimit: number]>(
|
|
213
|
-
"number.inRange",
|
|
214
|
-
),
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* The `date.after` predicate checks that the value in the path is after the
|
|
218
|
-
* date value passed into the predicate.
|
|
219
|
-
*
|
|
220
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#after}
|
|
221
|
-
*/
|
|
222
|
-
dateAfter:
|
|
223
|
-
pathWithArgsPredicate<[date: string | number | Date]>("date.after"),
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* The `date.before` predicate checks that the value in the path is before the
|
|
227
|
-
* date value passed into the predicate.
|
|
228
|
-
*
|
|
229
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#before}
|
|
230
|
-
*/
|
|
231
|
-
dateBefore:
|
|
232
|
-
pathWithArgsPredicate<[date: string | number | Date]>("date.before"),
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* The `date.between` predicate checks that the value in the path is within
|
|
236
|
-
* the date values passed into the predicate.
|
|
237
|
-
*
|
|
238
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#between}
|
|
239
|
-
*/
|
|
240
|
-
dateBetween:
|
|
241
|
-
pathWithArgsPredicate<
|
|
242
|
-
[startDate: string | number | Date, endDate: string | number | Date]
|
|
243
|
-
>("date.between"),
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* The `date.day-of-month` predicate checks that the value in the path is
|
|
247
|
-
* equal to the day of the month passed into the predicate.
|
|
248
|
-
*
|
|
249
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonth}
|
|
250
|
-
*/
|
|
251
|
-
dateDayOfMonth: pathWithArgsPredicate<[day: number]>("date.day-of-month"),
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* The `date.day-of-month-after` predicate checks that the value in the path
|
|
255
|
-
* is after the day of the month passed into the predicate.
|
|
256
|
-
*
|
|
257
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonthafter}
|
|
258
|
-
*/
|
|
259
|
-
dateDayOfMonthAfter: pathWithArgsPredicate<[day: number]>(
|
|
260
|
-
"date.day-of-month-after",
|
|
261
|
-
),
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* The `date.day-of-month-before` predicate checks that the value in the path
|
|
265
|
-
* is before the day of the month passed into the predicate.
|
|
266
|
-
*
|
|
267
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonthbefore}
|
|
268
|
-
*/
|
|
269
|
-
dateDayOfMonthBefore: pathWithArgsPredicate<[day: number]>(
|
|
270
|
-
"date.day-of-month-before",
|
|
271
|
-
),
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* The `date.day-of-week` predicate checks that the value in the path is equal
|
|
275
|
-
* to the day of the week passed into the predicate.
|
|
276
|
-
*
|
|
277
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweek}
|
|
278
|
-
*/
|
|
279
|
-
dateDayOfWeek:
|
|
280
|
-
pathWithArgsPredicate<[day: string | number]>("date.day-of-week"),
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* The `date.day-of-week-after` predicate checks that the value in the path is
|
|
284
|
-
* after the day of the week passed into the predicate.
|
|
285
|
-
*
|
|
286
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweekafter}
|
|
287
|
-
*/
|
|
288
|
-
dateDayOfWeekAfter: pathWithArgsPredicate<[day: string | number]>(
|
|
289
|
-
"date.day-of-week-after",
|
|
290
|
-
),
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* The date.day-of-week-before predicate checks that the value in the path is
|
|
294
|
-
* before the day of the week passed into the predicate.
|
|
295
|
-
*
|
|
296
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweekbefore}
|
|
297
|
-
*/
|
|
298
|
-
dateDayOfWeekBefore: pathWithArgsPredicate<[day: string | number]>(
|
|
299
|
-
"date.day-of-week-before",
|
|
300
|
-
),
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* The `date.month` predicate checks that the value in the path occurs in the
|
|
304
|
-
* month value passed into the predicate.
|
|
305
|
-
*
|
|
306
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#month}
|
|
307
|
-
*/
|
|
308
|
-
dateMonth: pathWithArgsPredicate<[month: string | number]>("date.month"),
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* The `date.month-after` predicate checks that the value in the path occurs
|
|
312
|
-
* in any month after the value passed into the predicate.
|
|
313
|
-
*
|
|
314
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#monthafter}
|
|
315
|
-
*/
|
|
316
|
-
dateMonthAfter:
|
|
317
|
-
pathWithArgsPredicate<[month: string | number]>("date.month-after"),
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* The `date.month-before` predicate checks that the value in the path occurs
|
|
321
|
-
* in any month before the value passed into the predicate.
|
|
322
|
-
*
|
|
323
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#monthbefore}
|
|
324
|
-
*/
|
|
325
|
-
dateMonthBefore:
|
|
326
|
-
pathWithArgsPredicate<[month: string | number]>("date.month-before"),
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* The `date.year` predicate checks that the value in the path occurs in the
|
|
330
|
-
* year value passed into the predicate.
|
|
331
|
-
*
|
|
332
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#year}
|
|
333
|
-
*/
|
|
334
|
-
dateYear: pathWithArgsPredicate<[year: number]>("date.year"),
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* The `date.hour` predicate checks that the value in the path occurs within
|
|
338
|
-
* the hour value passed into the predicate.
|
|
339
|
-
*
|
|
340
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hour}
|
|
341
|
-
*/
|
|
342
|
-
dateHour: pathWithArgsPredicate<[hour: number]>("date.hour"),
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* The `date.hour-after` predicate checks that the value in the path occurs
|
|
346
|
-
* after the hour value passed into the predicate.
|
|
347
|
-
*
|
|
348
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hourafter}
|
|
349
|
-
*/
|
|
350
|
-
dateHourAfter: pathWithArgsPredicate<[hour: number]>("date.hour-after"),
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* The `date.hour-before` predicate checks that the value in the path occurs
|
|
354
|
-
* before the hour value passed into the predicate.
|
|
355
|
-
*
|
|
356
|
-
* {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hourbefore}
|
|
357
|
-
*/
|
|
358
|
-
dateHourBefore: pathWithArgsPredicate<[hour: number]>("date.hour-before"),
|
|
359
|
-
};
|