@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,29 +0,0 @@
1
- import { castArray } from "./castArray";
2
-
3
- interface WithPredicates {
4
- predicates?: string | string[];
5
- }
6
-
7
- /**
8
- * Adds one or more predicates to an object with a `predicates` property.
9
- * Appended predicates are added to the end of the existing list.
10
- *
11
- * @typeParam T - Object to which predicates will be append.
12
- * @param objWithPredicates - Object to append predicates on the `predicates`
13
- * property.
14
- * @param predicates - One or more predicates to append.
15
- *
16
- * @returns The object with the appended predicates.
17
- */
18
- export const appendPredicates = <T extends WithPredicates>(
19
- objWithPredicates: T = {} as T,
20
- predicates: string | string[],
21
- ) => {
22
- return {
23
- ...objWithPredicates,
24
- predicates: [
25
- ...(objWithPredicates.predicates || []),
26
- ...castArray(predicates),
27
- ],
28
- };
29
- };
package/src/predicate.ts DELETED
@@ -1,359 +0,0 @@
1
- /**
2
- * Formats the value of a predicate element to a stringified version accepted by
3
- * the Prismic REST API.
4
- *
5
- * @param value - Value to format.
6
- *
7
- * @returns `value` formatted for the Prismic REST API.
8
- */
9
- const formatValue = (
10
- value:
11
- | string
12
- | number
13
- | Date
14
- | unknown
15
- | (string | number | Date | unknown)[],
16
- ): string => {
17
- if (Array.isArray(value)) {
18
- return `[${value.map(formatValue).join(", ")}]`;
19
- }
20
-
21
- if (typeof value === "string") {
22
- return `"${value}"`;
23
- }
24
-
25
- if (value instanceof Date) {
26
- return `${value.getTime()}`;
27
- }
28
-
29
- return `${value}`;
30
- };
31
-
32
- /**
33
- * Creates a predicate builder function for predicates with a path and
34
- * arguments.
35
- *
36
- * @typeParam Args - Arguments for the predicate.
37
- * @param name - Name of the predicate used in the resulting string.
38
- *
39
- * @returns Predicate builder function for the given name.
40
- */
41
- const pathWithArgsPredicate = <Args extends unknown[]>(name: string) => {
42
- /**
43
- * @param path - Path to the value to be compared.
44
- */
45
- const fn = (path: string, ...args: Args): string => {
46
- const formattedArgs = args.map(formatValue).join(", ");
47
- const joiner = path && args.length ? ", " : "";
48
-
49
- return `[${name}(${path}${joiner}${formattedArgs})]`;
50
- };
51
-
52
- return fn;
53
- };
54
-
55
- /**
56
- * Creates a predicate builder function for predicates with only a path.
57
- *
58
- * @param name - Name of the predicate used in the resulting string.
59
- *
60
- * @returns Predicate builder function for the given name.
61
- */
62
- const pathPredicate = (name: string) => {
63
- const predicateFn = pathWithArgsPredicate(name);
64
-
65
- /**
66
- * @param path - Path for the predicate.
67
- */
68
- const fn = (path: string): string => {
69
- return predicateFn(path);
70
- };
71
-
72
- return fn;
73
- };
74
-
75
- /**
76
- * Creates a predicate builder function for predicates with only arguments and
77
- * no path.
78
- *
79
- * @param name - Name of the predicate used in the resulting string.
80
- *
81
- * @returns Predicate builder function for the given name.
82
- */
83
- const argsPredicate = <Args extends unknown[]>(name: string) => {
84
- const predicateFn = pathWithArgsPredicate<Args>(name);
85
-
86
- /**
87
- * @param args - Arguments for the predicate.
88
- */
89
- const fn = (...args: Args): string => {
90
- return predicateFn("", ...args);
91
- };
92
-
93
- return fn;
94
- };
95
-
96
- export const predicate = {
97
- /**
98
- * The `at` predicate checks that the path matches the described value
99
- * exactly. It takes a single value for a field or an array (only for tags).
100
- *
101
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#at}
102
- */
103
- at: pathWithArgsPredicate<
104
- [value: string | number | boolean | Date | string[]]
105
- >("at"),
106
-
107
- /**
108
- * The `not` predicate checks that the path doesn't match the provided value
109
- * exactly. It takes a single value for a field or an array (only for tags).
110
- *
111
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#not}
112
- */
113
- not: pathWithArgsPredicate<
114
- [value: string | number | boolean | Date | string[]]
115
- >("not"),
116
-
117
- /**
118
- * The `any` predicate takes an array of values. It works exactly the same way
119
- * as the `at` operator, but checks whether the fragment matches any of the
120
- * values in the array.
121
- *
122
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#any}
123
- */
124
- any: pathWithArgsPredicate<[values: (string | number | boolean | Date)[]]>(
125
- "any",
126
- ),
127
-
128
- /**
129
- * The `in` predicate is used specifically to retrieve an array of documents
130
- * by their IDs or UIDs. This predicate is much more efficient at this than
131
- * the any predicate.
132
- *
133
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#in}
134
- */
135
- in: pathWithArgsPredicate<[values: string[]]>("in"),
136
-
137
- /**
138
- * The `fulltext` predicate provides two capabilities:
139
- *
140
- * 1. Checking if a certain string is anywhere inside a document (this is what
141
- * you should use to make your project's search engine feature)
142
- * 2. Checking if the string is contained inside a specific custom type’s Rich
143
- * Text or Key Text fragment.
144
- *
145
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#fulltext}
146
- */
147
- fulltext: pathWithArgsPredicate<[searchTerms: string]>("fulltext"),
148
-
149
- /**
150
- * The `has` predicate checks whether a fragment has a value. It will return
151
- * all the documents of the specified type that contain a value for the
152
- * specified field.
153
- *
154
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#has}
155
- */
156
- has: pathPredicate("has"),
157
-
158
- /**
159
- * The `missing` predicate checks if a fragment doesn't have a value. It will
160
- * return all the documents of the specified type that do not contain a value
161
- * for the specified field.
162
- *
163
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#missing}
164
- */
165
- missing: pathPredicate("missing"),
166
-
167
- /**
168
- * The `similar` predicate takes the ID of a document, and returns a list of
169
- * documents with similar content. This allows you to build an automated
170
- * content discovery feature (for example, a "Related posts" section).
171
- *
172
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#similar}
173
- */
174
- similar: argsPredicate<[id: string, value: number]>("similar"),
175
-
176
- /**
177
- * The `geopoint.near` predicate checks that the value in the path is within
178
- * the radius of the given coordinates.
179
- *
180
- * This predicate will only work for a GeoPoint field.
181
- *
182
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#near}
183
- */
184
- geopointNear:
185
- pathWithArgsPredicate<
186
- [latitude: number, longitude: number, radius: number]
187
- >("geopoint.near"),
188
-
189
- /**
190
- * The `number.lt` predicate checks that the value in the number field is less
191
- * than the value passed into the predicate.
192
- *
193
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#lt-less-than}
194
- */
195
- numberLessThan: pathWithArgsPredicate<[value: number]>("number.lt"),
196
-
197
- /**
198
- * The `number.gt` predicate checks that the value in the number field is
199
- * greater than the value passed into the predicate.
200
- *
201
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#gt-greater-than}
202
- */
203
- numberGreaterThan: pathWithArgsPredicate<[value: number]>("number.gt"),
204
-
205
- /**
206
- * The `number.inRange` predicate checks that the value in the path is within
207
- * the two values passed into the predicate.
208
- *
209
- * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api#inrange}
210
- */
211
- numberInRange:
212
- pathWithArgsPredicate<[lowerLimit: number, upperLimit: number]>(
213
- "number.inRange",
214
- ),
215
-
216
- /**
217
- * The `date.after` predicate checks that the value in the path is after the
218
- * date value passed into the predicate.
219
- *
220
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#after}
221
- */
222
- dateAfter:
223
- pathWithArgsPredicate<[date: string | number | Date]>("date.after"),
224
-
225
- /**
226
- * The `date.before` predicate checks that the value in the path is before the
227
- * date value passed into the predicate.
228
- *
229
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#before}
230
- */
231
- dateBefore:
232
- pathWithArgsPredicate<[date: string | number | Date]>("date.before"),
233
-
234
- /**
235
- * The `date.between` predicate checks that the value in the path is within
236
- * the date values passed into the predicate.
237
- *
238
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#between}
239
- */
240
- dateBetween:
241
- pathWithArgsPredicate<
242
- [startDate: string | number | Date, endDate: string | number | Date]
243
- >("date.between"),
244
-
245
- /**
246
- * The `date.day-of-month` predicate checks that the value in the path is
247
- * equal to the day of the month passed into the predicate.
248
- *
249
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonth}
250
- */
251
- dateDayOfMonth: pathWithArgsPredicate<[day: number]>("date.day-of-month"),
252
-
253
- /**
254
- * The `date.day-of-month-after` predicate checks that the value in the path
255
- * is after the day of the month passed into the predicate.
256
- *
257
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonthafter}
258
- */
259
- dateDayOfMonthAfter: pathWithArgsPredicate<[day: number]>(
260
- "date.day-of-month-after",
261
- ),
262
-
263
- /**
264
- * The `date.day-of-month-before` predicate checks that the value in the path
265
- * is before the day of the month passed into the predicate.
266
- *
267
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofmonthbefore}
268
- */
269
- dateDayOfMonthBefore: pathWithArgsPredicate<[day: number]>(
270
- "date.day-of-month-before",
271
- ),
272
-
273
- /**
274
- * The `date.day-of-week` predicate checks that the value in the path is equal
275
- * to the day of the week passed into the predicate.
276
- *
277
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweek}
278
- */
279
- dateDayOfWeek:
280
- pathWithArgsPredicate<[day: string | number]>("date.day-of-week"),
281
-
282
- /**
283
- * The `date.day-of-week-after` predicate checks that the value in the path is
284
- * after the day of the week passed into the predicate.
285
- *
286
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweekafter}
287
- */
288
- dateDayOfWeekAfter: pathWithArgsPredicate<[day: string | number]>(
289
- "date.day-of-week-after",
290
- ),
291
-
292
- /**
293
- * The date.day-of-week-before predicate checks that the value in the path is
294
- * before the day of the week passed into the predicate.
295
- *
296
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#dayofweekbefore}
297
- */
298
- dateDayOfWeekBefore: pathWithArgsPredicate<[day: string | number]>(
299
- "date.day-of-week-before",
300
- ),
301
-
302
- /**
303
- * The `date.month` predicate checks that the value in the path occurs in the
304
- * month value passed into the predicate.
305
- *
306
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#month}
307
- */
308
- dateMonth: pathWithArgsPredicate<[month: string | number]>("date.month"),
309
-
310
- /**
311
- * The `date.month-after` predicate checks that the value in the path occurs
312
- * in any month after the value passed into the predicate.
313
- *
314
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#monthafter}
315
- */
316
- dateMonthAfter:
317
- pathWithArgsPredicate<[month: string | number]>("date.month-after"),
318
-
319
- /**
320
- * The `date.month-before` predicate checks that the value in the path occurs
321
- * in any month before the value passed into the predicate.
322
- *
323
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#monthbefore}
324
- */
325
- dateMonthBefore:
326
- pathWithArgsPredicate<[month: string | number]>("date.month-before"),
327
-
328
- /**
329
- * The `date.year` predicate checks that the value in the path occurs in the
330
- * year value passed into the predicate.
331
- *
332
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#year}
333
- */
334
- dateYear: pathWithArgsPredicate<[year: number]>("date.year"),
335
-
336
- /**
337
- * The `date.hour` predicate checks that the value in the path occurs within
338
- * the hour value passed into the predicate.
339
- *
340
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hour}
341
- */
342
- dateHour: pathWithArgsPredicate<[hour: number]>("date.hour"),
343
-
344
- /**
345
- * The `date.hour-after` predicate checks that the value in the path occurs
346
- * after the hour value passed into the predicate.
347
- *
348
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hourafter}
349
- */
350
- dateHourAfter: pathWithArgsPredicate<[hour: number]>("date.hour-after"),
351
-
352
- /**
353
- * The `date.hour-before` predicate checks that the value in the path occurs
354
- * before the hour value passed into the predicate.
355
- *
356
- * {@link https://prismic.io/docs/technologies/date-and-time-based-predicate-reference-rest-api#hourbefore}
357
- */
358
- dateHourBefore: pathWithArgsPredicate<[hour: number]>("date.hour-before"),
359
- };
@@ -1,157 +0,0 @@
1
- import { PrismicDocument } from "./value/document";
2
- import { ExtractOrFallback } from "./utils";
3
-
4
- /**
5
- * Extracts one or more Prismic document types that match a given Prismic
6
- * document type. If no matches are found, no extraction is performed and the
7
- * union of all provided Prismic document types are returned.
8
- *
9
- * @typeParam TDocuments - Prismic document types from which to extract.
10
- * @typeParam TDocumentType - Type(s) to match `TDocuments` against.
11
- */
12
- export type ExtractDocumentType<
13
- TDocuments extends PrismicDocument,
14
- TDocumentType extends TDocuments["type"],
15
- > = ExtractOrFallback<TDocuments, { type: TDocumentType }>;
16
-
17
- /**
18
- * A universal API to make network requests. A subset of the `fetch()` API.
19
- *
20
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
21
- */
22
- export type FetchLike = (
23
- input: string,
24
- init?: RequestInitLike,
25
- ) => Promise<ResponseLike>;
26
-
27
- /**
28
- * An object that allows you to abort a `fetch()` request if needed via an
29
- * `AbortController` object
30
- *
31
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
32
- */
33
- // `any` is used often here to ensure this type is universally valid among
34
- // different AbortSignal implementations. The types of each property are not
35
- // important to validate since it is blindly passed to a given `fetch()`
36
- // function.
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- export type AbortSignalLike = any;
39
-
40
- /**
41
- * The minimum required properties from RequestInit.
42
- */
43
- export interface RequestInitLike {
44
- headers?: Record<string, string>;
45
-
46
- /**
47
- * An object that allows you to abort a `fetch()` request if needed via an
48
- * `AbortController` object
49
- *
50
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
51
- */
52
- // NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`
53
- // for backwards compatibility (the type is exported) and to signal to
54
- // other readers that this should be an AbortSignal-like object.
55
- signal?: AbortSignalLike;
56
- }
57
-
58
- /**
59
- * The minimum required properties from Response.
60
- */
61
- export interface ResponseLike {
62
- status: number;
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- json(): Promise<any>;
65
- }
66
-
67
- /**
68
- * The minimum required properties to treat as an HTTP Request for automatic
69
- * Prismic preview support.
70
- */
71
- export type HttpRequestLike =
72
- | /**
73
- * Web API Request
74
- *
75
- * @see http://developer.mozilla.org/en-US/docs/Web/API/Request
76
- */
77
- {
78
- headers?: {
79
- get(name: string): string | null;
80
- };
81
- url?: string;
82
- }
83
-
84
- /**
85
- * Express-style Request
86
- */
87
- | {
88
- headers?: {
89
- cookie?: string;
90
- };
91
- query?: Record<string, unknown>;
92
- };
93
-
94
- /**
95
- * An `orderings` parameter that orders the results by the specified field.
96
- *
97
- * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#orderings}
98
- */
99
- export interface Ordering {
100
- field: string;
101
- direction?: "asc" | "desc";
102
- }
103
-
104
- /**
105
- * A `routes` parameter that determines how a document's URL field is resolved.
106
- *
107
- * @example With a document's UID field.
108
- *
109
- * ```ts
110
- * {
111
- * "type": "page",
112
- * "path": "/:uid"
113
- * }
114
- * ```
115
- *
116
- * @example With a Content Relationship `parent` field.
117
- *
118
- * ```ts
119
- * {
120
- * "type": "page",
121
- * "path": "/:parent?/:uid",
122
- * "resolvers": {
123
- * "parent": "parent"
124
- * }
125
- * }
126
- * ```
127
- *
128
- * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
129
- */
130
- export interface Route {
131
- /**
132
- * The Custom Type of the document.
133
- */
134
- type: string;
135
-
136
- /**
137
- * A specific UID to which this route definition is scoped. The route is only
138
- * defined for the document whose UID matches the given UID.
139
- */
140
- uid?: string;
141
-
142
- /**
143
- * A specific language to which this route definition is scoped. The route is
144
- * only defined for documents whose language matches the given language.
145
- */
146
- lang?: string;
147
-
148
- /**
149
- * The resolved path of the document with optional placeholders.
150
- */
151
- path: string;
152
-
153
- /**
154
- * An object that lists the API IDs of the Content Relationships in the route.
155
- */
156
- resolvers?: Record<string, string>;
157
- }
@@ -1,103 +0,0 @@
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;
@@ -1,34 +0,0 @@
1
- /**
2
- * Create a union of the given object's values, and optionally specify which
3
- * keys to get the values from.
4
- *
5
- * Taken from the `type-fest` package.
6
- *
7
- * See:
8
- * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/value-of.d.ts
9
- */
10
- export type ValueOf<
11
- ObjectType,
12
- ValueType extends keyof ObjectType = keyof ObjectType,
13
- > = ObjectType[ValueType];
14
-
15
- /**
16
- * Functions like TypeScript's native `Extract` utility type with added support
17
- * to fall back to a value if the resulting union is `never`.
18
- *
19
- * @example
20
- *
21
- * ```ts
22
- * ExtractOrFallback<"a" | "b", "a">; // => "a"
23
- * ExtractOrFallback<"a" | "b", "c">; // => "a" | "b"
24
- * ExtractOrFallback<"a" | "b", "c", "foo">; // => "foo"
25
- * ```
26
- *
27
- * @typeParam T - The union from which values will be extracted.
28
- * @typeParam U - The extraction condition.
29
- * @typeParam Fallback - The value to return if the resulting union is `never`.
30
- * Defaults to `T`.
31
- */
32
- export type ExtractOrFallback<T, U, Fallback = T> = Extract<T, U> extends never
33
- ? Fallback
34
- : Extract<T, U>;
File without changes