@prismicio/client 6.7.0 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ForbiddenError.cjs +7 -0
- package/dist/ForbiddenError.cjs.map +1 -0
- package/dist/ForbiddenError.d.ts +11 -0
- package/dist/ForbiddenError.js +7 -0
- package/dist/ForbiddenError.js.map +1 -0
- package/dist/NotFoundError.cjs +7 -0
- package/dist/NotFoundError.cjs.map +1 -0
- package/dist/NotFoundError.d.ts +3 -0
- package/dist/NotFoundError.js +7 -0
- package/dist/NotFoundError.js.map +1 -0
- package/dist/ParsingError.cjs +7 -0
- package/dist/ParsingError.cjs.map +1 -0
- package/dist/ParsingError.d.ts +12 -0
- package/dist/ParsingError.js +7 -0
- package/dist/ParsingError.js.map +1 -0
- package/dist/PrismicError.cjs +19 -0
- package/dist/PrismicError.cjs.map +1 -0
- package/dist/PrismicError.d.ts +5 -0
- package/dist/PrismicError.js +19 -0
- package/dist/PrismicError.js.map +1 -0
- package/dist/buildQueryURL.cjs +41 -0
- package/dist/buildQueryURL.cjs.map +1 -0
- package/dist/buildQueryURL.d.ts +130 -0
- package/dist/buildQueryURL.js +41 -0
- package/dist/buildQueryURL.js.map +1 -0
- package/dist/client.cjs +414 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.ts +908 -0
- package/dist/client.js +414 -0
- package/dist/client.js.map +1 -0
- package/dist/cookie.cjs +5 -0
- package/dist/cookie.cjs.map +1 -0
- package/dist/cookie.d.ts +5 -0
- package/dist/cookie.js +5 -0
- package/dist/cookie.js.map +1 -0
- package/dist/getGraphQLEndpoint.cjs +13 -0
- package/dist/getGraphQLEndpoint.cjs.map +1 -0
- package/dist/getGraphQLEndpoint.d.ts +9 -0
- package/dist/getGraphQLEndpoint.js +13 -0
- package/dist/getGraphQLEndpoint.js.map +1 -0
- package/dist/getRepositoryEndpoint.cjs +13 -0
- package/dist/getRepositoryEndpoint.cjs.map +1 -0
- package/dist/getRepositoryEndpoint.d.ts +10 -0
- package/dist/getRepositoryEndpoint.js +13 -0
- package/dist/getRepositoryEndpoint.js.map +1 -0
- package/dist/getRepositoryName.cjs +12 -0
- package/dist/getRepositoryName.cjs.map +1 -0
- package/dist/getRepositoryName.d.ts +13 -0
- package/dist/getRepositoryName.js +12 -0
- package/dist/getRepositoryName.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 +79 -0
- package/dist/helpers/asHTML.cjs.map +1 -0
- package/dist/helpers/asHTML.d.ts +20 -0
- package/dist/helpers/asHTML.js +79 -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 +40 -0
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -0
- package/dist/helpers/asImageWidthSrcSet.d.ts +60 -0
- package/dist/helpers/asImageWidthSrcSet.js +40 -0
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -0
- package/dist/helpers/asLink.cjs +32 -0
- package/dist/helpers/asLink.cjs.map +1 -0
- package/dist/helpers/asLink.d.ts +24 -0
- package/dist/helpers/asLink.js +32 -0
- package/dist/helpers/asLink.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 +19 -0
- package/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/helpers/documentToLinkField.d.ts +15 -0
- package/dist/helpers/documentToLinkField.js +19 -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 +175 -0
- package/dist/helpers/isFilled.js +67 -0
- package/dist/helpers/isFilled.js.map +1 -0
- package/dist/index.cjs +67 -721
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +92 -1526
- package/dist/index.js +64 -681
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs +12 -0
- package/dist/isRepositoryEndpoint.cjs.map +1 -0
- package/dist/isRepositoryEndpoint.d.ts +10 -0
- package/dist/isRepositoryEndpoint.js +12 -0
- package/dist/isRepositoryEndpoint.js.map +1 -0
- package/dist/isRepositoryName.cjs +7 -0
- package/dist/isRepositoryName.cjs.map +1 -0
- package/dist/isRepositoryName.d.ts +9 -0
- package/dist/isRepositoryName.js +7 -0
- package/dist/isRepositoryName.js.map +1 -0
- package/dist/lib/appendPredicates.cjs +14 -0
- package/dist/lib/appendPredicates.cjs.map +1 -0
- package/dist/lib/appendPredicates.d.ts +18 -0
- package/dist/lib/appendPredicates.js +14 -0
- package/dist/lib/appendPredicates.js.map +1 -0
- package/dist/lib/castArray.cjs +5 -0
- package/dist/lib/castArray.cjs.map +1 -0
- package/dist/lib/castArray.d.ts +11 -0
- package/dist/lib/castArray.js +5 -0
- package/dist/lib/castArray.js.map +1 -0
- package/dist/lib/castThunk.cjs +5 -0
- package/dist/lib/castThunk.cjs.map +1 -0
- package/dist/lib/castThunk.d.ts +10 -0
- package/dist/lib/castThunk.js +5 -0
- package/dist/lib/castThunk.js.map +1 -0
- package/dist/lib/findMasterRef.cjs +8 -0
- package/dist/lib/findMasterRef.cjs.map +1 -0
- package/dist/lib/findMasterRef.d.ts +10 -0
- package/dist/lib/findMasterRef.js +8 -0
- package/dist/lib/findMasterRef.js.map +1 -0
- package/dist/lib/findRef.cjs +12 -0
- package/dist/lib/findRef.cjs.map +1 -0
- package/dist/lib/findRef.d.ts +13 -0
- package/dist/lib/findRef.js +12 -0
- package/dist/lib/findRef.js.map +1 -0
- package/dist/lib/findRefByID.cjs +8 -0
- package/dist/lib/findRefByID.cjs.map +1 -0
- package/dist/lib/findRefByID.d.ts +11 -0
- package/dist/lib/findRefByID.js +8 -0
- package/dist/lib/findRefByID.js.map +1 -0
- package/dist/lib/findRefByLabel.cjs +8 -0
- package/dist/lib/findRefByLabel.cjs.map +1 -0
- package/dist/lib/findRefByLabel.d.ts +11 -0
- package/dist/lib/findRefByLabel.js +8 -0
- package/dist/lib/findRefByLabel.js.map +1 -0
- package/dist/lib/getPreviewCookie.cjs +21 -0
- package/dist/lib/getPreviewCookie.cjs.map +1 -0
- package/dist/lib/getPreviewCookie.d.ts +9 -0
- package/dist/lib/getPreviewCookie.js +21 -0
- package/dist/lib/getPreviewCookie.js.map +1 -0
- package/dist/lib/minifyGraphQLQuery.cjs +7 -0
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
- package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
- package/dist/lib/minifyGraphQLQuery.js +7 -0
- package/dist/lib/minifyGraphQLQuery.js.map +1 -0
- package/dist/lib/serializerHelpers.cjs +56 -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/predicate.cjs +68 -0
- package/dist/predicate.cjs.map +1 -0
- package/dist/predicate.d.ts +209 -0
- package/dist/predicate.js +68 -0
- package/dist/predicate.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/client.d.ts +128 -0
- package/dist/types/helpers.d.ts +63 -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 +19 -0
- package/dist/types/model/sharedSliceVariation.d.ts +22 -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 +44 -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 +25 -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 +25 -0
- package/dist/types/model/types.js.map +1 -0
- package/dist/types/model/uid.d.ts +13 -0
- package/dist/types/utils.d.ts +28 -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 +40 -33
- package/src/buildQueryURL.ts +8 -4
- package/src/client.ts +111 -118
- package/src/cookie.ts +2 -1
- package/src/getRepositoryName.ts +4 -2
- package/src/helpers/asDate.ts +48 -0
- package/src/helpers/asHTML.ts +154 -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 +99 -0
- package/src/helpers/asText.ts +29 -0
- package/src/helpers/documentToLinkField.ts +47 -0
- package/src/helpers/isFilled.ts +290 -0
- package/src/index.ts +237 -21
- package/src/isRepositoryEndpoint.ts +2 -1
- package/src/isRepositoryName.ts +2 -1
- package/src/lib/appendPredicates.ts +2 -1
- package/src/lib/findMasterRef.ts +2 -2
- package/src/lib/findRef.ts +2 -5
- package/src/lib/findRefByID.ts +2 -2
- package/src/lib/findRefByLabel.ts +2 -5
- package/src/lib/getPreviewCookie.ts +3 -2
- package/src/lib/serializerHelpers.ts +96 -0
- package/src/predicate.ts +4 -2
- 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.ts → types/client.ts} +16 -52
- package/src/types/helpers.ts +103 -0
- package/src/types/model/boolean.ts +16 -0
- package/src/types/model/color.ts +14 -0
- package/src/types/model/contentRelationship.ts +22 -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 +17 -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 +23 -0
- package/src/types/model/sharedSliceVariation.ts +33 -0
- package/src/types/model/slice.ts +49 -0
- package/src/types/model/sliceZone.ts +62 -0
- package/src/types/model/timestamp.ts +15 -0
- package/src/types/model/title.ts +8 -0
- package/src/types/model/types.ts +91 -0
- package/src/types/model/uid.ts +14 -0
- package/src/types/utils.ts +34 -0
- package/src/types/value/boolean.ts +6 -0
- package/src/types/value/color.ts +10 -0
- package/src/types/value/contentRelationship.ts +48 -0
- package/src/types/value/date.ts +10 -0
- package/src/types/value/document.ts +142 -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 +25 -0
- package/src/types/value/number.ts +10 -0
- package/src/types/value/richText.ts +286 -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 +16 -0
- package/src/types/value/timestamp.ts +12 -0
- package/src/types/value/title.ts +31 -0
- package/src/types/value/types.ts +60 -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/src/lib/orElseThrow.ts +0 -17
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import type { ColorField } from "../types/value/color";
|
|
2
|
+
import type { DateField } from "../types/value/date";
|
|
3
|
+
import type { EmbedField, AnyOEmbed } from "../types/value/embed";
|
|
4
|
+
import type { GeoPointField } from "../types/value/geoPoint";
|
|
5
|
+
import type { GroupField } from "../types/value/group";
|
|
6
|
+
import type { ImageFieldImage, ImageField } from "../types/value/image";
|
|
7
|
+
import type { IntegrationFields } from "../types/value/integrationFields";
|
|
8
|
+
import type { KeyTextField } from "../types/value/keyText";
|
|
9
|
+
import type { LinkField } from "../types/value/link";
|
|
10
|
+
import type { LinkToMediaField } from "../types/value/linkToMedia";
|
|
11
|
+
import type { ContentRelationshipField } from "../types/value/contentRelationship";
|
|
12
|
+
import type { NumberField } from "../types/value/number";
|
|
13
|
+
import type { RichTextField } from "../types/value/richText";
|
|
14
|
+
import type { SelectField } from "../types/value/select";
|
|
15
|
+
import type { SharedSlice } from "../types/value/sharedSlice";
|
|
16
|
+
import type { Slice } from "../types/value/slice";
|
|
17
|
+
import type { SliceZone } from "../types/value/sliceZone";
|
|
18
|
+
import type { TimestampField } from "../types/value/timestamp";
|
|
19
|
+
import type { TitleField } from "../types/value/title";
|
|
20
|
+
import type { AnyRegularField } from "../types/value/types";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Determines if a value is not nullish (i.e. not `null` or `undefined`). This
|
|
24
|
+
* is used to check if nullable field values are filled.
|
|
25
|
+
*
|
|
26
|
+
* @param input - The value to check.
|
|
27
|
+
*
|
|
28
|
+
* @returns `true` if `input` is not nullish, `false` otherwise.
|
|
29
|
+
*/
|
|
30
|
+
const isNonNullish = <T>(input: T): input is NonNullable<T> => {
|
|
31
|
+
return input != null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Determines if an array is not empty. This is used to check if array-based
|
|
36
|
+
* fields are filled.
|
|
37
|
+
*
|
|
38
|
+
* @param input - The array to check.
|
|
39
|
+
*
|
|
40
|
+
* @returns `true` if `input` has at least one element, `false` otherwise.
|
|
41
|
+
*/
|
|
42
|
+
const isNonEmptyArray = <T>(input: T[]): input is [T, ...T[]] => {
|
|
43
|
+
return !!input.length;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Determines if a Rich Text field is filled.
|
|
48
|
+
*
|
|
49
|
+
* @param field - Rich Text field to check.
|
|
50
|
+
*
|
|
51
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
52
|
+
*/
|
|
53
|
+
export const richText = (
|
|
54
|
+
field: RichTextField | null | undefined,
|
|
55
|
+
): field is RichTextField<"filled"> => {
|
|
56
|
+
if (!isNonNullish(field)) {
|
|
57
|
+
return false;
|
|
58
|
+
} else if (field.length === 1 && "text" in field[0]) {
|
|
59
|
+
return !!field[0].text;
|
|
60
|
+
} else {
|
|
61
|
+
return !!field.length;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Determines if a Title field is filled.
|
|
67
|
+
*
|
|
68
|
+
* @param field - Title field to check.
|
|
69
|
+
*
|
|
70
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
71
|
+
*/
|
|
72
|
+
export const title = richText as (
|
|
73
|
+
field: TitleField | null | undefined,
|
|
74
|
+
) => field is TitleField<"filled">;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Determines if an Image thumbnail is filled.
|
|
78
|
+
*
|
|
79
|
+
* @param thumbnail - Image thumbnail to check.
|
|
80
|
+
*
|
|
81
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
82
|
+
*/
|
|
83
|
+
export const imageThumbnail = (
|
|
84
|
+
thumbnail: ImageFieldImage | null | undefined,
|
|
85
|
+
): thumbnail is ImageFieldImage<"filled"> => {
|
|
86
|
+
return isNonNullish(thumbnail) && !!thumbnail.url;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Determines if an Image field is filled.
|
|
91
|
+
*
|
|
92
|
+
* @param field - Image field to check.
|
|
93
|
+
*
|
|
94
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
95
|
+
*/
|
|
96
|
+
export const image = imageThumbnail as <
|
|
97
|
+
ThumbnailNames extends string | null = never,
|
|
98
|
+
>(
|
|
99
|
+
field: ImageField<ThumbnailNames> | null | undefined,
|
|
100
|
+
) => field is ImageField<ThumbnailNames, "filled">;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Determines if a Link field is filled.
|
|
104
|
+
*
|
|
105
|
+
* @param field - Link field to check.
|
|
106
|
+
*
|
|
107
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
108
|
+
*/
|
|
109
|
+
export const link = <
|
|
110
|
+
TypeEnum = string,
|
|
111
|
+
LangEnum = string,
|
|
112
|
+
DataInterface extends Record<
|
|
113
|
+
string,
|
|
114
|
+
AnyRegularField | GroupField | SliceZone
|
|
115
|
+
> = never,
|
|
116
|
+
>(
|
|
117
|
+
field: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined,
|
|
118
|
+
): field is LinkField<TypeEnum, LangEnum, DataInterface, "filled"> => {
|
|
119
|
+
return isNonNullish(field) && ("id" in field || "url" in field);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Determines if a Link to Media field is filled.
|
|
124
|
+
*
|
|
125
|
+
* @param field - Link to Media field to check.
|
|
126
|
+
*
|
|
127
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
128
|
+
*/
|
|
129
|
+
export const linkToMedia = link as (
|
|
130
|
+
field: LinkToMediaField | null | undefined,
|
|
131
|
+
) => field is LinkToMediaField<"filled">;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Determines if a Content Relationship field is filled.
|
|
135
|
+
*
|
|
136
|
+
* @param field - Content Relationship field to check.
|
|
137
|
+
*
|
|
138
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
139
|
+
*/
|
|
140
|
+
export const contentRelationship = link as <
|
|
141
|
+
TypeEnum = string,
|
|
142
|
+
LangEnum = string,
|
|
143
|
+
DataInterface extends Record<
|
|
144
|
+
string,
|
|
145
|
+
AnyRegularField | GroupField | SliceZone
|
|
146
|
+
> = never,
|
|
147
|
+
>(
|
|
148
|
+
field:
|
|
149
|
+
| ContentRelationshipField<TypeEnum, LangEnum, DataInterface>
|
|
150
|
+
| null
|
|
151
|
+
| undefined,
|
|
152
|
+
) => field is ContentRelationshipField<
|
|
153
|
+
TypeEnum,
|
|
154
|
+
LangEnum,
|
|
155
|
+
DataInterface,
|
|
156
|
+
"filled"
|
|
157
|
+
>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Determines if a Date field is filled.
|
|
161
|
+
*
|
|
162
|
+
* @param field - Date field to check.
|
|
163
|
+
*
|
|
164
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
165
|
+
*/
|
|
166
|
+
export const date = isNonNullish as (
|
|
167
|
+
field: DateField | null | undefined,
|
|
168
|
+
) => field is DateField<"filled">;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Determines if a Timestamp field is filled.
|
|
172
|
+
*
|
|
173
|
+
* @param field - Timestamp field to check.
|
|
174
|
+
*
|
|
175
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
176
|
+
*/
|
|
177
|
+
export const timestamp = isNonNullish as (
|
|
178
|
+
field: TimestampField | null | undefined,
|
|
179
|
+
) => field is TimestampField<"filled">;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Determines if a Color field is filled.
|
|
183
|
+
*
|
|
184
|
+
* @param field - Color field to check.
|
|
185
|
+
*
|
|
186
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
187
|
+
*/
|
|
188
|
+
export const color = isNonNullish as (
|
|
189
|
+
field: ColorField | null | undefined,
|
|
190
|
+
) => field is ColorField<"filled">;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Determines if a Number field is filled.
|
|
194
|
+
*
|
|
195
|
+
* @param field - Number field to check.
|
|
196
|
+
*
|
|
197
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
198
|
+
*/
|
|
199
|
+
export const number = isNonNullish as (
|
|
200
|
+
field: NumberField | null | undefined,
|
|
201
|
+
) => field is NumberField<"filled">;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Determines if a Key Text field is filled.
|
|
205
|
+
*
|
|
206
|
+
* @param field - Key Text field to check.
|
|
207
|
+
*
|
|
208
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
209
|
+
*/
|
|
210
|
+
export const keyText = (
|
|
211
|
+
field: KeyTextField | null | undefined,
|
|
212
|
+
): field is KeyTextField<"filled"> => {
|
|
213
|
+
return isNonNullish(keyText) && !!field;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Determines if a Select field is filled.
|
|
218
|
+
*
|
|
219
|
+
* @param field - Select field to check.
|
|
220
|
+
*
|
|
221
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
222
|
+
*/
|
|
223
|
+
export const select = isNonNullish as <Enum extends string>(
|
|
224
|
+
field: SelectField<Enum> | null | undefined,
|
|
225
|
+
) => field is SelectField<Enum, "filled">;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Determines if an Embed field is filled.
|
|
229
|
+
*
|
|
230
|
+
* @param field - Embed field to check.
|
|
231
|
+
*
|
|
232
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
233
|
+
*/
|
|
234
|
+
export const embed = <Field extends EmbedField<AnyOEmbed>>(
|
|
235
|
+
field: Field | null | undefined,
|
|
236
|
+
): field is Extract<Field, EmbedField<AnyOEmbed, "filled">> => {
|
|
237
|
+
return isNonNullish(field) && !!field.embed_url;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Determines if a GeoPoint field is filled.
|
|
242
|
+
*
|
|
243
|
+
* @param field - GeoPoint field to check.
|
|
244
|
+
*
|
|
245
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
246
|
+
*/
|
|
247
|
+
export const geoPoint = (
|
|
248
|
+
field: GeoPointField | null | undefined,
|
|
249
|
+
): field is GeoPointField<"filled"> => {
|
|
250
|
+
return isNonNullish(field) && "longitude" in field;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Determines if an Integration Fields field is filled.
|
|
255
|
+
*
|
|
256
|
+
* @param field - Integration Fields field to check.
|
|
257
|
+
*
|
|
258
|
+
* @returns `true` if `field` is filled, `false` otherwise.
|
|
259
|
+
*/
|
|
260
|
+
export const integrationFields = isNonNullish as <
|
|
261
|
+
Data extends Record<string, unknown>,
|
|
262
|
+
>(
|
|
263
|
+
field: IntegrationFields<Data> | null | undefined,
|
|
264
|
+
) => field is IntegrationFields<Data, "filled">;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Determines if a Group has at least one item.
|
|
268
|
+
*
|
|
269
|
+
* @param group - Group to check.
|
|
270
|
+
*
|
|
271
|
+
* @returns `true` if `group` contains at least one item, `false` otherwise.
|
|
272
|
+
*/
|
|
273
|
+
export const group = <Fields extends Record<string, AnyRegularField>>(
|
|
274
|
+
group: GroupField<Fields> | null | undefined,
|
|
275
|
+
): group is GroupField<Fields, "filled"> => {
|
|
276
|
+
return isNonNullish(group) && isNonEmptyArray(group);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Determines if a Slice Zone has at least one Slice.
|
|
281
|
+
*
|
|
282
|
+
* @param slices - Slice Zone to check.
|
|
283
|
+
*
|
|
284
|
+
* @returns `true` if `slices` contains at least one Slice, `false` otherwise.
|
|
285
|
+
*/
|
|
286
|
+
export const sliceZone = <Slices extends Slice | SharedSlice>(
|
|
287
|
+
slices: SliceZone<Slices> | null | undefined,
|
|
288
|
+
): slices is SliceZone<Slices, "filled"> => {
|
|
289
|
+
return isNonNullish(slices) && isNonEmptyArray(slices);
|
|
290
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// TODO: Remove in v3.
|
|
8
|
-
export const getEndpoint = getRepositoryEndpoint;
|
|
1
|
+
//=============================================================================
|
|
2
|
+
// Client - Everything you need to query data from Prismic.
|
|
3
|
+
//=============================================================================
|
|
4
|
+
|
|
5
|
+
// Primary Client API.
|
|
6
|
+
export { getRepositoryEndpoint } from "./getRepositoryEndpoint";
|
|
9
7
|
export { getRepositoryName } from "./getRepositoryName";
|
|
10
8
|
export { getGraphQLEndpoint } from "./getGraphQLEndpoint";
|
|
11
9
|
export { isRepositoryName } from "./isRepositoryName";
|
|
@@ -14,18 +12,7 @@ export { buildQueryURL } from "./buildQueryURL";
|
|
|
14
12
|
export { createClient, Client } from "./client";
|
|
15
13
|
|
|
16
14
|
// Predicates API.
|
|
17
|
-
|
|
18
|
-
export { predicate };
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Renamed to `predicate` (without an "s").
|
|
21
|
-
*/
|
|
22
|
-
// TODO: Remove in v3.
|
|
23
|
-
export const predicates = predicate;
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Renamed to `predicate` (lowercase and without an "s").
|
|
26
|
-
*/
|
|
27
|
-
// TODO: Remove in v3.
|
|
28
|
-
export const Predicates = predicate;
|
|
15
|
+
export { predicate } from "./predicate";
|
|
29
16
|
|
|
30
17
|
// Custom errors used by Client.
|
|
31
18
|
export { PrismicError } from "./PrismicError";
|
|
@@ -47,4 +34,233 @@ export type {
|
|
|
47
34
|
RequestInitLike,
|
|
48
35
|
ResponseLike,
|
|
49
36
|
Route,
|
|
50
|
-
} from "./types";
|
|
37
|
+
} from "./types/client";
|
|
38
|
+
|
|
39
|
+
//=============================================================================
|
|
40
|
+
// Helpers - Everything you need to template Prismic data.
|
|
41
|
+
//=============================================================================
|
|
42
|
+
|
|
43
|
+
// Primary Helpers API.
|
|
44
|
+
export { asDate } from "./helpers/asDate";
|
|
45
|
+
export { asLink } from "./helpers/asLink";
|
|
46
|
+
export { asText } from "./helpers/asText";
|
|
47
|
+
export { asHTML } from "./helpers/asHTML";
|
|
48
|
+
export { asImageSrc } from "./helpers/asImageSrc";
|
|
49
|
+
export { asImageWidthSrcSet } from "./helpers/asImageWidthSrcSet";
|
|
50
|
+
export { asImagePixelDensitySrcSet } from "./helpers/asImagePixelDensitySrcSet";
|
|
51
|
+
export * as isFilled from "./helpers/isFilled";
|
|
52
|
+
|
|
53
|
+
// Conversion helper.
|
|
54
|
+
export { documentToLinkField } from "./helpers/documentToLinkField";
|
|
55
|
+
|
|
56
|
+
// RichText element types.
|
|
57
|
+
export { Element } from "@prismicio/richtext";
|
|
58
|
+
|
|
59
|
+
export type {
|
|
60
|
+
LinkResolverFunction,
|
|
61
|
+
HTMLFunctionSerializer,
|
|
62
|
+
HTMLMapSerializer,
|
|
63
|
+
} from "./types/helpers";
|
|
64
|
+
|
|
65
|
+
//=============================================================================
|
|
66
|
+
// Value - Types representing Prismic document and field values.
|
|
67
|
+
//=============================================================================
|
|
68
|
+
|
|
69
|
+
export { RichTextNodeType } from "./types/value/richText";
|
|
70
|
+
export { LinkType } from "./types/value/link";
|
|
71
|
+
export { OEmbedType } from "./types/value/embed";
|
|
72
|
+
|
|
73
|
+
export type {
|
|
74
|
+
PrismicDocument,
|
|
75
|
+
PrismicDocumentWithUID,
|
|
76
|
+
PrismicDocumentWithoutUID,
|
|
77
|
+
PrismicDocumentHeader,
|
|
78
|
+
AlternateLanguage,
|
|
79
|
+
} from "./types/value/document";
|
|
80
|
+
|
|
81
|
+
export type {
|
|
82
|
+
// RichText & Title
|
|
83
|
+
RichTextField,
|
|
84
|
+
// RichText & Title (block nodes)
|
|
85
|
+
RTTextNodeBase,
|
|
86
|
+
RTHeading1Node,
|
|
87
|
+
RTHeading2Node,
|
|
88
|
+
RTHeading3Node,
|
|
89
|
+
RTHeading4Node,
|
|
90
|
+
RTHeading5Node,
|
|
91
|
+
RTHeading6Node,
|
|
92
|
+
RTParagraphNode,
|
|
93
|
+
RTPreformattedNode,
|
|
94
|
+
RTListItemNode,
|
|
95
|
+
RTOListItemNode,
|
|
96
|
+
// RichText & Title (span nodes)
|
|
97
|
+
RTSpanNodeBase,
|
|
98
|
+
RTStrongNode,
|
|
99
|
+
RTEmNode,
|
|
100
|
+
RTLabelNode,
|
|
101
|
+
// RichText & Title (media nodes)
|
|
102
|
+
RTImageNode,
|
|
103
|
+
RTEmbedNode,
|
|
104
|
+
// RichText & Title (link nodes)
|
|
105
|
+
RTLinkNode,
|
|
106
|
+
// RichText & Title (serialization related nodes)
|
|
107
|
+
RTListNode,
|
|
108
|
+
RTOListNode,
|
|
109
|
+
RTSpanNode,
|
|
110
|
+
// RichText & Title (helpers)
|
|
111
|
+
RTNode,
|
|
112
|
+
RTTextNode,
|
|
113
|
+
RTBlockNode,
|
|
114
|
+
RTInlineNode,
|
|
115
|
+
RTAnyNode,
|
|
116
|
+
} from "./types/value/richText";
|
|
117
|
+
export type { TitleField } from "./types/value/title";
|
|
118
|
+
|
|
119
|
+
export type {
|
|
120
|
+
ImageField,
|
|
121
|
+
ImageFieldImage,
|
|
122
|
+
FilledImageFieldImage,
|
|
123
|
+
EmptyImageFieldImage,
|
|
124
|
+
} from "./types/value/image";
|
|
125
|
+
|
|
126
|
+
export type {
|
|
127
|
+
EmptyLinkField,
|
|
128
|
+
LinkField,
|
|
129
|
+
FilledLinkToWebField,
|
|
130
|
+
} from "./types/value/link";
|
|
131
|
+
export type {
|
|
132
|
+
ContentRelationshipField,
|
|
133
|
+
FilledContentRelationshipField,
|
|
134
|
+
} from "./types/value/contentRelationship";
|
|
135
|
+
export type {
|
|
136
|
+
LinkToMediaField,
|
|
137
|
+
FilledLinkToMediaField,
|
|
138
|
+
} from "./types/value/linkToMedia";
|
|
139
|
+
|
|
140
|
+
export type {
|
|
141
|
+
OEmbedExtra,
|
|
142
|
+
PhotoOEmbed,
|
|
143
|
+
VideoOEmbed,
|
|
144
|
+
LinkOEmbed,
|
|
145
|
+
RichOEmbed,
|
|
146
|
+
AnyOEmbed,
|
|
147
|
+
EmbedField,
|
|
148
|
+
} from "./types/value/embed";
|
|
149
|
+
|
|
150
|
+
export type { BooleanField } from "./types/value/boolean";
|
|
151
|
+
export type { ColorField } from "./types/value/color";
|
|
152
|
+
export type { DateField } from "./types/value/date";
|
|
153
|
+
export type { KeyTextField } from "./types/value/keyText";
|
|
154
|
+
export type { NumberField } from "./types/value/number";
|
|
155
|
+
export type { SelectField } from "./types/value/select";
|
|
156
|
+
export type { TimestampField } from "./types/value/timestamp";
|
|
157
|
+
export type { GeoPointField } from "./types/value/geoPoint";
|
|
158
|
+
|
|
159
|
+
export type { IntegrationFields } from "./types/value/integrationFields";
|
|
160
|
+
|
|
161
|
+
export type { GroupField } from "./types/value/group";
|
|
162
|
+
|
|
163
|
+
export type { SliceZone } from "./types/value/sliceZone";
|
|
164
|
+
export type { Slice } from "./types/value/slice";
|
|
165
|
+
export type { SharedSlice } from "./types/value/sharedSlice";
|
|
166
|
+
export type { SharedSliceVariation } from "./types/value/sharedSliceVariation";
|
|
167
|
+
|
|
168
|
+
export type { FieldState, AnyRegularField } from "./types/value/types";
|
|
169
|
+
|
|
170
|
+
//=============================================================================
|
|
171
|
+
// Model - Types representing Prismic Custom Type and Shared Slice models.
|
|
172
|
+
//=============================================================================
|
|
173
|
+
|
|
174
|
+
export { CustomTypeModelFieldType } from "./types/model/types";
|
|
175
|
+
export { CustomTypeModelLinkSelectType } from "./types/model/link";
|
|
176
|
+
export { CustomTypeModelSliceType } from "./types/model/sliceZone";
|
|
177
|
+
export { CustomTypeModelSliceDisplay } from "./types/model/slice";
|
|
178
|
+
|
|
179
|
+
export type {
|
|
180
|
+
CustomTypeModel,
|
|
181
|
+
CustomTypeModelDefinition,
|
|
182
|
+
CustomTypeModelTab,
|
|
183
|
+
} from "./types/model/customType";
|
|
184
|
+
|
|
185
|
+
export type {
|
|
186
|
+
CustomTypeModelRichTextField,
|
|
187
|
+
CustomTypeModelRichTextMultiField,
|
|
188
|
+
CustomTypeModelRichTextSingleField,
|
|
189
|
+
} from "./types/model/richText";
|
|
190
|
+
export type { CustomTypeModelTitleField } from "./types/model/title";
|
|
191
|
+
|
|
192
|
+
export type {
|
|
193
|
+
CustomTypeModelImageField,
|
|
194
|
+
CustomTypeModelImageConstraint,
|
|
195
|
+
CustomTypeModelImageThumbnail,
|
|
196
|
+
} from "./types/model/image";
|
|
197
|
+
|
|
198
|
+
export type { CustomTypeModelContentRelationshipField } from "./types/model/contentRelationship";
|
|
199
|
+
export type { CustomTypeModelLinkField } from "./types/model/link";
|
|
200
|
+
export type { CustomTypeModelLinkToMediaField } from "./types/model/linkToMedia";
|
|
201
|
+
|
|
202
|
+
export type { CustomTypeModelEmbedField } from "./types/model/embed";
|
|
203
|
+
|
|
204
|
+
export type { CustomTypeModelBooleanField } from "./types/model/boolean";
|
|
205
|
+
export type { CustomTypeModelColorField } from "./types/model/color";
|
|
206
|
+
export type { CustomTypeModelDateField } from "./types/model/date";
|
|
207
|
+
export type { CustomTypeModelKeyTextField } from "./types/model/keyText";
|
|
208
|
+
export type { CustomTypeModelNumberField } from "./types/model/number";
|
|
209
|
+
export type { CustomTypeModelSelectField } from "./types/model/select";
|
|
210
|
+
export type { CustomTypeModelTimestampField } from "./types/model/timestamp";
|
|
211
|
+
export type { CustomTypeModelGeoPointField } from "./types/model/geoPoint";
|
|
212
|
+
|
|
213
|
+
export type { CustomTypeModelIntegrationFieldsField } from "./types/model/integrationFields";
|
|
214
|
+
export type { CustomTypeModelGroupField } from "./types/model/group";
|
|
215
|
+
export type {
|
|
216
|
+
CustomTypeModelSliceZoneField,
|
|
217
|
+
CustomTypeModelSliceLabel,
|
|
218
|
+
CustomTypeModelSharedSlice,
|
|
219
|
+
} from "./types/model/sliceZone";
|
|
220
|
+
export type {
|
|
221
|
+
CustomTypeModelSlice,
|
|
222
|
+
CustomTypeModelLegacySlice,
|
|
223
|
+
} from "./types/model/slice";
|
|
224
|
+
export type { SharedSliceModel } from "./types/model/sharedSlice";
|
|
225
|
+
export type { SharedSliceModelVariation } from "./types/model/sharedSliceVariation";
|
|
226
|
+
|
|
227
|
+
export type { CustomTypeModelUIDField } from "./types/model/uid";
|
|
228
|
+
|
|
229
|
+
export type { CustomTypeModelRangeField } from "./types/model/range";
|
|
230
|
+
export type { CustomTypeModelSeparatorField } from "./types/model/separator";
|
|
231
|
+
|
|
232
|
+
export type {
|
|
233
|
+
CustomTypeModelField,
|
|
234
|
+
CustomTypeModelFieldForGroup,
|
|
235
|
+
} from "./types/model/types";
|
|
236
|
+
|
|
237
|
+
//=============================================================================
|
|
238
|
+
// API - Types representing Prismic Rest API V2 responses.
|
|
239
|
+
//=============================================================================
|
|
240
|
+
|
|
241
|
+
export type { Query } from "./types/api/query";
|
|
242
|
+
|
|
243
|
+
export type { Ref } from "./types/api/ref";
|
|
244
|
+
|
|
245
|
+
export type { Release } from "./types/api/release";
|
|
246
|
+
|
|
247
|
+
export type {
|
|
248
|
+
Repository,
|
|
249
|
+
Language,
|
|
250
|
+
Form,
|
|
251
|
+
FormField,
|
|
252
|
+
} from "./types/api/repository";
|
|
253
|
+
|
|
254
|
+
export type { Tags } from "./types/api/tags";
|
|
255
|
+
|
|
256
|
+
//=============================================================================
|
|
257
|
+
// Webhook - Types representing Prismic webhooks.
|
|
258
|
+
//=============================================================================
|
|
259
|
+
|
|
260
|
+
export { WebhookType } from "./types/webhook/types";
|
|
261
|
+
|
|
262
|
+
export type { WebhookBody } from "./types/webhook/types";
|
|
263
|
+
|
|
264
|
+
export type { WebhookBodyAPIUpdate } from "./types/webhook/apiUpdate";
|
|
265
|
+
|
|
266
|
+
export type { WebhookBodyTestTrigger } from "./types/webhook/testTrigger";
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param input - Input to test.
|
|
6
6
|
*
|
|
7
|
-
* @returns `true` if `input` is a valid Prismic Rest API V2 endpoint, `false`
|
|
7
|
+
* @returns `true` if `input` is a valid Prismic Rest API V2 endpoint, `false`
|
|
8
|
+
* otherwise.
|
|
8
9
|
*/
|
|
9
10
|
export const isRepositoryEndpoint = (input: string): boolean => {
|
|
10
11
|
try {
|
package/src/isRepositoryName.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param input - Input to test.
|
|
5
5
|
*
|
|
6
|
-
* @returns `true` if `input` is a valid Prismic repository name, `false`
|
|
6
|
+
* @returns `true` if `input` is a valid Prismic repository name, `false`
|
|
7
|
+
* otherwise.
|
|
7
8
|
*/
|
|
8
9
|
export const isRepositoryName = (input: string): boolean => {
|
|
9
10
|
return /^[a-zA-Z0-9][-a-zA-Z0-9]{2,}[a-zA-Z0-9]$/.test(input);
|
|
@@ -9,7 +9,8 @@ interface WithPredicates {
|
|
|
9
9
|
* Appended predicates are added to the end of the existing list.
|
|
10
10
|
*
|
|
11
11
|
* @typeParam T - Object to which predicates will be append.
|
|
12
|
-
* @param objWithPredicates - Object to append predicates on the `predicates`
|
|
12
|
+
* @param objWithPredicates - Object to append predicates on the `predicates`
|
|
13
|
+
* property.
|
|
13
14
|
* @param predicates - One or more predicates to append.
|
|
14
15
|
*
|
|
15
16
|
* @returns The object with the appended predicates.
|
package/src/lib/findMasterRef.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
3
|
import { findRef } from "./findRef";
|
|
4
4
|
|
|
@@ -10,6 +10,6 @@ import { findRef } from "./findRef";
|
|
|
10
10
|
* @returns The master ref from the list.
|
|
11
11
|
* @throws If a matching ref cannot be found.
|
|
12
12
|
*/
|
|
13
|
-
export const findMasterRef = (refs:
|
|
13
|
+
export const findMasterRef = (refs: Ref[]): Ref => {
|
|
14
14
|
return findRef(refs, (ref) => ref.isMasterRef);
|
|
15
15
|
};
|
package/src/lib/findRef.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
3
|
import { PrismicError } from "../PrismicError";
|
|
4
4
|
|
|
@@ -13,10 +13,7 @@ import { PrismicError } from "../PrismicError";
|
|
|
13
13
|
* @returns The first matching ref.
|
|
14
14
|
* @throws If a matching ref cannot be found.
|
|
15
15
|
*/
|
|
16
|
-
export const findRef = (
|
|
17
|
-
refs: prismicT.Ref[],
|
|
18
|
-
predicate: (ref: prismicT.Ref) => boolean,
|
|
19
|
-
): prismicT.Ref => {
|
|
16
|
+
export const findRef = (refs: Ref[], predicate: (ref: Ref) => boolean): Ref => {
|
|
20
17
|
const ref = refs.find((ref) => predicate(ref));
|
|
21
18
|
|
|
22
19
|
if (!ref) {
|
package/src/lib/findRefByID.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
3
|
import { findRef } from "./findRef";
|
|
4
4
|
|
|
@@ -11,6 +11,6 @@ import { findRef } from "./findRef";
|
|
|
11
11
|
* @returns The ref with a matching ID from the list.
|
|
12
12
|
* @throws If a matching ref cannot be found.
|
|
13
13
|
*/
|
|
14
|
-
export const findRefByID = (refs:
|
|
14
|
+
export const findRefByID = (refs: Ref[], id: string): Ref => {
|
|
15
15
|
return findRef(refs, (ref) => ref.id === id);
|
|
16
16
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "../types/api/ref";
|
|
2
2
|
|
|
3
3
|
import { findRef } from "./findRef";
|
|
4
4
|
|
|
@@ -11,9 +11,6 @@ import { findRef } from "./findRef";
|
|
|
11
11
|
* @returns The ref with a matching label from the list.
|
|
12
12
|
* @throws If a matching ref cannot be found.
|
|
13
13
|
*/
|
|
14
|
-
export const findRefByLabel = (
|
|
15
|
-
refs: prismicT.Ref[],
|
|
16
|
-
label: string,
|
|
17
|
-
): prismicT.Ref => {
|
|
14
|
+
export const findRefByLabel = (refs: Ref[], label: string): Ref => {
|
|
18
15
|
return findRef(refs, (ref) => ref.label === label);
|
|
19
16
|
};
|
|
@@ -7,7 +7,8 @@ const readValue = (value: string): string => {
|
|
|
7
7
|
/**
|
|
8
8
|
* Returns the value of a cookie from a given cookie store.
|
|
9
9
|
*
|
|
10
|
-
* @param cookieJar - The stringified cookie store from which to read the
|
|
10
|
+
* @param cookieJar - The stringified cookie store from which to read the
|
|
11
|
+
* cookie.
|
|
11
12
|
*
|
|
12
13
|
* @returns The value of the cookie, if it exists.
|
|
13
14
|
*/
|
|
@@ -22,7 +23,7 @@ export const getPreviewCookie = (cookieJar: string): string | undefined => {
|
|
|
22
23
|
|
|
23
24
|
if (name === previewCookieName) {
|
|
24
25
|
value = readValue(parts.slice(1).join("="));
|
|
25
|
-
|
|
26
|
+
break;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|