@prismicio/client 6.7.1 → 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.
Files changed (343) hide show
  1. package/dist/ForbiddenError.cjs +7 -0
  2. package/dist/ForbiddenError.cjs.map +1 -0
  3. package/dist/ForbiddenError.d.ts +11 -0
  4. package/dist/ForbiddenError.js +7 -0
  5. package/dist/ForbiddenError.js.map +1 -0
  6. package/dist/NotFoundError.cjs +7 -0
  7. package/dist/NotFoundError.cjs.map +1 -0
  8. package/dist/NotFoundError.d.ts +3 -0
  9. package/dist/NotFoundError.js +7 -0
  10. package/dist/NotFoundError.js.map +1 -0
  11. package/dist/ParsingError.cjs +7 -0
  12. package/dist/ParsingError.cjs.map +1 -0
  13. package/dist/ParsingError.d.ts +12 -0
  14. package/dist/ParsingError.js +7 -0
  15. package/dist/ParsingError.js.map +1 -0
  16. package/dist/PrismicError.cjs +19 -0
  17. package/dist/PrismicError.cjs.map +1 -0
  18. package/dist/PrismicError.d.ts +5 -0
  19. package/dist/PrismicError.js +19 -0
  20. package/dist/PrismicError.js.map +1 -0
  21. package/dist/buildQueryURL.cjs +41 -0
  22. package/dist/buildQueryURL.cjs.map +1 -0
  23. package/dist/buildQueryURL.d.ts +130 -0
  24. package/dist/buildQueryURL.js +41 -0
  25. package/dist/buildQueryURL.js.map +1 -0
  26. package/dist/client.cjs +414 -0
  27. package/dist/client.cjs.map +1 -0
  28. package/dist/client.d.ts +908 -0
  29. package/dist/client.js +414 -0
  30. package/dist/client.js.map +1 -0
  31. package/dist/cookie.cjs +5 -0
  32. package/dist/cookie.cjs.map +1 -0
  33. package/dist/cookie.d.ts +5 -0
  34. package/dist/cookie.js +5 -0
  35. package/dist/cookie.js.map +1 -0
  36. package/dist/getGraphQLEndpoint.cjs +13 -0
  37. package/dist/getGraphQLEndpoint.cjs.map +1 -0
  38. package/dist/getGraphQLEndpoint.d.ts +9 -0
  39. package/dist/getGraphQLEndpoint.js +13 -0
  40. package/dist/getGraphQLEndpoint.js.map +1 -0
  41. package/dist/getRepositoryEndpoint.cjs +13 -0
  42. package/dist/getRepositoryEndpoint.cjs.map +1 -0
  43. package/dist/getRepositoryEndpoint.d.ts +10 -0
  44. package/dist/getRepositoryEndpoint.js +13 -0
  45. package/dist/getRepositoryEndpoint.js.map +1 -0
  46. package/dist/getRepositoryName.cjs +12 -0
  47. package/dist/getRepositoryName.cjs.map +1 -0
  48. package/dist/getRepositoryName.d.ts +13 -0
  49. package/dist/getRepositoryName.js +12 -0
  50. package/dist/getRepositoryName.js.map +1 -0
  51. package/dist/helpers/asDate.cjs +14 -0
  52. package/dist/helpers/asDate.cjs.map +1 -0
  53. package/dist/helpers/asDate.d.ts +16 -0
  54. package/dist/helpers/asDate.js +14 -0
  55. package/dist/helpers/asDate.js.map +1 -0
  56. package/dist/helpers/asHTML.cjs +79 -0
  57. package/dist/helpers/asHTML.cjs.map +1 -0
  58. package/dist/helpers/asHTML.d.ts +20 -0
  59. package/dist/helpers/asHTML.js +79 -0
  60. package/dist/helpers/asHTML.js.map +1 -0
  61. package/dist/helpers/asImagePixelDensitySrcSet.cjs +21 -0
  62. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -0
  63. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -0
  64. package/dist/helpers/asImagePixelDensitySrcSet.js +21 -0
  65. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -0
  66. package/dist/helpers/asImageSrc.cjs +13 -0
  67. package/dist/helpers/asImageSrc.cjs.map +1 -0
  68. package/dist/helpers/asImageSrc.d.ts +27 -0
  69. package/dist/helpers/asImageSrc.js +13 -0
  70. package/dist/helpers/asImageSrc.js.map +1 -0
  71. package/dist/helpers/asImageWidthSrcSet.cjs +40 -0
  72. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -0
  73. package/dist/helpers/asImageWidthSrcSet.d.ts +60 -0
  74. package/dist/helpers/asImageWidthSrcSet.js +40 -0
  75. package/dist/helpers/asImageWidthSrcSet.js.map +1 -0
  76. package/dist/helpers/asLink.cjs +32 -0
  77. package/dist/helpers/asLink.cjs.map +1 -0
  78. package/dist/helpers/asLink.d.ts +24 -0
  79. package/dist/helpers/asLink.js +32 -0
  80. package/dist/helpers/asLink.js.map +1 -0
  81. package/dist/helpers/asText.cjs +12 -0
  82. package/dist/helpers/asText.cjs.map +1 -0
  83. package/dist/helpers/asText.d.ts +16 -0
  84. package/dist/helpers/asText.js +12 -0
  85. package/dist/helpers/asText.js.map +1 -0
  86. package/dist/helpers/documentToLinkField.cjs +19 -0
  87. package/dist/helpers/documentToLinkField.cjs.map +1 -0
  88. package/dist/helpers/documentToLinkField.d.ts +15 -0
  89. package/dist/helpers/documentToLinkField.js +19 -0
  90. package/dist/helpers/documentToLinkField.js.map +1 -0
  91. package/dist/helpers/isFilled.cjs +67 -0
  92. package/dist/helpers/isFilled.cjs.map +1 -0
  93. package/dist/helpers/isFilled.d.ts +175 -0
  94. package/dist/helpers/isFilled.js +67 -0
  95. package/dist/helpers/isFilled.js.map +1 -0
  96. package/dist/index.cjs +67 -721
  97. package/dist/index.cjs.map +1 -1
  98. package/dist/index.d.ts +92 -1526
  99. package/dist/index.js +64 -681
  100. package/dist/index.js.map +1 -1
  101. package/dist/isRepositoryEndpoint.cjs +12 -0
  102. package/dist/isRepositoryEndpoint.cjs.map +1 -0
  103. package/dist/isRepositoryEndpoint.d.ts +10 -0
  104. package/dist/isRepositoryEndpoint.js +12 -0
  105. package/dist/isRepositoryEndpoint.js.map +1 -0
  106. package/dist/isRepositoryName.cjs +7 -0
  107. package/dist/isRepositoryName.cjs.map +1 -0
  108. package/dist/isRepositoryName.d.ts +9 -0
  109. package/dist/isRepositoryName.js +7 -0
  110. package/dist/isRepositoryName.js.map +1 -0
  111. package/dist/lib/appendPredicates.cjs +14 -0
  112. package/dist/lib/appendPredicates.cjs.map +1 -0
  113. package/dist/lib/appendPredicates.d.ts +18 -0
  114. package/dist/lib/appendPredicates.js +14 -0
  115. package/dist/lib/appendPredicates.js.map +1 -0
  116. package/dist/lib/castArray.cjs +5 -0
  117. package/dist/lib/castArray.cjs.map +1 -0
  118. package/dist/lib/castArray.d.ts +11 -0
  119. package/dist/lib/castArray.js +5 -0
  120. package/dist/lib/castArray.js.map +1 -0
  121. package/dist/lib/castThunk.cjs +5 -0
  122. package/dist/lib/castThunk.cjs.map +1 -0
  123. package/dist/lib/castThunk.d.ts +10 -0
  124. package/dist/lib/castThunk.js +5 -0
  125. package/dist/lib/castThunk.js.map +1 -0
  126. package/dist/lib/findMasterRef.cjs +8 -0
  127. package/dist/lib/findMasterRef.cjs.map +1 -0
  128. package/dist/lib/findMasterRef.d.ts +10 -0
  129. package/dist/lib/findMasterRef.js +8 -0
  130. package/dist/lib/findMasterRef.js.map +1 -0
  131. package/dist/lib/findRef.cjs +12 -0
  132. package/dist/lib/findRef.cjs.map +1 -0
  133. package/dist/lib/findRef.d.ts +13 -0
  134. package/dist/lib/findRef.js +12 -0
  135. package/dist/lib/findRef.js.map +1 -0
  136. package/dist/lib/findRefByID.cjs +8 -0
  137. package/dist/lib/findRefByID.cjs.map +1 -0
  138. package/dist/lib/findRefByID.d.ts +11 -0
  139. package/dist/lib/findRefByID.js +8 -0
  140. package/dist/lib/findRefByID.js.map +1 -0
  141. package/dist/lib/findRefByLabel.cjs +8 -0
  142. package/dist/lib/findRefByLabel.cjs.map +1 -0
  143. package/dist/lib/findRefByLabel.d.ts +11 -0
  144. package/dist/lib/findRefByLabel.js +8 -0
  145. package/dist/lib/findRefByLabel.js.map +1 -0
  146. package/dist/lib/getPreviewCookie.cjs +21 -0
  147. package/dist/lib/getPreviewCookie.cjs.map +1 -0
  148. package/dist/lib/getPreviewCookie.d.ts +9 -0
  149. package/dist/lib/getPreviewCookie.js +21 -0
  150. package/dist/lib/getPreviewCookie.js.map +1 -0
  151. package/dist/lib/minifyGraphQLQuery.cjs +7 -0
  152. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
  153. package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
  154. package/dist/lib/minifyGraphQLQuery.js +7 -0
  155. package/dist/lib/minifyGraphQLQuery.js.map +1 -0
  156. package/dist/lib/serializerHelpers.cjs +56 -0
  157. package/dist/lib/serializerHelpers.cjs.map +1 -0
  158. package/dist/lib/serializerHelpers.d.ts +9 -0
  159. package/dist/lib/serializerHelpers.js +54 -0
  160. package/dist/lib/serializerHelpers.js.map +1 -0
  161. package/dist/predicate.cjs +68 -0
  162. package/dist/predicate.cjs.map +1 -0
  163. package/dist/predicate.d.ts +209 -0
  164. package/dist/predicate.js +68 -0
  165. package/dist/predicate.js.map +1 -0
  166. package/dist/types/api/query.d.ts +42 -0
  167. package/dist/types/api/ref.d.ts +32 -0
  168. package/dist/types/api/release.d.ts +10 -0
  169. package/dist/types/api/repository.d.ts +100 -0
  170. package/dist/types/api/tags.d.ts +8 -0
  171. package/dist/types/client.d.ts +128 -0
  172. package/dist/types/helpers.d.ts +63 -0
  173. package/dist/types/model/boolean.d.ts +15 -0
  174. package/dist/types/model/color.d.ts +13 -0
  175. package/dist/types/model/contentRelationship.d.ts +18 -0
  176. package/dist/types/model/customType.d.ts +42 -0
  177. package/dist/types/model/date.d.ts +14 -0
  178. package/dist/types/model/embed.d.ts +13 -0
  179. package/dist/types/model/geoPoint.d.ts +12 -0
  180. package/dist/types/model/group.d.ts +15 -0
  181. package/dist/types/model/image.d.ts +31 -0
  182. package/dist/types/model/integrationFields.d.ts +14 -0
  183. package/dist/types/model/keyText.d.ts +13 -0
  184. package/dist/types/model/link.cjs +9 -0
  185. package/dist/types/model/link.cjs.map +1 -0
  186. package/dist/types/model/link.d.ts +27 -0
  187. package/dist/types/model/link.js +9 -0
  188. package/dist/types/model/link.js.map +1 -0
  189. package/dist/types/model/linkToMedia.d.ts +16 -0
  190. package/dist/types/model/number.d.ts +15 -0
  191. package/dist/types/model/range.d.ts +14 -0
  192. package/dist/types/model/richText.d.ts +35 -0
  193. package/dist/types/model/select.d.ts +18 -0
  194. package/dist/types/model/separator.d.ts +10 -0
  195. package/dist/types/model/sharedSlice.d.ts +19 -0
  196. package/dist/types/model/sharedSliceVariation.d.ts +22 -0
  197. package/dist/types/model/slice.cjs +8 -0
  198. package/dist/types/model/slice.cjs.map +1 -0
  199. package/dist/types/model/slice.d.ts +33 -0
  200. package/dist/types/model/slice.js +8 -0
  201. package/dist/types/model/slice.js.map +1 -0
  202. package/dist/types/model/sliceZone.cjs +8 -0
  203. package/dist/types/model/sliceZone.cjs.map +1 -0
  204. package/dist/types/model/sliceZone.d.ts +44 -0
  205. package/dist/types/model/sliceZone.js +8 -0
  206. package/dist/types/model/sliceZone.js.map +1 -0
  207. package/dist/types/model/timestamp.d.ts +14 -0
  208. package/dist/types/model/title.d.ts +7 -0
  209. package/dist/types/model/types.cjs +25 -0
  210. package/dist/types/model/types.cjs.map +1 -0
  211. package/dist/types/model/types.d.ts +62 -0
  212. package/dist/types/model/types.js +25 -0
  213. package/dist/types/model/types.js.map +1 -0
  214. package/dist/types/model/uid.d.ts +13 -0
  215. package/dist/types/utils.d.ts +28 -0
  216. package/dist/types/value/boolean.d.ts +6 -0
  217. package/dist/types/value/color.d.ts +8 -0
  218. package/dist/types/value/contentRelationship.d.ts +29 -0
  219. package/dist/types/value/date.d.ts +8 -0
  220. package/dist/types/value/document.d.ts +113 -0
  221. package/dist/types/value/embed.cjs +10 -0
  222. package/dist/types/value/embed.cjs.map +1 -0
  223. package/dist/types/value/embed.d.ts +167 -0
  224. package/dist/types/value/embed.js +10 -0
  225. package/dist/types/value/embed.js.map +1 -0
  226. package/dist/types/value/geoPoint.d.ts +11 -0
  227. package/dist/types/value/group.d.ts +7 -0
  228. package/dist/types/value/image.d.ts +36 -0
  229. package/dist/types/value/integrationFields.d.ts +9 -0
  230. package/dist/types/value/keyText.d.ts +8 -0
  231. package/dist/types/value/link.cjs +10 -0
  232. package/dist/types/value/link.cjs.map +1 -0
  233. package/dist/types/value/link.d.ts +40 -0
  234. package/dist/types/value/link.js +10 -0
  235. package/dist/types/value/link.js.map +1 -0
  236. package/dist/types/value/linkToMedia.d.ts +20 -0
  237. package/dist/types/value/number.d.ts +8 -0
  238. package/dist/types/value/richText.cjs +25 -0
  239. package/dist/types/value/richText.cjs.map +1 -0
  240. package/dist/types/value/richText.d.ts +203 -0
  241. package/dist/types/value/richText.js +25 -0
  242. package/dist/types/value/richText.js.map +1 -0
  243. package/dist/types/value/select.d.ts +9 -0
  244. package/dist/types/value/sharedSlice.d.ts +11 -0
  245. package/dist/types/value/sharedSliceVariation.d.ts +7 -0
  246. package/dist/types/value/slice.d.ts +13 -0
  247. package/dist/types/value/sliceZone.d.ts +12 -0
  248. package/dist/types/value/timestamp.d.ts +8 -0
  249. package/dist/types/value/title.d.ts +12 -0
  250. package/dist/types/value/types.d.ts +40 -0
  251. package/dist/types/webhook/apiUpdate.d.ts +52 -0
  252. package/dist/types/webhook/testTrigger.d.ts +9 -0
  253. package/dist/types/webhook/types.cjs +8 -0
  254. package/dist/types/webhook/types.cjs.map +1 -0
  255. package/dist/types/webhook/types.d.ts +18 -0
  256. package/dist/types/webhook/types.js +8 -0
  257. package/dist/types/webhook/types.js.map +1 -0
  258. package/package.json +40 -33
  259. package/src/buildQueryURL.ts +8 -4
  260. package/src/client.ts +111 -118
  261. package/src/cookie.ts +2 -1
  262. package/src/getRepositoryName.ts +4 -2
  263. package/src/helpers/asDate.ts +48 -0
  264. package/src/helpers/asHTML.ts +154 -0
  265. package/src/helpers/asImagePixelDensitySrcSet.ts +96 -0
  266. package/src/helpers/asImageSrc.ts +41 -0
  267. package/src/helpers/asImageWidthSrcSet.ts +139 -0
  268. package/src/helpers/asLink.ts +99 -0
  269. package/src/helpers/asText.ts +29 -0
  270. package/src/helpers/documentToLinkField.ts +47 -0
  271. package/src/helpers/isFilled.ts +290 -0
  272. package/src/index.ts +237 -21
  273. package/src/isRepositoryEndpoint.ts +2 -1
  274. package/src/isRepositoryName.ts +2 -1
  275. package/src/lib/appendPredicates.ts +2 -1
  276. package/src/lib/findMasterRef.ts +2 -2
  277. package/src/lib/findRef.ts +2 -5
  278. package/src/lib/findRefByID.ts +2 -2
  279. package/src/lib/findRefByLabel.ts +2 -5
  280. package/src/lib/getPreviewCookie.ts +3 -2
  281. package/src/lib/serializerHelpers.ts +96 -0
  282. package/src/predicate.ts +4 -2
  283. package/src/types/api/query.ts +50 -0
  284. package/src/types/api/ref.ts +36 -0
  285. package/src/types/api/release.ts +11 -0
  286. package/src/types/api/repository.ts +117 -0
  287. package/src/types/api/tags.ts +8 -0
  288. package/src/{types.ts → types/client.ts} +3 -37
  289. package/src/types/helpers.ts +103 -0
  290. package/src/types/model/boolean.ts +16 -0
  291. package/src/types/model/color.ts +14 -0
  292. package/src/types/model/contentRelationship.ts +22 -0
  293. package/src/types/model/customType.ts +61 -0
  294. package/src/types/model/date.ts +15 -0
  295. package/src/types/model/embed.ts +14 -0
  296. package/src/types/model/geoPoint.ts +13 -0
  297. package/src/types/model/group.ts +24 -0
  298. package/src/types/model/image.ts +37 -0
  299. package/src/types/model/integrationFields.ts +15 -0
  300. package/src/types/model/keyText.ts +14 -0
  301. package/src/types/model/link.ts +31 -0
  302. package/src/types/model/linkToMedia.ts +17 -0
  303. package/src/types/model/number.ts +16 -0
  304. package/src/types/model/range.ts +15 -0
  305. package/src/types/model/richText.ts +40 -0
  306. package/src/types/model/select.ts +22 -0
  307. package/src/types/model/separator.ts +11 -0
  308. package/src/types/model/sharedSlice.ts +23 -0
  309. package/src/types/model/sharedSliceVariation.ts +33 -0
  310. package/src/types/model/slice.ts +49 -0
  311. package/src/types/model/sliceZone.ts +62 -0
  312. package/src/types/model/timestamp.ts +15 -0
  313. package/src/types/model/title.ts +8 -0
  314. package/src/types/model/types.ts +91 -0
  315. package/src/types/model/uid.ts +14 -0
  316. package/src/types/utils.ts +34 -0
  317. package/src/types/value/boolean.ts +6 -0
  318. package/src/types/value/color.ts +10 -0
  319. package/src/types/value/contentRelationship.ts +48 -0
  320. package/src/types/value/date.ts +10 -0
  321. package/src/types/value/document.ts +142 -0
  322. package/src/types/value/embed.ts +196 -0
  323. package/src/types/value/geoPoint.ts +15 -0
  324. package/src/types/value/group.ts +14 -0
  325. package/src/types/value/image.ts +67 -0
  326. package/src/types/value/integrationFields.ts +13 -0
  327. package/src/types/value/keyText.ts +10 -0
  328. package/src/types/value/link.ts +59 -0
  329. package/src/types/value/linkToMedia.ts +25 -0
  330. package/src/types/value/number.ts +10 -0
  331. package/src/types/value/richText.ts +286 -0
  332. package/src/types/value/select.ts +13 -0
  333. package/src/types/value/sharedSlice.ts +15 -0
  334. package/src/types/value/sharedSliceVariation.ts +18 -0
  335. package/src/types/value/slice.ts +24 -0
  336. package/src/types/value/sliceZone.ts +16 -0
  337. package/src/types/value/timestamp.ts +12 -0
  338. package/src/types/value/title.ts +31 -0
  339. package/src/types/value/types.ts +60 -0
  340. package/src/types/webhook/apiUpdate.ts +56 -0
  341. package/src/types/webhook/testTrigger.ts +10 -0
  342. package/src/types/webhook/types.ts +21 -0
  343. package/src/lib/orElseThrow.ts +0 -17
@@ -0,0 +1,96 @@
1
+ import escapeHtml from "escape-html";
2
+
3
+ import {
4
+ RTBlockNode,
5
+ RTInlineNode,
6
+ RTPreformattedNode,
7
+ RTImageNode,
8
+ RTEmbedNode,
9
+ RTLinkNode,
10
+ RichTextNodeType,
11
+ } from "../types/value/richText";
12
+ import { LinkType } from "../types/value/link";
13
+ import { LinkResolverFunction } from "../types/helpers";
14
+
15
+ import { asLink } from "../helpers/asLink";
16
+
17
+ export const getLabel = (node: RTBlockNode | RTInlineNode): string => {
18
+ return "data" in node && "label" in node.data
19
+ ? ` class="${node.data.label}"`
20
+ : "";
21
+ };
22
+
23
+ export const serializeStandardTag = (
24
+ tag: string,
25
+ node: RTBlockNode | RTInlineNode,
26
+ children: string[],
27
+ ): string => {
28
+ return `<${tag}${getLabel(node)}>${children.join("")}</${tag}>`;
29
+ };
30
+
31
+ export const serializePreFormatted = (node: RTPreformattedNode): string => {
32
+ return `<pre${getLabel(node)}>${escapeHtml(node.text)}</pre>`;
33
+ };
34
+
35
+ export const serializeImage = (
36
+ linkResolver: LinkResolverFunction<string> | undefined | null,
37
+ node: RTImageNode,
38
+ ): string => {
39
+ let imageTag = `<img src="${node.url}" alt="${escapeHtml(node.alt)}"${
40
+ node.copyright ? ` copyright="${escapeHtml(node.copyright)}"` : ""
41
+ } />`;
42
+
43
+ // If the image has a link, we wrap it with an anchor tag
44
+ if (node.linkTo) {
45
+ imageTag = serializeHyperlink(
46
+ linkResolver,
47
+ {
48
+ type: RichTextNodeType.hyperlink,
49
+ data: node.linkTo,
50
+ start: 0,
51
+ end: 0,
52
+ },
53
+ [imageTag],
54
+ );
55
+ }
56
+
57
+ return `<p class="block-img">${imageTag}</p>`;
58
+ };
59
+
60
+ export const serializeEmbed = (node: RTEmbedNode): string => {
61
+ return `<div data-oembed="${node.oembed.embed_url}" data-oembed-type="${
62
+ node.oembed.type
63
+ }" data-oembed-provider="${node.oembed.provider_name}"${getLabel(node)}>${
64
+ node.oembed.html
65
+ }</div>`;
66
+ };
67
+
68
+ export const serializeHyperlink = (
69
+ linkResolver: LinkResolverFunction | undefined | null,
70
+ node: RTLinkNode,
71
+ children: string[],
72
+ ): string => {
73
+ switch (node.data.link_type) {
74
+ case LinkType.Web: {
75
+ return `<a href="${escapeHtml(node.data.url)}" ${
76
+ node.data.target ? `target="${node.data.target}" ` : ""
77
+ }rel="noopener noreferrer"${getLabel(node)}>${children.join("")}</a>`;
78
+ }
79
+
80
+ case LinkType.Document: {
81
+ return `<a href="${asLink(node.data, linkResolver)}"${getLabel(
82
+ node,
83
+ )}>${children.join("")}</a>`;
84
+ }
85
+
86
+ case LinkType.Media: {
87
+ return `<a href="${node.data.url}"${getLabel(node)}>${children.join(
88
+ "",
89
+ )}</a>`;
90
+ }
91
+ }
92
+ };
93
+
94
+ export const serializeSpan = (content?: string): string => {
95
+ return content ? escapeHtml(content).replace(/\n/g, "<br />") : "";
96
+ };
package/src/predicate.ts CHANGED
@@ -30,7 +30,8 @@ const formatValue = (
30
30
  };
31
31
 
32
32
  /**
33
- * Creates a predicate builder function for predicates with a path and arguments.
33
+ * Creates a predicate builder function for predicates with a path and
34
+ * arguments.
34
35
  *
35
36
  * @typeParam Args - Arguments for the predicate.
36
37
  * @param name - Name of the predicate used in the resulting string.
@@ -72,7 +73,8 @@ const pathPredicate = (name: string) => {
72
73
  };
73
74
 
74
75
  /**
75
- * Creates a predicate builder function for predicates with only arguments and no path.
76
+ * Creates a predicate builder function for predicates with only arguments and
77
+ * no path.
76
78
  *
77
79
  * @param name - Name of the predicate used in the resulting string.
78
80
  *
@@ -0,0 +1,50 @@
1
+ import { PrismicDocument } from "../value/document";
2
+
3
+ /**
4
+ * A query response from the Prismic REST API V2. The response contains
5
+ * paginated metadata and a list of matching results for the query.
6
+ *
7
+ * @typeParam Document - The type(s) of Prismic document that can be returned.
8
+ * @see More details on querying: {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api}
9
+ */
10
+ export interface Query<Document extends PrismicDocument = PrismicDocument> {
11
+ /**
12
+ * The page number for this page of results.
13
+ */
14
+ page: number;
15
+
16
+ /**
17
+ * Maximum number of results per page.
18
+ */
19
+ results_per_page: number;
20
+
21
+ /**
22
+ * Number of results in this page.
23
+ */
24
+ results_size: number;
25
+
26
+ /**
27
+ * Total number of results within all pages.
28
+ */
29
+ total_results_size: number;
30
+
31
+ /**
32
+ * Total number of pages.
33
+ */
34
+ total_pages: number;
35
+
36
+ /**
37
+ * The Prismic REST API V2 URL to the next page, if one exists.
38
+ */
39
+ next_page: string | null;
40
+
41
+ /**
42
+ * The Prismic REST API V2 URL to the previous page, if one exists.
43
+ */
44
+ prev_page: string | null;
45
+
46
+ /**
47
+ * A paginated list of documents matching the query.
48
+ */
49
+ results: Document[];
50
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Metadata for a reference to a version of a repository's content.
3
+ *
4
+ * @see More details on refs: {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}
5
+ */
6
+ export interface Ref {
7
+ /**
8
+ * The unique identifier for the ref.
9
+ */
10
+ id: string;
11
+
12
+ /**
13
+ * The identifier that should be provided to the API to select a content
14
+ * version.
15
+ */
16
+ ref: string;
17
+
18
+ /**
19
+ * A human-readable name for the ref. The master ref is always named "Master".
20
+ */
21
+ label: string;
22
+
23
+ /**
24
+ * Determines if the ref is the master ref. The master ref contains the latest
25
+ * published content.
26
+ */
27
+ isMasterRef: boolean;
28
+
29
+ /**
30
+ * If the ref is associated with a Release, this field contains the timestamp
31
+ * at which the Release will be automatically published, if set.
32
+ *
33
+ * @see More details on Releases: {@link https://prismic.io/docs/core-concepts/draft-plan-and-schedule-content#releases}
34
+ */
35
+ scheduledAt?: string;
36
+ }
@@ -0,0 +1,11 @@
1
+ import { Ref } from "./ref";
2
+
3
+ /**
4
+ * Metadata for a Release.
5
+ *
6
+ * @remarks
7
+ * This is an alias for `Ref`.
8
+ * @see {@link Ref}
9
+ * @see More details on Releases: {@link https://prismic.io/docs/core-concepts/draft-plan-and-schedule-content#releases}
10
+ */
11
+ export type Release = Ref;
@@ -0,0 +1,117 @@
1
+ import { Ref } from "./ref";
2
+
3
+ /**
4
+ * Repository metadata returned from the Prismic REST API V2. This data can be
5
+ * fetched by sending a `GET` a request to a repository's `/api/v2` endpoint.
6
+ *
7
+ * @see More details on the `/api/v2` endpoint: {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#the-api-endpoint-2}
8
+ */
9
+ export interface Repository {
10
+ /**
11
+ * A list of refs for the repository.
12
+ *
13
+ * @see {@link Ref}
14
+ */
15
+ refs: Ref[];
16
+
17
+ /**
18
+ * An identifier used to query content with the latest Integration Fields
19
+ * data.
20
+ */
21
+ integrationFieldsRef: string | null;
22
+
23
+ /**
24
+ * A list of languages for the repository.
25
+ *
26
+ * @see {@link Language}
27
+ */
28
+ languages: Language[];
29
+
30
+ /**
31
+ * A list of the repository's Custom Type API IDs mapped to their
32
+ * human-readable name.
33
+ */
34
+ types: Record<string, string>;
35
+
36
+ /**
37
+ * A list of tags for the repository.
38
+ */
39
+ tags: string[];
40
+
41
+ /**
42
+ * An internally-used list of REST API features for the repository.
43
+ *
44
+ * @internal
45
+ */
46
+ forms: Record<string, Form>;
47
+
48
+ /**
49
+ * The URL used to begin the OAuth process for the repository.
50
+ */
51
+ oauth_initiate: string;
52
+
53
+ // TODO: Describe this field
54
+ oauth_token: string;
55
+
56
+ /**
57
+ * The version of the API.
58
+ */
59
+ version: string;
60
+
61
+ /**
62
+ * Licensing information for the repository content.
63
+ */
64
+ license: string;
65
+
66
+ /**
67
+ * @deprecated Experiments are no longer part of Prismic.
68
+ */
69
+ experiments: unknown;
70
+
71
+ /**
72
+ * @deprecated Bookmarks are not longer part of Prismic.
73
+ */
74
+ bookmarks: Record<string, string>;
75
+ }
76
+
77
+ /**
78
+ * Metadata for a language that has been configured for a repository.
79
+ */
80
+ export interface Language {
81
+ /**
82
+ * A unique identifier for the language.
83
+ */
84
+ id: string;
85
+
86
+ /**
87
+ * The name of the language.
88
+ */
89
+ name: string;
90
+ }
91
+
92
+ /**
93
+ * A Prismic REST API V2 feature supported by the repository. It contains
94
+ * metadata about the feature and how to interact with it via the API.
95
+ *
96
+ * @internal
97
+ */
98
+ export interface Form {
99
+ method: "GET";
100
+ enctype: string;
101
+ action: string;
102
+ name?: string;
103
+ rel?: string;
104
+ fields: Record<string, FormField>;
105
+ }
106
+
107
+ /**
108
+ * A field for a feature of the Prismic REST API V2. It contains metadata about
109
+ * the feature's field and how to interact with it via the API.
110
+ *
111
+ * @internal
112
+ */
113
+ export interface FormField {
114
+ type: "String" | "Integer";
115
+ multiple: boolean;
116
+ default?: string;
117
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * List of tags returned from the Prismic Tags API. This data can be fetched by
3
+ * sending a `GET` request to a repository's `/api/tags` endpoint.
4
+ *
5
+ * @typeParam Tag - Tags that are returned by the Tags API.
6
+ * @see More details on the Tags API: {@link https://prismic.io/docs/technologies/tags-api-technical-reference}
7
+ */
8
+ export type Tags<Tag extends string = string> = Tag[];
@@ -1,39 +1,5 @@
1
- import * as prismicT from "@prismicio/types";
2
-
3
- /**
4
- * Create a union of the given object's values, and optionally specify which
5
- * keys to get the values from.
6
- *
7
- * Taken from the `type-fest` package.
8
- *
9
- * See:
10
- * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/value-of.d.ts
11
- */
12
- export type ValueOf<
13
- ObjectType,
14
- ValueType extends keyof ObjectType = keyof ObjectType,
15
- > = ObjectType[ValueType];
16
-
17
- /**
18
- * Functions like TypeScript's native `Extract` utility type with added support
19
- * to fall back to a value if the resulting union is `never`.
20
- *
21
- * @example
22
- *
23
- * ```ts
24
- * ExtractOrFallback<"a" | "b", "a"> // => "a"
25
- * ExtractOrFallback<"a" | "b", "c"> // => "a" | "b"
26
- * ExtractOrFallback<"a" | "b", "c", "foo"> // => "foo"
27
- * ```
28
- *
29
- * @typeParam T - The union from which values will be extracted.
30
- * @typeParam U - The extraction condition.
31
- * @typeParam Fallback - The value to return if the resulting union is `never`.
32
- * Defaults to `T`.
33
- */
34
- type ExtractOrFallback<T, U, Fallback = T> = Extract<T, U> extends never
35
- ? Fallback
36
- : Extract<T, U>;
1
+ import { PrismicDocument } from "./value/document";
2
+ import { ExtractOrFallback } from "./utils";
37
3
 
38
4
  /**
39
5
  * Extracts one or more Prismic document types that match a given Prismic
@@ -44,7 +10,7 @@ type ExtractOrFallback<T, U, Fallback = T> = Extract<T, U> extends never
44
10
  * @typeParam TDocumentType - Type(s) to match `TDocuments` against.
45
11
  */
46
12
  export type ExtractDocumentType<
47
- TDocuments extends prismicT.PrismicDocument,
13
+ TDocuments extends PrismicDocument,
48
14
  TDocumentType extends TDocuments["type"],
49
15
  > = ExtractOrFallback<TDocuments, { type: TDocumentType }>;
50
16
 
@@ -0,0 +1,103 @@
1
+ import {
2
+ RichTextFunctionSerializer,
3
+ RichTextMapSerializer,
4
+ RichTextMapSerializerFunction,
5
+ } from "@prismicio/richtext";
6
+
7
+ import { FilledContentRelationshipField } from "./value/contentRelationship";
8
+
9
+ /**
10
+ * Resolves a link to a Prismic document to a URL
11
+ *
12
+ * @typeParam ReturnType - Return type of your link resolver function, useful if
13
+ * you prefer to return a complex object
14
+ * @param linkToDocumentField - A document link field to resolve
15
+ *
16
+ * @returns Resolved URL
17
+ * @see Prismic link resolver documentation: {@link https://prismic.io/docs/technologies/link-resolver-javascript}
18
+ */
19
+ export type LinkResolverFunction<ReturnType = string> = (
20
+ linkToDocumentField: FilledContentRelationshipField,
21
+ ) => ReturnType;
22
+
23
+ /**
24
+ * Serializes a node from a rich text or title field with a function to HTML
25
+ *
26
+ * Unlike a typical `@prismicio/richtext` function serializer, this serializer
27
+ * converts the `children` argument to a single string rather than an array of
28
+ * strings.
29
+ *
30
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
31
+ */
32
+ export type HTMLFunctionSerializer = (
33
+ type: Parameters<RichTextFunctionSerializer<string>>[0],
34
+ node: Parameters<RichTextFunctionSerializer<string>>[1],
35
+ text: Parameters<RichTextFunctionSerializer<string>>[2],
36
+ children: Parameters<RichTextFunctionSerializer<string>>[3][number],
37
+ key: Parameters<RichTextFunctionSerializer<string>>[4],
38
+ ) => string | null | undefined;
39
+
40
+ /**
41
+ * Serializes a node from a rich text or title field with a map to HTML
42
+ *
43
+ * Unlike a typical `@prismicio/richtext` map serializer, this serializer
44
+ * converts the `children` property to a single string rather than an array of
45
+ * strings.
46
+ *
47
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
48
+ */
49
+ export type HTMLMapSerializer = {
50
+ [P in keyof RichTextMapSerializer<string>]: (payload: {
51
+ type: Parameters<HTMLMapSerializerFunction<P>>[0]["type"];
52
+ node: Parameters<HTMLMapSerializerFunction<P>>[0]["node"];
53
+ text: Parameters<HTMLMapSerializerFunction<P>>[0]["text"];
54
+ children: Parameters<HTMLMapSerializerFunction<P>>[0]["children"][number];
55
+ key: Parameters<HTMLMapSerializerFunction<P>>[0]["key"];
56
+ }) => string | null | undefined;
57
+ };
58
+
59
+ /**
60
+ * A {@link RichTextMapSerializerFunction} type specifically for
61
+ * {@link HTMLMapSerializer}.
62
+ *
63
+ * @typeParam BlockName - The serializer's Rich Text block type.
64
+ */
65
+ type HTMLMapSerializerFunction<
66
+ BlockType extends keyof RichTextMapSerializer<string>,
67
+ > = RichTextMapSerializerFunction<
68
+ string,
69
+ ExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,
70
+ ExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>
71
+ >;
72
+
73
+ /**
74
+ * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.
75
+ *
76
+ * @typeParam T - The `RichTextMapSerializerFunction` containing the needed
77
+ * `Node` generic.
78
+ */
79
+ type ExtractNodeGeneric<T> = T extends RichTextMapSerializerFunction<
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ any,
82
+ infer U,
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ any
85
+ >
86
+ ? U
87
+ : never;
88
+
89
+ /**
90
+ * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.
91
+ *
92
+ * @typeParam T - The `RichTextMapSerializerFunction` containing the needed
93
+ * `TextType` generic.
94
+ */
95
+ type ExtractTextTypeGeneric<T> = T extends RichTextMapSerializerFunction<
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ any,
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ any,
100
+ infer U
101
+ >
102
+ ? U
103
+ : never;
@@ -0,0 +1,16 @@
1
+ import type { CustomTypeModelFieldType } from "./types";
2
+
3
+ /**
4
+ * A Boolean Custom Type field.
5
+ *
6
+ * More details: {@link https://prismic.io/docs/core-concepts/boolean}
7
+ */
8
+ export interface CustomTypeModelBooleanField {
9
+ type: typeof CustomTypeModelFieldType.Boolean;
10
+ config?: {
11
+ label?: string | null;
12
+ default_value?: boolean;
13
+ placeholder_true?: string;
14
+ placeholder_false?: string;
15
+ };
16
+ }
@@ -0,0 +1,14 @@
1
+ import type { CustomTypeModelFieldType } from "./types";
2
+
3
+ /**
4
+ * A Color Custom Type field.
5
+ *
6
+ * More details: {@link https://prismic.io/docs/core-concepts/color}
7
+ */
8
+ export interface CustomTypeModelColorField {
9
+ type: typeof CustomTypeModelFieldType.Color;
10
+ config?: {
11
+ label?: string | null;
12
+ placeholder?: string;
13
+ };
14
+ }
@@ -0,0 +1,22 @@
1
+ import type { CustomTypeModelFieldType } from "./types";
2
+ import type { CustomTypeModelLinkSelectType } from "./link";
3
+
4
+ /**
5
+ * A Content Relationship Custom Type field.
6
+ *
7
+ * More details:
8
+ * {@link https://prismic.io/docs/core-concepts/link-content-relationship}
9
+ */
10
+ export interface CustomTypeModelContentRelationshipField<
11
+ CustomTypeIDs extends string = string,
12
+ Tags extends string = string,
13
+ > {
14
+ type: typeof CustomTypeModelFieldType.Link;
15
+ config?: {
16
+ label?: string | null;
17
+ placeholder?: string;
18
+ select: typeof CustomTypeModelLinkSelectType.Document;
19
+ customtypes?: readonly CustomTypeIDs[];
20
+ tags?: readonly Tags[];
21
+ };
22
+ }
@@ -0,0 +1,61 @@
1
+ import { CustomTypeModelField } from "./types";
2
+
3
+ /**
4
+ * A Prismic Custom Type model.
5
+ *
6
+ * @typeParam ID - API ID of the Custom Type.
7
+ * @typeParam Definition - The Custom Type's tabs and their fields.
8
+ */
9
+ export interface CustomTypeModel<
10
+ ID extends string = string,
11
+ Definition extends CustomTypeModelDefinition = CustomTypeModelDefinition,
12
+ > {
13
+ /**
14
+ * The ID of the Custom Type model.
15
+ */
16
+ id: ID;
17
+
18
+ /**
19
+ * The human readable name of the Custom Type Model.
20
+ */
21
+ // TODO: Revert to `label?: string | null` if `label` can be partial in: https://github.com/prismicio/prismic-types-internal/blob/HEAD/src/customtypes/CustomType.ts#L39
22
+ label: string | null | undefined;
23
+
24
+ /**
25
+ * Determines if more than one document for the Custom Type can be created.
26
+ */
27
+ repeatable: boolean;
28
+
29
+ /**
30
+ * The Custom Type model definition.
31
+ */
32
+ json: Definition;
33
+
34
+ /**
35
+ * Determines if new documents for the Custom Type can be created.
36
+ */
37
+ status: boolean;
38
+ }
39
+
40
+ /**
41
+ * A Prismic Custom Type's tabs and their fields.
42
+ *
43
+ * @typeParam TabName - Names of Custom Type tabs.
44
+ */
45
+ export type CustomTypeModelDefinition<TabName extends string = string> = Record<
46
+ TabName,
47
+ CustomTypeModelTab
48
+ >;
49
+
50
+ /**
51
+ * A Custom Type's tab. Each tab can contain any number of fields but is limited
52
+ * to one Slice Zone.
53
+ *
54
+ * @typeParam FieldName - API IDs of the fields.
55
+ */
56
+ export type CustomTypeModelTab<
57
+ Fields extends Record<string, CustomTypeModelField> = Record<
58
+ string,
59
+ CustomTypeModelField
60
+ >,
61
+ > = Fields;
@@ -0,0 +1,15 @@
1
+ import type { CustomTypeModelFieldType } from "./types";
2
+
3
+ /**
4
+ * A Date Custom Type field.
5
+ *
6
+ * More details: {@link https://prismic.io/docs/core-concepts/date}
7
+ */
8
+ export interface CustomTypeModelDateField {
9
+ type: typeof CustomTypeModelFieldType.Date;
10
+ config?: {
11
+ label?: string | null;
12
+ placeholder?: string;
13
+ default?: string;
14
+ };
15
+ }
@@ -0,0 +1,14 @@
1
+ import type { CustomTypeModelFieldType } from "./types";
2
+
3
+ /**
4
+ * An Embed Custom Type field.
5
+ *
6
+ * More details: {@link https://prismic.io/docs/core-concepts/embed}
7
+ */
8
+ export interface CustomTypeModelEmbedField {
9
+ type: typeof CustomTypeModelFieldType.Embed;
10
+ config?: {
11
+ label?: string | null;
12
+ placeholder?: string;
13
+ };
14
+ }
@@ -0,0 +1,13 @@
1
+ import type { CustomTypeModelFieldType } from "./types";
2
+
3
+ /**
4
+ * A GeoPoint Custom Type field.
5
+ *
6
+ * More details: {@link https://prismic.io/docs/core-concepts/geopoint}
7
+ */
8
+ export interface CustomTypeModelGeoPointField {
9
+ type: typeof CustomTypeModelFieldType.GeoPoint;
10
+ config?: {
11
+ label?: string | null;
12
+ };
13
+ }
@@ -0,0 +1,24 @@
1
+ import type {
2
+ CustomTypeModelFieldType,
3
+ CustomTypeModelFieldForGroup,
4
+ } from "./types";
5
+
6
+ /**
7
+ * A Group Custom Type field.
8
+ *
9
+ * More details: {@link https://prismic.io/docs/core-concepts/group}
10
+ *
11
+ * @typeParam Fields - A record of fields that can be repeated.
12
+ */
13
+ export interface CustomTypeModelGroupField<
14
+ Fields extends Record<string, CustomTypeModelFieldForGroup> = Record<
15
+ string,
16
+ CustomTypeModelFieldForGroup
17
+ >,
18
+ > {
19
+ type: typeof CustomTypeModelFieldType.Group;
20
+ config?: {
21
+ label?: string | null;
22
+ fields?: Fields;
23
+ };
24
+ }