@prismicio/client 7.0.0-alpha.0 → 7.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/README.md +4 -4
  2. package/dist/buildQueryURL.cjs +26 -8
  3. package/dist/buildQueryURL.cjs.map +1 -1
  4. package/dist/buildQueryURL.d.ts +207 -130
  5. package/dist/buildQueryURL.js +25 -7
  6. package/dist/buildQueryURL.js.map +1 -1
  7. package/dist/cookie.cjs +1 -1
  8. package/dist/cookie.cjs.map +1 -1
  9. package/dist/cookie.d.ts +5 -5
  10. package/dist/cookie.js.map +1 -1
  11. package/dist/createClient.cjs +1142 -0
  12. package/dist/createClient.cjs.map +1 -0
  13. package/dist/{client.d.ts → createClient.d.ts} +980 -908
  14. package/dist/createClient.js +1142 -0
  15. package/dist/createClient.js.map +1 -0
  16. package/dist/{ForbiddenError.cjs → errors/ForbiddenError.cjs} +1 -1
  17. package/dist/errors/ForbiddenError.cjs.map +1 -0
  18. package/dist/{ForbiddenError.d.ts → errors/ForbiddenError.d.ts} +11 -11
  19. package/dist/errors/ForbiddenError.js.map +1 -0
  20. package/dist/{NotFoundError.cjs → errors/NotFoundError.cjs} +1 -1
  21. package/dist/errors/NotFoundError.cjs.map +1 -0
  22. package/dist/{NotFoundError.d.ts → errors/NotFoundError.d.ts} +3 -3
  23. package/dist/errors/NotFoundError.js.map +1 -0
  24. package/dist/{ParsingError.cjs → errors/ParsingError.cjs} +1 -1
  25. package/dist/errors/ParsingError.cjs.map +1 -0
  26. package/dist/{ParsingError.d.ts → errors/ParsingError.d.ts} +12 -12
  27. package/dist/errors/ParsingError.js.map +1 -0
  28. package/dist/{PrismicError.cjs → errors/PrismicError.cjs} +1 -1
  29. package/dist/errors/PrismicError.cjs.map +1 -0
  30. package/dist/{PrismicError.d.ts → errors/PrismicError.d.ts} +5 -5
  31. package/dist/errors/PrismicError.js.map +1 -0
  32. package/dist/filter.cjs +247 -0
  33. package/dist/filter.cjs.map +1 -0
  34. package/dist/filter.d.ts +209 -0
  35. package/dist/filter.js +247 -0
  36. package/dist/filter.js.map +1 -0
  37. package/dist/getGraphQLEndpoint.cjs +2 -2
  38. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  39. package/dist/getGraphQLEndpoint.d.ts +9 -9
  40. package/dist/getGraphQLEndpoint.js +1 -1
  41. package/dist/getGraphQLEndpoint.js.map +1 -1
  42. package/dist/getRepositoryEndpoint.cjs +2 -2
  43. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  44. package/dist/getRepositoryEndpoint.d.ts +10 -10
  45. package/dist/getRepositoryEndpoint.js +1 -1
  46. package/dist/getRepositoryEndpoint.js.map +1 -1
  47. package/dist/getRepositoryName.cjs +2 -2
  48. package/dist/getRepositoryName.cjs.map +1 -1
  49. package/dist/getRepositoryName.d.ts +13 -13
  50. package/dist/getRepositoryName.js +1 -1
  51. package/dist/getRepositoryName.js.map +1 -1
  52. package/dist/getToolbarSrc.cjs +13 -0
  53. package/dist/getToolbarSrc.cjs.map +1 -0
  54. package/dist/getToolbarSrc.d.ts +34 -0
  55. package/dist/getToolbarSrc.js +13 -0
  56. package/dist/getToolbarSrc.js.map +1 -0
  57. package/dist/helpers/asDate.cjs +1 -1
  58. package/dist/helpers/asDate.cjs.map +1 -1
  59. package/dist/helpers/asDate.d.ts +16 -16
  60. package/dist/helpers/asDate.js.map +1 -1
  61. package/dist/helpers/asHTML.cjs +7 -6
  62. package/dist/helpers/asHTML.cjs.map +1 -1
  63. package/dist/helpers/asHTML.d.ts +77 -20
  64. package/dist/helpers/asHTML.js +6 -5
  65. package/dist/helpers/asHTML.js.map +1 -1
  66. package/dist/helpers/asImagePixelDensitySrcSet.cjs +1 -1
  67. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  68. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -52
  69. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  70. package/dist/helpers/asImageSrc.cjs +1 -1
  71. package/dist/helpers/asImageSrc.cjs.map +1 -1
  72. package/dist/helpers/asImageSrc.d.ts +27 -27
  73. package/dist/helpers/asImageSrc.js.map +1 -1
  74. package/dist/helpers/asImageWidthSrcSet.cjs +19 -14
  75. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  76. package/dist/helpers/asImageWidthSrcSet.d.ts +60 -60
  77. package/dist/helpers/asImageWidthSrcSet.js +18 -13
  78. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  79. package/dist/helpers/asLink.cjs +8 -2
  80. package/dist/helpers/asLink.cjs.map +1 -1
  81. package/dist/helpers/asLink.d.ts +34 -24
  82. package/dist/helpers/asLink.js +7 -1
  83. package/dist/helpers/asLink.js.map +1 -1
  84. package/dist/helpers/asLinkAttrs.cjs +28 -0
  85. package/dist/helpers/asLinkAttrs.cjs.map +1 -0
  86. package/dist/helpers/asLinkAttrs.d.ts +63 -0
  87. package/dist/helpers/asLinkAttrs.js +28 -0
  88. package/dist/helpers/asLinkAttrs.js.map +1 -0
  89. package/dist/helpers/asText.cjs +1 -1
  90. package/dist/helpers/asText.cjs.map +1 -1
  91. package/dist/helpers/asText.d.ts +16 -16
  92. package/dist/helpers/asText.js.map +1 -1
  93. package/dist/helpers/documentToLinkField.cjs +12 -5
  94. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  95. package/dist/helpers/documentToLinkField.d.ts +15 -15
  96. package/dist/helpers/documentToLinkField.js +11 -4
  97. package/dist/helpers/documentToLinkField.js.map +1 -1
  98. package/dist/helpers/isFilled.cjs +1 -1
  99. package/dist/helpers/isFilled.cjs.map +1 -1
  100. package/dist/helpers/isFilled.d.ts +172 -175
  101. package/dist/helpers/isFilled.js.map +1 -1
  102. package/dist/index.cjs +20 -14
  103. package/dist/index.cjs.map +1 -1
  104. package/dist/index.d.ts +139 -92
  105. package/dist/index.js +12 -6
  106. package/dist/index.js.map +1 -1
  107. package/dist/isRepositoryEndpoint.cjs +1 -1
  108. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  109. package/dist/isRepositoryEndpoint.d.ts +10 -10
  110. package/dist/isRepositoryEndpoint.js.map +1 -1
  111. package/dist/isRepositoryName.cjs +1 -1
  112. package/dist/isRepositoryName.cjs.map +1 -1
  113. package/dist/isRepositoryName.d.ts +9 -9
  114. package/dist/isRepositoryName.js.map +1 -1
  115. package/dist/lib/appendFilters.cjs +11 -0
  116. package/dist/lib/appendFilters.cjs.map +1 -0
  117. package/dist/lib/appendFilters.d.ts +18 -0
  118. package/dist/lib/appendFilters.js +11 -0
  119. package/dist/lib/appendFilters.js.map +1 -0
  120. package/dist/lib/castArray.cjs +4 -2
  121. package/dist/lib/castArray.cjs.map +1 -1
  122. package/dist/lib/castArray.d.ts +11 -11
  123. package/dist/lib/castArray.js +3 -1
  124. package/dist/lib/castArray.js.map +1 -1
  125. package/dist/lib/castThunk.cjs +4 -2
  126. package/dist/lib/castThunk.cjs.map +1 -1
  127. package/dist/lib/castThunk.d.ts +10 -10
  128. package/dist/lib/castThunk.js +3 -1
  129. package/dist/lib/castThunk.js.map +1 -1
  130. package/dist/lib/devMsg.cjs +8 -0
  131. package/dist/lib/devMsg.cjs.map +1 -0
  132. package/dist/lib/devMsg.d.ts +16 -0
  133. package/dist/lib/devMsg.js +8 -0
  134. package/dist/lib/devMsg.js.map +1 -0
  135. package/dist/lib/escapeHTML.cjs +43 -0
  136. package/dist/lib/escapeHTML.cjs.map +1 -0
  137. package/dist/lib/escapeHTML.d.ts +1 -0
  138. package/dist/lib/escapeHTML.js +43 -0
  139. package/dist/lib/escapeHTML.js.map +1 -0
  140. package/dist/lib/everyTagFilter.cjs +9 -0
  141. package/dist/lib/everyTagFilter.cjs.map +1 -0
  142. package/dist/lib/everyTagFilter.d.ts +9 -0
  143. package/dist/lib/everyTagFilter.js +9 -0
  144. package/dist/lib/everyTagFilter.js.map +1 -0
  145. package/dist/lib/findMasterRef.cjs +1 -1
  146. package/dist/lib/findMasterRef.cjs.map +1 -1
  147. package/dist/lib/findMasterRef.d.ts +10 -10
  148. package/dist/lib/findMasterRef.js.map +1 -1
  149. package/dist/lib/findRef.cjs +4 -4
  150. package/dist/lib/findRef.cjs.map +1 -1
  151. package/dist/lib/findRef.d.ts +13 -13
  152. package/dist/lib/findRef.js +3 -3
  153. package/dist/lib/findRef.js.map +1 -1
  154. package/dist/lib/findRefByID.cjs +1 -1
  155. package/dist/lib/findRefByID.cjs.map +1 -1
  156. package/dist/lib/findRefByID.d.ts +11 -11
  157. package/dist/lib/findRefByID.js.map +1 -1
  158. package/dist/lib/findRefByLabel.cjs +1 -1
  159. package/dist/lib/findRefByLabel.cjs.map +1 -1
  160. package/dist/lib/findRefByLabel.d.ts +11 -11
  161. package/dist/lib/findRefByLabel.js.map +1 -1
  162. package/dist/lib/getPreviewCookie.cjs +1 -1
  163. package/dist/lib/getPreviewCookie.cjs.map +1 -1
  164. package/dist/lib/getPreviewCookie.d.ts +9 -9
  165. package/dist/lib/getPreviewCookie.js.map +1 -1
  166. package/dist/lib/isInternalURL.cjs +9 -0
  167. package/dist/lib/isInternalURL.cjs.map +1 -0
  168. package/dist/lib/isInternalURL.d.ts +8 -0
  169. package/dist/lib/isInternalURL.js +9 -0
  170. package/dist/lib/isInternalURL.js.map +1 -0
  171. package/dist/lib/minifyGraphQLQuery.cjs +1 -1
  172. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
  173. package/dist/lib/minifyGraphQLQuery.d.ts +8 -8
  174. package/dist/lib/minifyGraphQLQuery.js.map +1 -1
  175. package/dist/lib/serializerHelpers.cjs +7 -9
  176. package/dist/lib/serializerHelpers.cjs.map +1 -1
  177. package/dist/lib/serializerHelpers.d.ts +9 -9
  178. package/dist/lib/serializerHelpers.js +6 -6
  179. package/dist/lib/serializerHelpers.js.map +1 -1
  180. package/dist/lib/someTagsFilter.cjs +9 -0
  181. package/dist/lib/someTagsFilter.cjs.map +1 -0
  182. package/dist/lib/someTagsFilter.d.ts +9 -0
  183. package/dist/lib/someTagsFilter.js +9 -0
  184. package/dist/lib/someTagsFilter.js.map +1 -0
  185. package/dist/lib/typeFilter.cjs +8 -0
  186. package/dist/lib/typeFilter.cjs.map +1 -0
  187. package/dist/lib/typeFilter.d.ts +8 -0
  188. package/dist/lib/typeFilter.js +8 -0
  189. package/dist/lib/typeFilter.js.map +1 -0
  190. package/dist/package.json.cjs +5 -0
  191. package/dist/package.json.cjs.map +1 -0
  192. package/dist/package.json.js +5 -0
  193. package/dist/package.json.js.map +1 -0
  194. package/dist/types/api/query.d.ts +42 -42
  195. package/dist/types/api/ref.d.ts +32 -32
  196. package/dist/types/api/release.d.ts +10 -10
  197. package/dist/types/api/repository.d.ts +100 -100
  198. package/dist/types/api/tags.d.ts +8 -8
  199. package/dist/types/model/boolean.d.ts +15 -15
  200. package/dist/types/model/color.d.ts +13 -13
  201. package/dist/types/model/contentRelationship.d.ts +18 -18
  202. package/dist/types/model/customType.d.ts +42 -42
  203. package/dist/types/model/date.d.ts +14 -14
  204. package/dist/types/model/embed.d.ts +13 -13
  205. package/dist/types/model/geoPoint.d.ts +12 -12
  206. package/dist/types/model/group.d.ts +15 -15
  207. package/dist/types/model/image.d.ts +31 -31
  208. package/dist/types/model/integrationFields.d.ts +14 -14
  209. package/dist/types/model/keyText.d.ts +13 -13
  210. package/dist/types/model/link.cjs +1 -1
  211. package/dist/types/model/link.cjs.map +1 -1
  212. package/dist/types/model/link.d.ts +27 -27
  213. package/dist/types/model/link.js.map +1 -1
  214. package/dist/types/model/linkToMedia.d.ts +16 -16
  215. package/dist/types/model/number.d.ts +15 -15
  216. package/dist/types/model/range.d.ts +14 -14
  217. package/dist/types/model/richText.d.ts +35 -35
  218. package/dist/types/model/select.d.ts +18 -18
  219. package/dist/types/model/separator.d.ts +10 -10
  220. package/dist/types/model/sharedSlice.d.ts +16 -19
  221. package/dist/types/model/sharedSliceVariation.d.ts +19 -22
  222. package/dist/types/model/slice.cjs +1 -1
  223. package/dist/types/model/slice.cjs.map +1 -1
  224. package/dist/types/model/slice.d.ts +33 -33
  225. package/dist/types/model/slice.js.map +1 -1
  226. package/dist/types/model/sliceZone.cjs +1 -1
  227. package/dist/types/model/sliceZone.cjs.map +1 -1
  228. package/dist/types/model/sliceZone.d.ts +41 -44
  229. package/dist/types/model/sliceZone.js.map +1 -1
  230. package/dist/types/model/timestamp.d.ts +14 -14
  231. package/dist/types/model/title.d.ts +7 -7
  232. package/dist/types/model/types.cjs +10 -1
  233. package/dist/types/model/types.cjs.map +1 -1
  234. package/dist/types/model/types.d.ts +62 -62
  235. package/dist/types/model/types.js +9 -0
  236. package/dist/types/model/types.js.map +1 -1
  237. package/dist/types/model/uid.d.ts +13 -13
  238. package/dist/types/value/boolean.d.ts +6 -6
  239. package/dist/types/value/color.d.ts +8 -8
  240. package/dist/types/value/contentRelationship.d.ts +29 -29
  241. package/dist/types/value/date.d.ts +8 -8
  242. package/dist/types/value/document.d.ts +113 -113
  243. package/dist/types/value/embed.cjs +1 -1
  244. package/dist/types/value/embed.cjs.map +1 -1
  245. package/dist/types/value/embed.d.ts +167 -167
  246. package/dist/types/value/embed.js.map +1 -1
  247. package/dist/types/value/geoPoint.d.ts +11 -11
  248. package/dist/types/value/group.d.ts +7 -7
  249. package/dist/types/value/image.d.ts +36 -36
  250. package/dist/types/value/integrationFields.d.ts +9 -9
  251. package/dist/types/value/keyText.d.ts +8 -8
  252. package/dist/types/value/link.cjs +1 -1
  253. package/dist/types/value/link.cjs.map +1 -1
  254. package/dist/types/value/link.d.ts +40 -40
  255. package/dist/types/value/link.js.map +1 -1
  256. package/dist/types/value/linkToMedia.d.ts +20 -20
  257. package/dist/types/value/number.d.ts +8 -8
  258. package/dist/types/value/richText.cjs +1 -1
  259. package/dist/types/value/richText.cjs.map +1 -1
  260. package/dist/types/value/richText.d.ts +203 -203
  261. package/dist/types/value/richText.js.map +1 -1
  262. package/dist/types/value/select.d.ts +9 -9
  263. package/dist/types/value/sharedSlice.d.ts +11 -11
  264. package/dist/types/value/sharedSliceVariation.d.ts +7 -7
  265. package/dist/types/value/slice.d.ts +13 -13
  266. package/dist/types/value/sliceZone.d.ts +12 -12
  267. package/dist/types/value/timestamp.d.ts +8 -8
  268. package/dist/types/value/title.d.ts +12 -12
  269. package/dist/types/value/types.d.ts +40 -40
  270. package/dist/types/webhook/apiUpdate.d.ts +52 -52
  271. package/dist/types/webhook/testTrigger.d.ts +9 -9
  272. package/dist/types/webhook/types.cjs +1 -1
  273. package/dist/types/webhook/types.cjs.map +1 -1
  274. package/dist/types/webhook/types.d.ts +18 -18
  275. package/dist/types/webhook/types.js.map +1 -1
  276. package/package.json +23 -24
  277. package/src/buildQueryURL.ts +179 -33
  278. package/src/{client.ts → createClient.ts} +214 -110
  279. package/src/filter.ts +356 -0
  280. package/src/getGraphQLEndpoint.ts +2 -1
  281. package/src/getRepositoryEndpoint.ts +2 -1
  282. package/src/getRepositoryName.ts +1 -1
  283. package/src/getToolbarSrc.ts +50 -0
  284. package/src/helpers/asDate.ts +3 -3
  285. package/src/helpers/asHTML.ts +122 -27
  286. package/src/helpers/asImagePixelDensitySrcSet.ts +1 -1
  287. package/src/helpers/asImageSrc.ts +1 -1
  288. package/src/helpers/asImageWidthSrcSet.ts +1 -1
  289. package/src/helpers/asLink.ts +37 -18
  290. package/src/helpers/asLinkAttrs.ts +127 -0
  291. package/src/helpers/asText.ts +4 -4
  292. package/src/helpers/documentToLinkField.ts +3 -3
  293. package/src/helpers/isFilled.ts +9 -11
  294. package/src/index.ts +60 -29
  295. package/src/lib/appendFilters.ts +26 -0
  296. package/src/lib/castArray.ts +3 -1
  297. package/src/lib/castThunk.ts +3 -2
  298. package/src/lib/devMsg.ts +20 -0
  299. package/src/lib/escapeHTML.ts +51 -0
  300. package/src/lib/everyTagFilter.ts +15 -0
  301. package/src/lib/findRef.ts +5 -5
  302. package/src/lib/isInternalURL.ts +14 -0
  303. package/src/lib/serializerHelpers.ts +20 -15
  304. package/src/lib/someTagsFilter.ts +15 -0
  305. package/src/lib/typeFilter.ts +12 -0
  306. package/src/types/api/query.ts +1 -1
  307. package/src/types/api/ref.ts +2 -2
  308. package/src/types/api/release.ts +1 -1
  309. package/src/types/api/repository.ts +1 -1
  310. package/src/types/api/tags.ts +1 -1
  311. package/src/types/model/boolean.ts +1 -1
  312. package/src/types/model/color.ts +1 -1
  313. package/src/types/model/contentRelationship.ts +2 -1
  314. package/src/types/model/date.ts +1 -1
  315. package/src/types/model/embed.ts +1 -1
  316. package/src/types/model/geoPoint.ts +1 -1
  317. package/src/types/model/group.ts +2 -2
  318. package/src/types/model/image.ts +3 -3
  319. package/src/types/model/integrationFields.ts +1 -1
  320. package/src/types/model/keyText.ts +1 -1
  321. package/src/types/model/link.ts +3 -3
  322. package/src/types/model/linkToMedia.ts +2 -1
  323. package/src/types/model/number.ts +1 -1
  324. package/src/types/model/richText.ts +3 -3
  325. package/src/types/model/select.ts +1 -1
  326. package/src/types/model/sharedSlice.ts +2 -5
  327. package/src/types/model/sharedSliceVariation.ts +1 -4
  328. package/src/types/model/slice.ts +5 -4
  329. package/src/types/model/sliceZone.ts +5 -7
  330. package/src/types/model/timestamp.ts +1 -1
  331. package/src/types/model/title.ts +1 -1
  332. package/src/types/model/types.ts +12 -16
  333. package/src/types/model/uid.ts +1 -1
  334. package/src/types/value/boolean.ts +1 -1
  335. package/src/types/value/color.ts +1 -1
  336. package/src/types/value/contentRelationship.ts +8 -9
  337. package/src/types/value/date.ts +1 -1
  338. package/src/types/value/document.ts +6 -5
  339. package/src/types/value/embed.ts +2 -2
  340. package/src/types/value/geoPoint.ts +1 -1
  341. package/src/types/value/group.ts +2 -2
  342. package/src/types/value/image.ts +1 -1
  343. package/src/types/value/integrationFields.ts +1 -1
  344. package/src/types/value/keyText.ts +1 -1
  345. package/src/types/value/link.ts +8 -8
  346. package/src/types/value/linkToMedia.ts +2 -1
  347. package/src/types/value/number.ts +1 -1
  348. package/src/types/value/richText.ts +6 -5
  349. package/src/types/value/select.ts +1 -1
  350. package/src/types/value/sharedSlice.ts +1 -1
  351. package/src/types/value/slice.ts +1 -1
  352. package/src/types/value/sliceZone.ts +2 -1
  353. package/src/types/value/timestamp.ts +1 -0
  354. package/src/types/value/title.ts +2 -1
  355. package/src/types/value/types.ts +9 -11
  356. package/src/types/webhook/apiUpdate.ts +4 -4
  357. package/src/types/webhook/testTrigger.ts +1 -1
  358. package/src/types/webhook/types.ts +2 -2
  359. package/dist/ForbiddenError.cjs.map +0 -1
  360. package/dist/ForbiddenError.js.map +0 -1
  361. package/dist/NotFoundError.cjs.map +0 -1
  362. package/dist/NotFoundError.js.map +0 -1
  363. package/dist/ParsingError.cjs.map +0 -1
  364. package/dist/ParsingError.js.map +0 -1
  365. package/dist/PrismicError.cjs.map +0 -1
  366. package/dist/PrismicError.js.map +0 -1
  367. package/dist/client.cjs +0 -414
  368. package/dist/client.cjs.map +0 -1
  369. package/dist/client.js +0 -414
  370. package/dist/client.js.map +0 -1
  371. package/dist/lib/appendPredicates.cjs +0 -14
  372. package/dist/lib/appendPredicates.cjs.map +0 -1
  373. package/dist/lib/appendPredicates.d.ts +0 -18
  374. package/dist/lib/appendPredicates.js +0 -14
  375. package/dist/lib/appendPredicates.js.map +0 -1
  376. package/dist/predicate.cjs +0 -68
  377. package/dist/predicate.cjs.map +0 -1
  378. package/dist/predicate.d.ts +0 -209
  379. package/dist/predicate.js +0 -68
  380. package/dist/predicate.js.map +0 -1
  381. package/dist/types/client.d.ts +0 -128
  382. package/dist/types/helpers.d.ts +0 -63
  383. package/dist/types/utils.d.ts +0 -28
  384. package/src/lib/appendPredicates.ts +0 -29
  385. package/src/predicate.ts +0 -359
  386. package/src/types/client.ts +0 -157
  387. package/src/types/helpers.ts +0 -103
  388. package/src/types/utils.ts +0 -34
  389. /package/dist/{ForbiddenError.js → errors/ForbiddenError.js} +0 -0
  390. /package/dist/{NotFoundError.js → errors/NotFoundError.js} +0 -0
  391. /package/dist/{ParsingError.js → errors/ParsingError.js} +0 -0
  392. /package/dist/{PrismicError.js → errors/PrismicError.js} +0 -0
  393. /package/src/{ForbiddenError.ts → errors/ForbiddenError.ts} +0 -0
  394. /package/src/{NotFoundError.ts → errors/NotFoundError.ts} +0 -0
  395. /package/src/{ParsingError.ts → errors/ParsingError.ts} +0 -0
  396. /package/src/{PrismicError.ts → errors/PrismicError.ts} +0 -0
@@ -1,16 +1,29 @@
1
+ import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
1
2
  import type { PrismicDocument } from "../types/value/document";
2
3
  import { FilledLinkToWebField, LinkField, LinkType } from "../types/value/link";
3
4
  import type { FilledLinkToMediaField } from "../types/value/linkToMedia";
4
- import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
5
- import type { LinkResolverFunction } from "../types/helpers";
6
5
 
7
6
  import { documentToLinkField } from "./documentToLinkField";
8
7
 
8
+ /**
9
+ * Resolves a Link to a Prismic document to a URL
10
+ *
11
+ * @typeParam ReturnType - Return type of your link resolver function, useful if
12
+ * you prefer to return a complex object
13
+ * @param linkToDocumentField - A document Link Field to resolve
14
+ *
15
+ * @returns Resolved URL
16
+ * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
17
+ */
18
+ export type LinkResolverFunction<ReturnType = string | null | undefined> = (
19
+ linkToDocumentField: FilledContentRelationshipField,
20
+ ) => ReturnType;
21
+
9
22
  /**
10
23
  * The return type of `asLink()`.
11
24
  */
12
- type AsLinkReturnType<
13
- LinkResolverFunctionReturnType = string,
25
+ export type AsLinkReturnType<
26
+ LinkResolverFunctionReturnType = string | null | undefined,
14
27
  Field extends LinkField | PrismicDocument | null | undefined =
15
28
  | LinkField
16
29
  | PrismicDocument
@@ -25,20 +38,21 @@ type AsLinkReturnType<
25
38
  : null;
26
39
 
27
40
  /**
28
- * Resolves any type of link field or document to a URL
41
+ * Resolves any type of Link field or Prismic document to a URL.
29
42
  *
30
- * @typeParam LinkResolverFunctionReturnType - Link resolver function return
43
+ * @typeParam LinkResolverFunctionReturnType - Link Resolver function return
31
44
  * type
32
- * @param linkFieldOrDocument - Any kind of link field or a document to resolve
33
- * @param linkResolver - An optional link resolver function, without it you're
45
+ * @typeParam Field - Link field or Prismic document to resolve to a URL
46
+ * @param linkFieldOrDocument - Any kind of Link field or a document to resolve
47
+ * @param linkResolver - An optional Link Resolver function. Without it, you are
34
48
  * expected to use the `routes` options from the API
35
49
  *
36
- * @returns Resolved URL, null if provided link is empty
37
- * @see Prismic link resolver documentation: {@link https://prismic.io/docs/technologies/link-resolver-javascript}
38
- * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/technologies/route-resolver-nuxtjs}
50
+ * @returns Resolved URL or, if the provided Link field or document is empty, `null`
51
+ * @see Prismic Link Resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
52
+ * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
39
53
  */
40
54
  export const asLink = <
41
- LinkResolverFunctionReturnType = string,
55
+ LinkResolverFunctionReturnType = string | null | undefined,
42
56
  Field extends LinkField | PrismicDocument | null | undefined =
43
57
  | LinkField
44
58
  | PrismicDocument
@@ -52,12 +66,17 @@ export const asLink = <
52
66
  return null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>;
53
67
  }
54
68
 
55
- // Converts document to link field if needed
56
- const linkField = (
57
- "link_type" in linkFieldOrDocument
58
- ? linkFieldOrDocument
59
- : documentToLinkField(linkFieldOrDocument)
60
- ) as LinkField;
69
+ // Converts document to Link Field if needed
70
+ const linkField =
71
+ // prettier-ignore
72
+ (
73
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
74
+ // @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
75
+ // TODO: Remove the `prettier-ignore` comment when this bug is fixed.
76
+ "link_type" in linkFieldOrDocument
77
+ ? linkFieldOrDocument
78
+ : documentToLinkField(linkFieldOrDocument)
79
+ ) as LinkField;
61
80
 
62
81
  switch (linkField.link_type) {
63
82
  case LinkType.Media:
@@ -0,0 +1,127 @@
1
+ import { isInternalURL } from "../lib/isInternalURL";
2
+
3
+ import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
4
+ import type { PrismicDocument } from "../types/value/document";
5
+ import { FilledLinkToWebField, LinkField } from "../types/value/link";
6
+ import type { FilledLinkToMediaField } from "../types/value/linkToMedia";
7
+
8
+ import { AsLinkReturnType, LinkResolverFunction, asLink } from "./asLink";
9
+ import { link as isFilledLink } from "./isFilled";
10
+
11
+ type AsLinkAttrsConfigRelArgs<
12
+ LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
13
+ Field extends LinkField | PrismicDocument | null | undefined =
14
+ | LinkField
15
+ | PrismicDocument
16
+ | null
17
+ | undefined,
18
+ > = {
19
+ href:
20
+ | NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>
21
+ | undefined;
22
+ isExternal: boolean;
23
+ target?: string;
24
+ };
25
+
26
+ export type AsLinkAttrsConfig<
27
+ LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
28
+ Field extends LinkField | PrismicDocument | null | undefined =
29
+ | LinkField
30
+ | PrismicDocument
31
+ | null
32
+ | undefined,
33
+ > = {
34
+ linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType>;
35
+ rel?: (
36
+ args: AsLinkAttrsConfigRelArgs<LinkResolverFunctionReturnType, Field>,
37
+ ) => string | undefined | void;
38
+ };
39
+
40
+ /**
41
+ * The return type of `asLinkAttrs()`.
42
+ */
43
+ type AsLinkAttrsReturnType<
44
+ LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
45
+ Field extends LinkField | PrismicDocument | null | undefined =
46
+ | LinkField
47
+ | PrismicDocument
48
+ | null
49
+ | undefined,
50
+ > = Field extends
51
+ | FilledLinkToWebField
52
+ | FilledLinkToMediaField
53
+ | FilledContentRelationshipField
54
+ | PrismicDocument
55
+ ? {
56
+ href:
57
+ | NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>
58
+ | undefined;
59
+ target?: string;
60
+ rel?: string;
61
+ }
62
+ : {
63
+ href?: undefined;
64
+ target?: undefined;
65
+ rel?: undefined;
66
+ };
67
+
68
+ /**
69
+ * Resolves any type of Link field or Prismic document to a set of link attributes. The attributes are designed to be passed to link HTML elements, like `<a>`.
70
+ *
71
+ * If a resolved URL is external (i.e. starts with a protocol like `https://`), `rel` is returned as `"noreferrer"`.
72
+ *
73
+ * @typeParam LinkResolverFunctionReturnType - Link Resolver function return
74
+ * type
75
+ * @typeParam Field - Link field or Prismic document to resolve to link attributes
76
+ * @param linkFieldOrDocument - Any kind of Link field or a document to resolve
77
+ * @param config - Configuration that determines the output of `asLinkAttrs()`
78
+ *
79
+ * @returns Resolved set of link attributes or, if the provided Link field or document is empty, and empty object
80
+ * @see Prismic Link Resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
81
+ * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
82
+ */
83
+ export const asLinkAttrs = <
84
+ LinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,
85
+ Field extends LinkField | PrismicDocument | null | undefined =
86
+ | LinkField
87
+ | PrismicDocument
88
+ | null
89
+ | undefined,
90
+ >(
91
+ linkFieldOrDocument: Field,
92
+ config: AsLinkAttrsConfig<LinkResolverFunctionReturnType> = {},
93
+ ): AsLinkAttrsReturnType<LinkResolverFunctionReturnType> => {
94
+ if (
95
+ linkFieldOrDocument &&
96
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
97
+ // @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
98
+ ("link_type" in linkFieldOrDocument
99
+ ? isFilledLink(linkFieldOrDocument)
100
+ : linkFieldOrDocument)
101
+ ) {
102
+ const target =
103
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
104
+ // @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501
105
+ "target" in linkFieldOrDocument ? linkFieldOrDocument.target : undefined;
106
+
107
+ const rawHref = asLink(linkFieldOrDocument, config.linkResolver);
108
+ const href =
109
+ rawHref == null ? undefined : (rawHref as NonNullable<typeof rawHref>);
110
+
111
+ const isExternal = typeof href === "string" ? !isInternalURL(href) : false;
112
+
113
+ const rel = config.rel
114
+ ? config.rel({ href, isExternal, target })
115
+ : isExternal
116
+ ? "noreferrer"
117
+ : undefined;
118
+
119
+ return {
120
+ href,
121
+ target,
122
+ rel: rel == null ? undefined : rel,
123
+ };
124
+ }
125
+
126
+ return {};
127
+ };
@@ -9,13 +9,13 @@ type AsTextReturnType<Field extends RichTextField | null | undefined> =
9
9
  Field extends RichTextField ? string : null;
10
10
 
11
11
  /**
12
- * Serializes a rich text or title field to a plain text string
12
+ * Serializes a Rich Text or Title field to a plain text string
13
13
  *
14
- * @param richTextField - A rich text or title field from Prismic
14
+ * @param richTextField - A Rich Text or Title field from Prismic
15
15
  * @param separator - Separator used to join each element, defaults to a space
16
16
  *
17
- * @returns Plain text equivalent of the provided rich text or title field
18
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
17
+ * @returns Plain text equivalent of the provided Rich Text or Title field
18
+ * @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
19
19
  */
20
20
  export const asText = <Field extends RichTextField | null | undefined>(
21
21
  richTextField: Field,
@@ -1,6 +1,6 @@
1
+ import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
1
2
  import type { PrismicDocument } from "../types/value/document";
2
3
  import { LinkType } from "../types/value/link";
3
- import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
4
4
 
5
5
  type SetOptional<T, Keys extends keyof T> = Omit<T, Keys> &
6
6
  Partial<Pick<T, Keys>>;
@@ -27,11 +27,11 @@ export const documentToLinkField = <
27
27
  return {
28
28
  link_type: LinkType.Document,
29
29
  id: prismicDocument.id,
30
- uid: prismicDocument.uid ?? undefined,
30
+ uid: prismicDocument.uid || undefined,
31
31
  type: prismicDocument.type,
32
32
  tags: prismicDocument.tags,
33
33
  lang: prismicDocument.lang,
34
- url: prismicDocument.url ?? undefined,
34
+ url: prismicDocument.url == null ? undefined : prismicDocument.url,
35
35
  slug: prismicDocument.slugs?.[0], // Slug field is not available with GraphQl
36
36
  // The REST API does not include a `data` property if the data
37
37
  // object is empty.
@@ -1,14 +1,14 @@
1
1
  import type { ColorField } from "../types/value/color";
2
+ import type { ContentRelationshipField } from "../types/value/contentRelationship";
2
3
  import type { DateField } from "../types/value/date";
3
- import type { EmbedField, AnyOEmbed } from "../types/value/embed";
4
+ import type { AnyOEmbed, EmbedField } from "../types/value/embed";
4
5
  import type { GeoPointField } from "../types/value/geoPoint";
5
6
  import type { GroupField } from "../types/value/group";
6
- import type { ImageFieldImage, ImageField } from "../types/value/image";
7
+ import type { ImageField, ImageFieldImage } from "../types/value/image";
7
8
  import type { IntegrationFields } from "../types/value/integrationFields";
8
9
  import type { KeyTextField } from "../types/value/keyText";
9
10
  import type { LinkField } from "../types/value/link";
10
11
  import type { LinkToMediaField } from "../types/value/linkToMedia";
11
- import type { ContentRelationshipField } from "../types/value/contentRelationship";
12
12
  import type { NumberField } from "../types/value/number";
13
13
  import type { RichTextField } from "../types/value/richText";
14
14
  import type { SelectField } from "../types/value/select";
@@ -109,10 +109,9 @@ export const image = imageThumbnail as <
109
109
  export const link = <
110
110
  TypeEnum = string,
111
111
  LangEnum = string,
112
- DataInterface extends Record<
113
- string,
114
- AnyRegularField | GroupField | SliceZone
115
- > = never,
112
+ DataInterface extends
113
+ | Record<string, AnyRegularField | GroupField | SliceZone>
114
+ | unknown = unknown,
116
115
  >(
117
116
  field: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined,
118
117
  ): field is LinkField<TypeEnum, LangEnum, DataInterface, "filled"> => {
@@ -140,10 +139,9 @@ export const linkToMedia = link as (
140
139
  export const contentRelationship = link as <
141
140
  TypeEnum = string,
142
141
  LangEnum = string,
143
- DataInterface extends Record<
144
- string,
145
- AnyRegularField | GroupField | SliceZone
146
- > = never,
142
+ DataInterface extends
143
+ | Record<string, AnyRegularField | GroupField | SliceZone>
144
+ | unknown = unknown,
147
145
  >(
148
146
  field:
149
147
  | ContentRelationshipField<TypeEnum, LangEnum, DataInterface>
package/src/index.ts CHANGED
@@ -1,48 +1,65 @@
1
+ // Use for deprecations.
2
+ import type {
3
+ HTMLRichTextFunctionSerializer,
4
+ HTMLRichTextMapSerializer,
5
+ } from "./helpers/asHTML";
6
+
7
+ import { filter } from "./filter";
8
+
1
9
  //=============================================================================
2
- // Client - Everything you need to query data from Prismic.
10
+ // Client - Query content from Prismic.
3
11
  //=============================================================================
4
12
 
5
13
  // Primary Client API.
14
+ export { createClient, Client } from "./createClient";
15
+
16
+ // API endpoint helpers.
6
17
  export { getRepositoryEndpoint } from "./getRepositoryEndpoint";
7
18
  export { getRepositoryName } from "./getRepositoryName";
8
19
  export { getGraphQLEndpoint } from "./getGraphQLEndpoint";
9
20
  export { isRepositoryName } from "./isRepositoryName";
10
21
  export { isRepositoryEndpoint } from "./isRepositoryEndpoint";
11
22
  export { buildQueryURL } from "./buildQueryURL";
12
- export { createClient, Client } from "./client";
13
23
 
14
- // Predicates API.
15
- export { predicate } from "./predicate";
24
+ // Toolbar helpers.
25
+ export { getToolbarSrc } from "./getToolbarSrc";
16
26
 
17
- // Custom errors used by Client.
18
- export { PrismicError } from "./PrismicError";
19
- export { ForbiddenError } from "./ForbiddenError";
20
- export { ParsingError } from "./ParsingError";
21
- export { NotFoundError } from "./NotFoundError";
27
+ // Query filters API.
28
+ /**
29
+ * @deprecated Renamed to `filter`
30
+ */
31
+ // TODO: Remove when we remove support for deprecated `predicate` export.
32
+ const predicate = filter;
33
+ export { filter, predicate };
22
34
 
23
35
  // A collection of well-known cookie names shared between Prismic libraries and systems.
24
36
  export * as cookie from "./cookie";
25
37
 
26
- // General types used throughout the project. These are made public to allow users to better type their projects.
27
- export type { CreateClient, ClientConfig } from "./client";
28
- export type { QueryParams, BuildQueryURLArgs } from "./buildQueryURL";
38
+ // General types used to query content from Prismic. These are made public to allow users to better type their projects.
29
39
  export type {
30
40
  AbortSignalLike,
41
+ ClientConfig,
42
+ CreateClient,
31
43
  FetchLike,
32
44
  HttpRequestLike,
33
- Ordering,
34
45
  RequestInitLike,
35
46
  ResponseLike,
47
+ } from "./createClient";
48
+ export type {
49
+ BuildQueryURLArgs,
50
+ Ordering,
51
+ QueryParams,
36
52
  Route,
37
- } from "./types/client";
53
+ } from "./buildQueryURL";
38
54
 
39
55
  //=============================================================================
40
- // Helpers - Everything you need to template Prismic data.
56
+ // Helpers - Manipulate content from Prismic.
41
57
  //=============================================================================
42
58
 
43
59
  // Primary Helpers API.
44
60
  export { asDate } from "./helpers/asDate";
45
61
  export { asLink } from "./helpers/asLink";
62
+ export { asLinkAttrs } from "./helpers/asLinkAttrs";
46
63
  export { asText } from "./helpers/asText";
47
64
  export { asHTML } from "./helpers/asHTML";
48
65
  export { asImageSrc } from "./helpers/asImageSrc";
@@ -56,16 +73,39 @@ export { documentToLinkField } from "./helpers/documentToLinkField";
56
73
  // RichText element types.
57
74
  export { Element } from "@prismicio/richtext";
58
75
 
76
+ export type { LinkResolverFunction } from "./helpers/asLink";
77
+ export type { AsLinkAttrsConfig } from "./helpers/asLinkAttrs";
78
+
79
+ /**
80
+ * @deprecated Renamed to `HTMLRichTextMapSerializer`
81
+ */
82
+ type HTMLMapSerializer = HTMLRichTextMapSerializer;
83
+ /**
84
+ * @deprecated Renamed to `HTMLRichTextFunctionSerializer`
85
+ */
86
+ type HTMLFunctionSerializer = HTMLRichTextFunctionSerializer;
59
87
  export type {
60
- LinkResolverFunction,
61
- HTMLFunctionSerializer,
88
+ HTMLRichTextMapSerializer,
89
+ HTMLRichTextFunctionSerializer,
62
90
  HTMLMapSerializer,
63
- } from "./types/helpers";
91
+ HTMLFunctionSerializer,
92
+ };
93
+ export type { HTMLRichTextSerializer } from "./helpers/asHTML";
64
94
 
65
95
  //=============================================================================
66
- // Value - Types representing Prismic document and field values.
96
+ // Errors - Custom errors for Prismic APIs.
67
97
  //=============================================================================
68
98
 
99
+ export { PrismicError } from "./errors/PrismicError";
100
+ export { ForbiddenError } from "./errors/ForbiddenError";
101
+ export { NotFoundError } from "./errors/NotFoundError";
102
+ export { ParsingError } from "./errors/ParsingError";
103
+
104
+ //=============================================================================
105
+ // Types - Types representing Prismic content, models, and API payloads.
106
+ //=============================================================================
107
+
108
+ // Values - Types representing Prismic content.
69
109
  export { RichTextNodeType } from "./types/value/richText";
70
110
  export { LinkType } from "./types/value/link";
71
111
  export { OEmbedType } from "./types/value/embed";
@@ -167,10 +207,7 @@ export type { SharedSliceVariation } from "./types/value/sharedSliceVariation";
167
207
 
168
208
  export type { FieldState, AnyRegularField } from "./types/value/types";
169
209
 
170
- //=============================================================================
171
- // Model - Types representing Prismic Custom Type and Shared Slice models.
172
- //=============================================================================
173
-
210
+ // Models - Types representing Prismic content models.
174
211
  export { CustomTypeModelFieldType } from "./types/model/types";
175
212
  export { CustomTypeModelLinkSelectType } from "./types/model/link";
176
213
  export { CustomTypeModelSliceType } from "./types/model/sliceZone";
@@ -234,10 +271,7 @@ export type {
234
271
  CustomTypeModelFieldForGroup,
235
272
  } from "./types/model/types";
236
273
 
237
- //=============================================================================
238
274
  // API - Types representing Prismic Rest API V2 responses.
239
- //=============================================================================
240
-
241
275
  export type { Query } from "./types/api/query";
242
276
 
243
277
  export type { Ref } from "./types/api/ref";
@@ -253,10 +287,7 @@ export type {
253
287
 
254
288
  export type { Tags } from "./types/api/tags";
255
289
 
256
- //=============================================================================
257
290
  // Webhook - Types representing Prismic webhooks.
258
- //=============================================================================
259
-
260
291
  export { WebhookType } from "./types/webhook/types";
261
292
 
262
293
  export type { WebhookBody } from "./types/webhook/types";
@@ -0,0 +1,26 @@
1
+ import { castArray } from "./castArray";
2
+
3
+ interface WithFilters {
4
+ filters?: string | string[];
5
+ }
6
+
7
+ /**
8
+ * Adds one or more filters to an object with a `filters` property.
9
+ * Appended filters are added to the end of the existing list.
10
+ *
11
+ * @typeParam T - Object to which filters will be append.
12
+ * @param objWithFilters - Object to append filters on the `filters`
13
+ * property.
14
+ * @param filters - One or more filters to append.
15
+ *
16
+ * @returns The object with the appended filters.
17
+ */
18
+ export const appendFilters = <T extends WithFilters>(
19
+ objWithFilters: T = {} as T,
20
+ filters: string | string[],
21
+ ): T & { filters: string[] } => {
22
+ return {
23
+ ...objWithFilters,
24
+ filters: [...(objWithFilters.filters || []), ...castArray(filters)],
25
+ };
26
+ };
@@ -8,4 +8,6 @@
8
8
  *
9
9
  * @returns `a` as an array.
10
10
  */
11
- export const castArray = <A>(a: A | A[]): A[] => (Array.isArray(a) ? a : [a]);
11
+ export const castArray = <A>(a: A | A[]): A[] => {
12
+ return Array.isArray(a) ? a : [a];
13
+ };
@@ -7,5 +7,6 @@
7
7
  *
8
8
  * @returns `a` as a a thunk.
9
9
  */
10
- export const castThunk = <A>(a: A | (() => A)): (() => A) =>
11
- typeof a === "function" ? (a as () => A) : () => a;
10
+ export const castThunk = <A>(a: A | (() => A)): (() => A) => {
11
+ return typeof a === "function" ? (a as () => A) : () => a;
12
+ };
@@ -0,0 +1,20 @@
1
+ import { version } from "../../package.json";
2
+
3
+ /**
4
+ * Returns a `prismic.dev/msg` URL for a given message slug.
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * devMsg("missing-param");
10
+ * // => "https://prismic.dev/msg/client/v1.2.3/missing-param.md"
11
+ * ```
12
+ *
13
+ * @param slug - Slug for the message. This corresponds to a Markdown file in
14
+ * the Git repository's `/messages` directory.
15
+ *
16
+ * @returns The `prismic.dev/msg` URL for the given slug.
17
+ */
18
+ export const devMsg = (slug: string): string => {
19
+ return `https://prismic.dev/msg/client/v${version}/${slug}`;
20
+ };
@@ -0,0 +1,51 @@
1
+ /*
2
+ ** Core logic from https://github.com/component/escape-html
3
+ ** Many thanks to @component
4
+ */
5
+
6
+ const matchHtmlRegExp = /["'&<>]/;
7
+
8
+ export const escapeHTML = (string?: string | null): string => {
9
+ const str = "" + string;
10
+ const match = matchHtmlRegExp.exec(str);
11
+
12
+ if (!match) {
13
+ return str;
14
+ }
15
+
16
+ let escape;
17
+ let html = "";
18
+ let index = 0;
19
+ let lastIndex = 0;
20
+
21
+ for (index = match.index; index < str.length; index++) {
22
+ switch (str.charCodeAt(index)) {
23
+ case 34: // "
24
+ escape = "&quot;";
25
+ break;
26
+ case 38: // &
27
+ escape = "&amp;";
28
+ break;
29
+ case 39: // '
30
+ escape = "&#39;";
31
+ break;
32
+ case 60: // <
33
+ escape = "&lt;";
34
+ break;
35
+ case 62: // >
36
+ escape = "&gt;";
37
+ break;
38
+ default:
39
+ continue;
40
+ }
41
+
42
+ if (lastIndex !== index) {
43
+ html += str.substring(lastIndex, index);
44
+ }
45
+
46
+ lastIndex = index + 1;
47
+ html += escape;
48
+ }
49
+
50
+ return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
51
+ };
@@ -0,0 +1,15 @@
1
+ import { filter } from "../filter";
2
+
3
+ import { castArray } from "./castArray";
4
+
5
+ /**
6
+ * Creates a filter to filter content by document tags. All tags are required
7
+ * on the document.
8
+ *
9
+ * @param tags - Document tags to filter queried content.
10
+ *
11
+ * @returns A filter that can be used in a Prismic REST API V2 request.
12
+ */
13
+ export const everyTagFilter = (tags: string | string[]): string => {
14
+ return filter.at("document.tags", castArray(tags));
15
+ };
@@ -1,20 +1,20 @@
1
1
  import { Ref } from "../types/api/ref";
2
2
 
3
- import { PrismicError } from "../PrismicError";
3
+ import { PrismicError } from "../errors/PrismicError";
4
4
 
5
5
  /**
6
- * Returns the first ref from a list that passes a predicate (a function that
6
+ * Returns the first ref from a list that passes a filter (a function that
7
7
  * returns true).
8
8
  *
9
9
  * @param refs - A list of refs to search.
10
- * @param predicate - A function that determines if a ref from the list matches
10
+ * @param filter - A function that determines if a ref from the list matches
11
11
  * the criteria.
12
12
  *
13
13
  * @returns The first matching ref.
14
14
  * @throws If a matching ref cannot be found.
15
15
  */
16
- export const findRef = (refs: Ref[], predicate: (ref: Ref) => boolean): Ref => {
17
- const ref = refs.find((ref) => predicate(ref));
16
+ export const findRef = (refs: Ref[], filter: (ref: Ref) => boolean): Ref => {
17
+ const ref = refs.find((ref) => filter(ref));
18
18
 
19
19
  if (!ref) {
20
20
  throw new PrismicError("Ref could not be found.", undefined, undefined);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Determines if a URL is internal or external.
3
+ *
4
+ * @param url - The URL to check if internal or external.
5
+ *
6
+ * @returns `true` if `url` is internal, `false` otherwise.
7
+ */
8
+ // TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a "/" or "#"`.
9
+ export const isInternalURL = (url: string): boolean => {
10
+ const isInternal = /^(\/(?!\/)|#)/.test(url);
11
+ const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
12
+
13
+ return isInternal && !isSpecialLink;
14
+ };