@prismicio/client 7.21.7 → 7.21.8-pr.446.7e39a41

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 (598) hide show
  1. package/dist/Client.cjs +190 -263
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.cts +175 -241
  4. package/dist/Client.d.cts.map +1 -1
  5. package/dist/Client.d.ts +175 -241
  6. package/dist/Client.d.ts.map +1 -1
  7. package/dist/Client.js +190 -263
  8. package/dist/Client.js.map +1 -1
  9. package/dist/Migration.cjs +54 -86
  10. package/dist/Migration.cjs.map +1 -1
  11. package/dist/Migration.d.cts +50 -84
  12. package/dist/Migration.d.cts.map +1 -1
  13. package/dist/Migration.d.ts +50 -84
  14. package/dist/Migration.d.ts.map +1 -1
  15. package/dist/Migration.js +54 -86
  16. package/dist/Migration.js.map +1 -1
  17. package/dist/WriteClient.cjs +77 -77
  18. package/dist/WriteClient.cjs.map +1 -1
  19. package/dist/WriteClient.d.cts +50 -63
  20. package/dist/WriteClient.d.cts.map +1 -1
  21. package/dist/WriteClient.d.ts +50 -63
  22. package/dist/WriteClient.d.ts.map +1 -1
  23. package/dist/WriteClient.js +77 -77
  24. package/dist/WriteClient.js.map +1 -1
  25. package/dist/buildQueryURL.cjs +15 -22
  26. package/dist/buildQueryURL.cjs.map +1 -1
  27. package/dist/buildQueryURL.d.cts +53 -63
  28. package/dist/buildQueryURL.d.cts.map +1 -1
  29. package/dist/buildQueryURL.d.ts +53 -63
  30. package/dist/buildQueryURL.d.ts.map +1 -1
  31. package/dist/buildQueryURL.js +15 -22
  32. package/dist/buildQueryURL.js.map +1 -1
  33. package/dist/cookie.cjs +1 -4
  34. package/dist/cookie.cjs.map +1 -1
  35. package/dist/cookie.d.cts +1 -4
  36. package/dist/cookie.d.cts.map +1 -1
  37. package/dist/cookie.d.ts +1 -4
  38. package/dist/cookie.d.ts.map +1 -1
  39. package/dist/cookie.js +1 -4
  40. package/dist/cookie.js.map +1 -1
  41. package/dist/createClient.cjs +10 -14
  42. package/dist/createClient.cjs.map +1 -1
  43. package/dist/createClient.d.cts +11 -18
  44. package/dist/createClient.d.cts.map +1 -1
  45. package/dist/createClient.d.ts +11 -18
  46. package/dist/createClient.d.ts.map +1 -1
  47. package/dist/createClient.js +10 -14
  48. package/dist/createClient.js.map +1 -1
  49. package/dist/createMigration.cjs +4 -7
  50. package/dist/createMigration.cjs.map +1 -1
  51. package/dist/createMigration.d.cts +5 -11
  52. package/dist/createMigration.d.cts.map +1 -1
  53. package/dist/createMigration.d.ts +5 -11
  54. package/dist/createMigration.d.ts.map +1 -1
  55. package/dist/createMigration.js +4 -7
  56. package/dist/createMigration.js.map +1 -1
  57. package/dist/createWriteClient.cjs +8 -13
  58. package/dist/createWriteClient.cjs.map +1 -1
  59. package/dist/createWriteClient.d.cts +10 -15
  60. package/dist/createWriteClient.d.cts.map +1 -1
  61. package/dist/createWriteClient.d.ts +10 -15
  62. package/dist/createWriteClient.d.ts.map +1 -1
  63. package/dist/createWriteClient.js +8 -13
  64. package/dist/createWriteClient.js.map +1 -1
  65. package/dist/errors.cjs.map +1 -1
  66. package/dist/errors.d.cts.map +1 -1
  67. package/dist/errors.d.ts.map +1 -1
  68. package/dist/errors.js.map +1 -1
  69. package/dist/filter.cjs +5 -18
  70. package/dist/filter.cjs.map +1 -1
  71. package/dist/filter.d.cts +59 -63
  72. package/dist/filter.d.cts.map +1 -1
  73. package/dist/filter.d.ts +59 -63
  74. package/dist/filter.d.ts.map +1 -1
  75. package/dist/filter.js +5 -18
  76. package/dist/filter.js.map +1 -1
  77. package/dist/getGraphQLEndpoint.cjs +0 -2
  78. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  79. package/dist/getGraphQLEndpoint.d.cts +0 -2
  80. package/dist/getGraphQLEndpoint.d.cts.map +1 -1
  81. package/dist/getGraphQLEndpoint.d.ts +0 -2
  82. package/dist/getGraphQLEndpoint.d.ts.map +1 -1
  83. package/dist/getGraphQLEndpoint.js +0 -2
  84. package/dist/getGraphQLEndpoint.js.map +1 -1
  85. package/dist/getRepositoryEndpoint.cjs +4 -8
  86. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  87. package/dist/getRepositoryEndpoint.d.cts +4 -8
  88. package/dist/getRepositoryEndpoint.d.cts.map +1 -1
  89. package/dist/getRepositoryEndpoint.d.ts +4 -8
  90. package/dist/getRepositoryEndpoint.d.ts.map +1 -1
  91. package/dist/getRepositoryEndpoint.js +4 -8
  92. package/dist/getRepositoryEndpoint.js.map +1 -1
  93. package/dist/getRepositoryName.cjs +2 -5
  94. package/dist/getRepositoryName.cjs.map +1 -1
  95. package/dist/getRepositoryName.d.cts +2 -5
  96. package/dist/getRepositoryName.d.cts.map +1 -1
  97. package/dist/getRepositoryName.d.ts +2 -5
  98. package/dist/getRepositoryName.d.ts.map +1 -1
  99. package/dist/getRepositoryName.js +2 -5
  100. package/dist/getRepositoryName.js.map +1 -1
  101. package/dist/getToolbarSrc.cjs +17 -19
  102. package/dist/getToolbarSrc.cjs.map +1 -1
  103. package/dist/getToolbarSrc.d.cts +17 -19
  104. package/dist/getToolbarSrc.d.cts.map +1 -1
  105. package/dist/getToolbarSrc.d.ts +17 -19
  106. package/dist/getToolbarSrc.d.ts.map +1 -1
  107. package/dist/getToolbarSrc.js +17 -19
  108. package/dist/getToolbarSrc.js.map +1 -1
  109. package/dist/helpers/asDate.cjs +6 -9
  110. package/dist/helpers/asDate.cjs.map +1 -1
  111. package/dist/helpers/asDate.d.cts +5 -10
  112. package/dist/helpers/asDate.d.cts.map +1 -1
  113. package/dist/helpers/asDate.d.ts +5 -10
  114. package/dist/helpers/asDate.d.ts.map +1 -1
  115. package/dist/helpers/asDate.js +6 -9
  116. package/dist/helpers/asDate.js.map +1 -1
  117. package/dist/helpers/asHTML.cjs +25 -26
  118. package/dist/helpers/asHTML.cjs.map +1 -1
  119. package/dist/helpers/asHTML.d.cts +29 -55
  120. package/dist/helpers/asHTML.d.cts.map +1 -1
  121. package/dist/helpers/asHTML.d.ts +29 -55
  122. package/dist/helpers/asHTML.d.ts.map +1 -1
  123. package/dist/helpers/asHTML.js +25 -26
  124. package/dist/helpers/asHTML.js.map +1 -1
  125. package/dist/helpers/asImagePixelDensitySrcSet.cjs +21 -27
  126. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  127. package/dist/helpers/asImagePixelDensitySrcSet.d.cts +25 -36
  128. package/dist/helpers/asImagePixelDensitySrcSet.d.cts.map +1 -1
  129. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +25 -36
  130. package/dist/helpers/asImagePixelDensitySrcSet.d.ts.map +1 -1
  131. package/dist/helpers/asImagePixelDensitySrcSet.js +21 -27
  132. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  133. package/dist/helpers/asImageSrc.cjs +7 -12
  134. package/dist/helpers/asImageSrc.cjs.map +1 -1
  135. package/dist/helpers/asImageSrc.d.cts +8 -15
  136. package/dist/helpers/asImageSrc.d.cts.map +1 -1
  137. package/dist/helpers/asImageSrc.d.ts +8 -15
  138. package/dist/helpers/asImageSrc.d.ts.map +1 -1
  139. package/dist/helpers/asImageSrc.js +7 -12
  140. package/dist/helpers/asImageSrc.js.map +1 -1
  141. package/dist/helpers/asImageWidthSrcSet.cjs +25 -32
  142. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  143. package/dist/helpers/asImageWidthSrcSet.d.cts +29 -41
  144. package/dist/helpers/asImageWidthSrcSet.d.cts.map +1 -1
  145. package/dist/helpers/asImageWidthSrcSet.d.ts +29 -41
  146. package/dist/helpers/asImageWidthSrcSet.d.ts.map +1 -1
  147. package/dist/helpers/asImageWidthSrcSet.js +25 -32
  148. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  149. package/dist/helpers/asLink.cjs.map +1 -1
  150. package/dist/helpers/asLink.d.cts +15 -32
  151. package/dist/helpers/asLink.d.cts.map +1 -1
  152. package/dist/helpers/asLink.d.ts +15 -32
  153. package/dist/helpers/asLink.d.ts.map +1 -1
  154. package/dist/helpers/asLink.js.map +1 -1
  155. package/dist/helpers/asLinkAttrs.cjs +8 -11
  156. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  157. package/dist/helpers/asLinkAttrs.d.cts +9 -14
  158. package/dist/helpers/asLinkAttrs.d.cts.map +1 -1
  159. package/dist/helpers/asLinkAttrs.d.ts +9 -14
  160. package/dist/helpers/asLinkAttrs.d.ts.map +1 -1
  161. package/dist/helpers/asLinkAttrs.js +8 -11
  162. package/dist/helpers/asLinkAttrs.js.map +1 -1
  163. package/dist/helpers/asText.cjs.map +1 -1
  164. package/dist/helpers/asText.d.cts +10 -23
  165. package/dist/helpers/asText.d.cts.map +1 -1
  166. package/dist/helpers/asText.d.ts +10 -23
  167. package/dist/helpers/asText.d.ts.map +1 -1
  168. package/dist/helpers/asText.js.map +1 -1
  169. package/dist/helpers/documentToLinkField.cjs +2 -7
  170. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  171. package/dist/helpers/documentToLinkField.d.cts +1 -5
  172. package/dist/helpers/documentToLinkField.d.cts.map +1 -1
  173. package/dist/helpers/documentToLinkField.d.ts +1 -5
  174. package/dist/helpers/documentToLinkField.d.ts.map +1 -1
  175. package/dist/helpers/documentToLinkField.js +2 -7
  176. package/dist/helpers/documentToLinkField.js.map +1 -1
  177. package/dist/helpers/isFilled.cjs +8 -35
  178. package/dist/helpers/isFilled.cjs.map +1 -1
  179. package/dist/helpers/isFilled.d.cts +8 -32
  180. package/dist/helpers/isFilled.d.cts.map +1 -1
  181. package/dist/helpers/isFilled.d.ts +8 -32
  182. package/dist/helpers/isFilled.d.ts.map +1 -1
  183. package/dist/helpers/isFilled.js +8 -35
  184. package/dist/helpers/isFilled.js.map +1 -1
  185. package/dist/helpers/mapSliceZone.cjs +8 -10
  186. package/dist/helpers/mapSliceZone.cjs.map +1 -1
  187. package/dist/helpers/mapSliceZone.d.cts +35 -63
  188. package/dist/helpers/mapSliceZone.d.cts.map +1 -1
  189. package/dist/helpers/mapSliceZone.d.ts +35 -63
  190. package/dist/helpers/mapSliceZone.d.ts.map +1 -1
  191. package/dist/helpers/mapSliceZone.js +8 -10
  192. package/dist/helpers/mapSliceZone.js.map +1 -1
  193. package/dist/index.cjs +11 -17
  194. package/dist/index.cjs.map +1 -1
  195. package/dist/index.d.cts +38 -51
  196. package/dist/index.d.cts.map +1 -1
  197. package/dist/index.d.ts +38 -51
  198. package/dist/index.d.ts.map +1 -1
  199. package/dist/index.js +11 -17
  200. package/dist/index.js.map +1 -1
  201. package/dist/isRepositoryEndpoint.cjs +3 -4
  202. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  203. package/dist/isRepositoryEndpoint.d.cts +3 -4
  204. package/dist/isRepositoryEndpoint.d.cts.map +1 -1
  205. package/dist/isRepositoryEndpoint.d.ts +3 -4
  206. package/dist/isRepositoryEndpoint.d.ts.map +1 -1
  207. package/dist/isRepositoryEndpoint.js +3 -4
  208. package/dist/isRepositoryEndpoint.js.map +1 -1
  209. package/dist/isRepositoryName.cjs +1 -2
  210. package/dist/isRepositoryName.cjs.map +1 -1
  211. package/dist/isRepositoryName.d.cts +1 -2
  212. package/dist/isRepositoryName.d.cts.map +1 -1
  213. package/dist/isRepositoryName.d.ts +1 -2
  214. package/dist/isRepositoryName.d.ts.map +1 -1
  215. package/dist/isRepositoryName.js +1 -2
  216. package/dist/isRepositoryName.js.map +1 -1
  217. package/dist/lib/devMsg.cjs +6 -8
  218. package/dist/lib/devMsg.cjs.map +1 -1
  219. package/dist/lib/devMsg.js +6 -8
  220. package/dist/lib/devMsg.js.map +1 -1
  221. package/dist/lib/getOptionalLinkProperties.cjs +5 -6
  222. package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
  223. package/dist/lib/getOptionalLinkProperties.js +5 -6
  224. package/dist/lib/getOptionalLinkProperties.js.map +1 -1
  225. package/dist/lib/getPreviewCookie.cjs +1 -3
  226. package/dist/lib/getPreviewCookie.cjs.map +1 -1
  227. package/dist/lib/getPreviewCookie.js +1 -3
  228. package/dist/lib/getPreviewCookie.js.map +1 -1
  229. package/dist/lib/isInternalURL.cjs +0 -1
  230. package/dist/lib/isInternalURL.cjs.map +1 -1
  231. package/dist/lib/isInternalURL.js +0 -1
  232. package/dist/lib/isInternalURL.js.map +1 -1
  233. package/dist/lib/isMigrationValue.cjs +7 -17
  234. package/dist/lib/isMigrationValue.cjs.map +1 -1
  235. package/dist/lib/isMigrationValue.js +7 -17
  236. package/dist/lib/isMigrationValue.js.map +1 -1
  237. package/dist/lib/isValue.cjs +2 -16
  238. package/dist/lib/isValue.cjs.map +1 -1
  239. package/dist/lib/isValue.js +2 -16
  240. package/dist/lib/isValue.js.map +1 -1
  241. package/dist/lib/pLimit.cjs +5 -7
  242. package/dist/lib/pLimit.cjs.map +1 -1
  243. package/dist/lib/pLimit.js +5 -7
  244. package/dist/lib/pLimit.js.map +1 -1
  245. package/dist/lib/request.cjs +12 -23
  246. package/dist/lib/request.cjs.map +1 -1
  247. package/dist/lib/request.d.cts +7 -20
  248. package/dist/lib/request.d.cts.map +1 -1
  249. package/dist/lib/request.d.ts +7 -20
  250. package/dist/lib/request.d.ts.map +1 -1
  251. package/dist/lib/request.js +12 -23
  252. package/dist/lib/request.js.map +1 -1
  253. package/dist/lib/resolveMigrationDocumentData.cjs +7 -15
  254. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
  255. package/dist/lib/resolveMigrationDocumentData.js +7 -15
  256. package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
  257. package/dist/lib/serializerHelpers.cjs.map +1 -1
  258. package/dist/lib/serializerHelpers.js.map +1 -1
  259. package/dist/lib/throttledWarn.cjs +3 -4
  260. package/dist/lib/throttledWarn.cjs.map +1 -1
  261. package/dist/lib/throttledWarn.js +3 -4
  262. package/dist/lib/throttledWarn.js.map +1 -1
  263. package/dist/lib/validateAssetMetadata.cjs +6 -18
  264. package/dist/lib/validateAssetMetadata.cjs.map +1 -1
  265. package/dist/lib/validateAssetMetadata.js +6 -18
  266. package/dist/lib/validateAssetMetadata.js.map +1 -1
  267. package/dist/package.cjs +1 -1
  268. package/dist/package.js +1 -1
  269. package/dist/richtext/asText.cjs +0 -2
  270. package/dist/richtext/asText.cjs.map +1 -1
  271. package/dist/richtext/asText.d.cts +0 -2
  272. package/dist/richtext/asText.d.cts.map +1 -1
  273. package/dist/richtext/asText.d.ts +0 -2
  274. package/dist/richtext/asText.d.ts.map +1 -1
  275. package/dist/richtext/asText.js +0 -2
  276. package/dist/richtext/asText.js.map +1 -1
  277. package/dist/richtext/asTree.cjs +2 -4
  278. package/dist/richtext/asTree.cjs.map +1 -1
  279. package/dist/richtext/asTree.d.cts +2 -4
  280. package/dist/richtext/asTree.d.cts.map +1 -1
  281. package/dist/richtext/asTree.d.ts +2 -4
  282. package/dist/richtext/asTree.d.ts.map +1 -1
  283. package/dist/richtext/asTree.js +2 -4
  284. package/dist/richtext/asTree.js.map +1 -1
  285. package/dist/richtext/composeSerializers.cjs +4 -7
  286. package/dist/richtext/composeSerializers.cjs.map +1 -1
  287. package/dist/richtext/composeSerializers.d.cts +4 -7
  288. package/dist/richtext/composeSerializers.d.cts.map +1 -1
  289. package/dist/richtext/composeSerializers.d.ts +4 -7
  290. package/dist/richtext/composeSerializers.d.ts.map +1 -1
  291. package/dist/richtext/composeSerializers.js +4 -7
  292. package/dist/richtext/composeSerializers.js.map +1 -1
  293. package/dist/richtext/serialize.cjs +2 -6
  294. package/dist/richtext/serialize.cjs.map +1 -1
  295. package/dist/richtext/serialize.d.cts +2 -6
  296. package/dist/richtext/serialize.d.cts.map +1 -1
  297. package/dist/richtext/serialize.d.ts +2 -6
  298. package/dist/richtext/serialize.d.ts.map +1 -1
  299. package/dist/richtext/serialize.js +2 -6
  300. package/dist/richtext/serialize.js.map +1 -1
  301. package/dist/richtext/types.cjs.map +1 -1
  302. package/dist/richtext/types.d.cts +3 -7
  303. package/dist/richtext/types.d.cts.map +1 -1
  304. package/dist/richtext/types.d.ts +3 -7
  305. package/dist/richtext/types.d.ts.map +1 -1
  306. package/dist/richtext/types.js.map +1 -1
  307. package/dist/richtext/wrapMapSerializer.cjs +2 -5
  308. package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
  309. package/dist/richtext/wrapMapSerializer.d.cts +2 -5
  310. package/dist/richtext/wrapMapSerializer.d.cts.map +1 -1
  311. package/dist/richtext/wrapMapSerializer.d.ts +2 -5
  312. package/dist/richtext/wrapMapSerializer.d.ts.map +1 -1
  313. package/dist/richtext/wrapMapSerializer.js +2 -5
  314. package/dist/richtext/wrapMapSerializer.js.map +1 -1
  315. package/dist/types/api/asset/asset.d.cts +17 -70
  316. package/dist/types/api/asset/asset.d.cts.map +1 -1
  317. package/dist/types/api/asset/asset.d.ts +17 -70
  318. package/dist/types/api/asset/asset.d.ts.map +1 -1
  319. package/dist/types/api/asset/tag.d.cts +5 -23
  320. package/dist/types/api/asset/tag.d.cts.map +1 -1
  321. package/dist/types/api/asset/tag.d.ts +5 -23
  322. package/dist/types/api/asset/tag.d.ts.map +1 -1
  323. package/dist/types/api/integration.d.cts +2 -4
  324. package/dist/types/api/integration.d.cts.map +1 -1
  325. package/dist/types/api/integration.d.ts +2 -4
  326. package/dist/types/api/integration.d.ts.map +1 -1
  327. package/dist/types/api/migration/release.d.cts +16 -0
  328. package/dist/types/api/migration/release.d.cts.map +1 -0
  329. package/dist/types/api/migration/release.d.ts +16 -0
  330. package/dist/types/api/migration/release.d.ts.map +1 -0
  331. package/dist/types/api/query.d.cts +10 -27
  332. package/dist/types/api/query.d.cts.map +1 -1
  333. package/dist/types/api/query.d.ts +10 -27
  334. package/dist/types/api/query.d.ts.map +1 -1
  335. package/dist/types/api/ref.d.cts +6 -16
  336. package/dist/types/api/ref.d.cts.map +1 -1
  337. package/dist/types/api/ref.d.ts +6 -16
  338. package/dist/types/api/ref.d.ts.map +1 -1
  339. package/dist/types/api/release.d.cts +1 -2
  340. package/dist/types/api/release.d.cts.map +1 -1
  341. package/dist/types/api/release.d.ts +1 -2
  342. package/dist/types/api/release.d.ts.map +1 -1
  343. package/dist/types/api/repository.d.cts +18 -45
  344. package/dist/types/api/repository.d.cts.map +1 -1
  345. package/dist/types/api/repository.d.ts +18 -45
  346. package/dist/types/api/repository.d.ts.map +1 -1
  347. package/dist/types/api/tags.d.cts +2 -3
  348. package/dist/types/api/tags.d.cts.map +1 -1
  349. package/dist/types/api/tags.d.ts +2 -3
  350. package/dist/types/api/tags.d.ts.map +1 -1
  351. package/dist/types/migration/Asset.cjs +4 -13
  352. package/dist/types/migration/Asset.cjs.map +1 -1
  353. package/dist/types/migration/Asset.d.cts +20 -66
  354. package/dist/types/migration/Asset.d.cts.map +1 -1
  355. package/dist/types/migration/Asset.d.ts +20 -66
  356. package/dist/types/migration/Asset.d.ts.map +1 -1
  357. package/dist/types/migration/Asset.js +4 -13
  358. package/dist/types/migration/Asset.js.map +1 -1
  359. package/dist/types/migration/ContentRelationship.d.cts +1 -3
  360. package/dist/types/migration/ContentRelationship.d.cts.map +1 -1
  361. package/dist/types/migration/ContentRelationship.d.ts +1 -3
  362. package/dist/types/migration/ContentRelationship.d.ts.map +1 -1
  363. package/dist/types/migration/Document.cjs +10 -19
  364. package/dist/types/migration/Document.cjs.map +1 -1
  365. package/dist/types/migration/Document.d.cts +12 -31
  366. package/dist/types/migration/Document.d.cts.map +1 -1
  367. package/dist/types/migration/Document.d.ts +12 -31
  368. package/dist/types/migration/Document.d.ts.map +1 -1
  369. package/dist/types/migration/Document.js +10 -19
  370. package/dist/types/migration/Document.js.map +1 -1
  371. package/dist/types/model/contentRelationship.d.cts +5 -15
  372. package/dist/types/model/contentRelationship.d.cts.map +1 -1
  373. package/dist/types/model/contentRelationship.d.ts +5 -15
  374. package/dist/types/model/contentRelationship.d.ts.map +1 -1
  375. package/dist/types/model/customType.d.cts +6 -17
  376. package/dist/types/model/customType.d.cts.map +1 -1
  377. package/dist/types/model/customType.d.ts +6 -17
  378. package/dist/types/model/customType.d.ts.map +1 -1
  379. package/dist/types/model/image.d.cts.map +1 -1
  380. package/dist/types/model/image.d.ts.map +1 -1
  381. package/dist/types/model/linkToMedia.d.cts.map +1 -1
  382. package/dist/types/model/linkToMedia.d.ts.map +1 -1
  383. package/dist/types/model/range.d.cts +1 -3
  384. package/dist/types/model/range.d.cts.map +1 -1
  385. package/dist/types/model/range.d.ts +1 -3
  386. package/dist/types/model/range.d.ts.map +1 -1
  387. package/dist/types/model/separator.d.cts +1 -3
  388. package/dist/types/model/separator.d.cts.map +1 -1
  389. package/dist/types/model/separator.d.ts +1 -3
  390. package/dist/types/model/separator.d.ts.map +1 -1
  391. package/dist/types/model/sharedSliceVariation.d.cts.map +1 -1
  392. package/dist/types/model/sharedSliceVariation.d.ts.map +1 -1
  393. package/dist/types/model/slice.cjs.map +1 -1
  394. package/dist/types/model/slice.d.cts +1 -3
  395. package/dist/types/model/slice.d.cts.map +1 -1
  396. package/dist/types/model/slice.d.ts +1 -3
  397. package/dist/types/model/slice.d.ts.map +1 -1
  398. package/dist/types/model/slice.js.map +1 -1
  399. package/dist/types/model/sliceZone.cjs.map +1 -1
  400. package/dist/types/model/sliceZone.d.cts.map +1 -1
  401. package/dist/types/model/sliceZone.d.ts.map +1 -1
  402. package/dist/types/model/sliceZone.js.map +1 -1
  403. package/dist/types/model/types.cjs +1 -3
  404. package/dist/types/model/types.cjs.map +1 -1
  405. package/dist/types/model/types.d.cts +9 -31
  406. package/dist/types/model/types.d.cts.map +1 -1
  407. package/dist/types/model/types.d.ts +9 -31
  408. package/dist/types/model/types.d.ts.map +1 -1
  409. package/dist/types/model/types.js +1 -3
  410. package/dist/types/model/types.js.map +1 -1
  411. package/dist/types/value/color.d.cts +0 -1
  412. package/dist/types/value/color.d.cts.map +1 -1
  413. package/dist/types/value/color.d.ts +0 -1
  414. package/dist/types/value/color.d.ts.map +1 -1
  415. package/dist/types/value/contentRelationship.d.cts +3 -5
  416. package/dist/types/value/contentRelationship.d.cts.map +1 -1
  417. package/dist/types/value/contentRelationship.d.ts +3 -5
  418. package/dist/types/value/contentRelationship.d.ts.map +1 -1
  419. package/dist/types/value/date.d.cts +0 -1
  420. package/dist/types/value/date.d.cts.map +1 -1
  421. package/dist/types/value/date.d.ts +0 -1
  422. package/dist/types/value/date.d.ts.map +1 -1
  423. package/dist/types/value/document.d.cts +23 -50
  424. package/dist/types/value/document.d.cts.map +1 -1
  425. package/dist/types/value/document.d.ts +23 -50
  426. package/dist/types/value/document.d.ts.map +1 -1
  427. package/dist/types/value/embed.cjs +1 -1
  428. package/dist/types/value/embed.cjs.map +1 -1
  429. package/dist/types/value/embed.d.cts +28 -95
  430. package/dist/types/value/embed.d.cts.map +1 -1
  431. package/dist/types/value/embed.d.ts +28 -95
  432. package/dist/types/value/embed.d.ts.map +1 -1
  433. package/dist/types/value/embed.js +1 -1
  434. package/dist/types/value/embed.js.map +1 -1
  435. package/dist/types/value/geoPoint.d.cts +0 -1
  436. package/dist/types/value/geoPoint.d.cts.map +1 -1
  437. package/dist/types/value/geoPoint.d.ts +0 -1
  438. package/dist/types/value/geoPoint.d.ts.map +1 -1
  439. package/dist/types/value/group.d.cts.map +1 -1
  440. package/dist/types/value/group.d.ts.map +1 -1
  441. package/dist/types/value/image.d.cts +5 -8
  442. package/dist/types/value/image.d.cts.map +1 -1
  443. package/dist/types/value/image.d.ts +5 -8
  444. package/dist/types/value/image.d.ts.map +1 -1
  445. package/dist/types/value/integration.d.cts +0 -1
  446. package/dist/types/value/integration.d.cts.map +1 -1
  447. package/dist/types/value/integration.d.ts +0 -1
  448. package/dist/types/value/integration.d.ts.map +1 -1
  449. package/dist/types/value/keyText.d.cts +0 -1
  450. package/dist/types/value/keyText.d.cts.map +1 -1
  451. package/dist/types/value/keyText.d.ts +0 -1
  452. package/dist/types/value/keyText.d.ts.map +1 -1
  453. package/dist/types/value/link.cjs +1 -3
  454. package/dist/types/value/link.cjs.map +1 -1
  455. package/dist/types/value/link.d.cts +8 -12
  456. package/dist/types/value/link.d.cts.map +1 -1
  457. package/dist/types/value/link.d.ts +8 -12
  458. package/dist/types/value/link.d.ts.map +1 -1
  459. package/dist/types/value/link.js +1 -3
  460. package/dist/types/value/link.js.map +1 -1
  461. package/dist/types/value/linkToMedia.d.cts.map +1 -1
  462. package/dist/types/value/linkToMedia.d.ts.map +1 -1
  463. package/dist/types/value/number.d.cts +0 -1
  464. package/dist/types/value/number.d.cts.map +1 -1
  465. package/dist/types/value/number.d.ts +0 -1
  466. package/dist/types/value/number.d.ts.map +1 -1
  467. package/dist/types/value/richText.cjs.map +1 -1
  468. package/dist/types/value/richText.d.cts +26 -77
  469. package/dist/types/value/richText.d.cts.map +1 -1
  470. package/dist/types/value/richText.d.ts +26 -77
  471. package/dist/types/value/richText.d.ts.map +1 -1
  472. package/dist/types/value/richText.js.map +1 -1
  473. package/dist/types/value/select.d.cts +0 -1
  474. package/dist/types/value/select.d.cts.map +1 -1
  475. package/dist/types/value/select.d.ts +0 -1
  476. package/dist/types/value/select.d.ts.map +1 -1
  477. package/dist/types/value/sharedSliceVariation.d.cts +1 -3
  478. package/dist/types/value/sharedSliceVariation.d.cts.map +1 -1
  479. package/dist/types/value/sharedSliceVariation.d.ts +1 -3
  480. package/dist/types/value/sharedSliceVariation.d.ts.map +1 -1
  481. package/dist/types/value/slice.d.cts.map +1 -1
  482. package/dist/types/value/slice.d.ts.map +1 -1
  483. package/dist/types/value/sliceZone.d.cts +3 -4
  484. package/dist/types/value/sliceZone.d.cts.map +1 -1
  485. package/dist/types/value/sliceZone.d.ts +3 -4
  486. package/dist/types/value/sliceZone.d.ts.map +1 -1
  487. package/dist/types/value/table.d.cts +14 -63
  488. package/dist/types/value/table.d.cts.map +1 -1
  489. package/dist/types/value/table.d.ts +14 -63
  490. package/dist/types/value/table.d.ts.map +1 -1
  491. package/dist/types/value/timestamp.d.cts.map +1 -1
  492. package/dist/types/value/timestamp.d.ts.map +1 -1
  493. package/dist/types/value/title.d.cts +1 -1
  494. package/dist/types/value/title.d.cts.map +1 -1
  495. package/dist/types/value/title.d.ts +1 -1
  496. package/dist/types/value/title.d.ts.map +1 -1
  497. package/dist/types/value/types.d.cts +11 -24
  498. package/dist/types/value/types.d.cts.map +1 -1
  499. package/dist/types/value/types.d.ts +11 -24
  500. package/dist/types/value/types.d.ts.map +1 -1
  501. package/dist/types/webhook/apiUpdate.d.cts +1 -3
  502. package/dist/types/webhook/apiUpdate.d.cts.map +1 -1
  503. package/dist/types/webhook/apiUpdate.d.ts +1 -3
  504. package/dist/types/webhook/apiUpdate.d.ts.map +1 -1
  505. package/package.json +32 -34
  506. package/src/Client.ts +236 -399
  507. package/src/Migration.ts +80 -139
  508. package/src/WriteClient.ts +113 -174
  509. package/src/buildQueryURL.ts +68 -100
  510. package/src/cookie.ts +1 -4
  511. package/src/createClient.ts +12 -20
  512. package/src/createMigration.ts +8 -16
  513. package/src/createWriteClient.ts +11 -19
  514. package/src/errors.ts +5 -15
  515. package/src/filter.ts +79 -122
  516. package/src/getGraphQLEndpoint.ts +0 -3
  517. package/src/getRepositoryEndpoint.ts +4 -9
  518. package/src/getRepositoryName.ts +2 -5
  519. package/src/getToolbarSrc.ts +17 -20
  520. package/src/helpers/asDate.ts +13 -18
  521. package/src/helpers/asHTML.ts +55 -102
  522. package/src/helpers/asImagePixelDensitySrcSet.ts +29 -49
  523. package/src/helpers/asImageSrc.ts +8 -16
  524. package/src/helpers/asImageWidthSrcSet.ts +33 -52
  525. package/src/helpers/asLink.ts +26 -54
  526. package/src/helpers/asLinkAttrs.ts +14 -29
  527. package/src/helpers/asText.ts +15 -31
  528. package/src/helpers/documentToLinkField.ts +4 -15
  529. package/src/helpers/isFilled.ts +14 -51
  530. package/src/helpers/mapSliceZone.ts +42 -84
  531. package/src/index.ts +20 -68
  532. package/src/isRepositoryEndpoint.ts +3 -4
  533. package/src/isRepositoryName.ts +1 -2
  534. package/src/lib/devMsg.ts +6 -8
  535. package/src/lib/getOptionalLinkProperties.ts +5 -6
  536. package/src/lib/getPreviewCookie.ts +1 -3
  537. package/src/lib/isInternalURL.ts +0 -1
  538. package/src/lib/isMigrationValue.ts +9 -22
  539. package/src/lib/isValue.ts +9 -38
  540. package/src/lib/pLimit.ts +9 -16
  541. package/src/lib/request.ts +15 -40
  542. package/src/lib/resolveMigrationDocumentData.ts +8 -27
  543. package/src/lib/serializerHelpers.ts +9 -29
  544. package/src/lib/throttledWarn.ts +4 -8
  545. package/src/lib/validateAssetMetadata.ts +17 -43
  546. package/src/richtext/asText.ts +2 -8
  547. package/src/richtext/asTree.ts +8 -26
  548. package/src/richtext/composeSerializers.ts +5 -11
  549. package/src/richtext/serialize.ts +4 -12
  550. package/src/richtext/types.ts +13 -57
  551. package/src/richtext/wrapMapSerializer.ts +4 -8
  552. package/src/types/api/asset/asset.ts +26 -77
  553. package/src/types/api/asset/tag.ts +6 -18
  554. package/src/types/api/integration.ts +4 -10
  555. package/src/types/api/migration/document.ts +11 -27
  556. package/src/types/api/migration/release.ts +12 -0
  557. package/src/types/api/query.ts +10 -27
  558. package/src/types/api/ref.ts +6 -16
  559. package/src/types/api/release.ts +1 -2
  560. package/src/types/api/repository.ts +18 -45
  561. package/src/types/api/tags.ts +2 -3
  562. package/src/types/migration/Asset.ts +26 -82
  563. package/src/types/migration/ContentRelationship.ts +5 -12
  564. package/src/types/migration/Document.ts +26 -52
  565. package/src/types/migration/Link.ts +7 -9
  566. package/src/types/model/contentRelationship.ts +7 -20
  567. package/src/types/model/customType.ts +7 -21
  568. package/src/types/model/image.ts +4 -5
  569. package/src/types/model/linkToMedia.ts +1 -2
  570. package/src/types/model/range.ts +1 -3
  571. package/src/types/model/separator.ts +1 -3
  572. package/src/types/model/sharedSliceVariation.ts +4 -4
  573. package/src/types/model/slice.ts +7 -12
  574. package/src/types/model/sliceZone.ts +4 -11
  575. package/src/types/model/types.ts +10 -31
  576. package/src/types/value/color.ts +3 -3
  577. package/src/types/value/contentRelationship.ts +8 -13
  578. package/src/types/value/date.ts +1 -3
  579. package/src/types/value/document.ts +24 -52
  580. package/src/types/value/embed.ts +33 -80
  581. package/src/types/value/geoPoint.ts +6 -8
  582. package/src/types/value/group.ts +1 -4
  583. package/src/types/value/image.ts +10 -14
  584. package/src/types/value/integration.ts +0 -1
  585. package/src/types/value/keyText.ts +3 -3
  586. package/src/types/value/link.ts +14 -22
  587. package/src/types/value/linkToMedia.ts +2 -5
  588. package/src/types/value/number.ts +3 -3
  589. package/src/types/value/richText.ts +30 -82
  590. package/src/types/value/select.ts +0 -1
  591. package/src/types/value/sharedSliceVariation.ts +3 -11
  592. package/src/types/value/slice.ts +2 -8
  593. package/src/types/value/sliceZone.ts +4 -6
  594. package/src/types/value/table.ts +25 -64
  595. package/src/types/value/timestamp.ts +3 -2
  596. package/src/types/value/title.ts +16 -18
  597. package/src/types/value/types.ts +8 -21
  598. package/src/types/webhook/apiUpdate.ts +1 -3
@@ -1 +1 @@
1
- {"version":3,"file":"request.cjs","names":["pLimit"],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited\n * `fetch()` request (429 response code). The default value is only used if the\n * response does not include a `retry-after` header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/**\n * A record of URLs mapped to throttled task runners.\n */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/**\n * A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their\n * optional signal.\n */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tarrayBuffer(): Promise<ArrayBuffer>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\nasync function memoizeResponse(response: ResponseLike): Promise<ResponseLike> {\n\t// Deduplicated responses are shared across multiple callers. Calling\n\t// response.clone() on a shared response can cause backpressure hangs\n\t// in Node.js, so we buffer the body as an ArrayBuffer upfront instead.\n\tconst buffer = await response.arrayBuffer()\n\n\tconst memoized: ResponseLike = {\n\t\tok: response.ok,\n\t\tstatus: response.status,\n\t\theaders: response.headers,\n\t\turl: response.url,\n\t\ttext: async () => new TextDecoder().decode(buffer),\n\t\tjson: async () => JSON.parse(new TextDecoder().decode(buffer)),\n\t\tarrayBuffer: async () => buffer,\n\t\tblob: async () => new Blob([buffer]),\n\t\tclone: () => memoized,\n\t}\n\n\treturn memoized\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request\n * deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n *\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init)\n\t\t\t\t.then(memoizeResponse)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter)\n\t\t\t? DEFAULT_RETRY_AFTER\n\t\t\t: retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response\n}\n"],"mappings":";;;;;;;AAOA,MAAa,sBAAsB;;;;AAKnC,MAAM,oBAA4D,EAAE;;;;;AAMpE,MAAM,oBAEF,EAAE;AAuFN,eAAe,gBAAgB,UAA+C;CAI7E,MAAM,SAAS,MAAM,SAAS,aAAa;CAE3C,MAAM,WAAyB;EAC9B,IAAI,SAAS;EACb,QAAQ,SAAS;EACjB,SAAS,SAAS;EAClB,KAAK,SAAS;EACd,MAAM,YAAY,IAAI,aAAa,CAAC,OAAO,OAAO;EAClD,MAAM,YAAY,KAAK,MAAM,IAAI,aAAa,CAAC,OAAO,OAAO,CAAC;EAC9D,aAAa,YAAY;EACzB,MAAM,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC;EACpC,aAAa;EACb;AAED,QAAO;;;;;;;;;;;;AAaR,eAAsB,QACrB,KACA,MACA,SACwB;CACxB,MAAM,YAAY,IAAI,UAAU;CAEhC,IAAI;AAGJ,KAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAI,KAAM,MAAM;;AAMf,SAJgB,kBAAA,gBAAkB,IAAI,cAAtB,kBAAA,iBAAoCA,eAAAA,OAAO,EAC1D,UAAA,MACA,CAAC,SAEiB,QAAQ,WAAW,KAAK,CAAC;QACtC;;EAEN,MAAM,eAAA,wBAAc,kBAAkB,gBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAY,IAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAI,KAAM,OAAO;AACnE,MAAI,YACH,OAAM;OACA;AACN,SAAM,QAAQ,WAAW,KAAK,CAC5B,KAAK,gBAAgB,CACrB,cAAc;;AACd,KAAA,yBAAA,kBAAkB,gBAAA,QAAA,2BAAA,KAAA,KAAA,uBAAY,OAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAO,KAAM,OAAO;AAClD,UAAA,yBAAI,kBAAkB,gBAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAY,UAAS,EAC1C,QAAO,kBAAkB;KAEzB;AAEH,IADa,kBAAkB,eAAlB,kBAAkB,6BAAe,IAAI,KAAK,GACnD,IAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAI,KAAM,QAAQ,IAAI;;;CAI5B,MAAM,WAAW,MAAM;AAGvB,KAAI,SAAS,WAAW,KAAK;EAC5B,MAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,cAAc,CAAC;EAC9D,MAAM,qBAAqB,OAAO,MAAM,WAAW,GAChD,sBACA,aAAa;AAEhB,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,mBAAmB,CAAC;AAEvE,SAAO,QAAQ,KAAK,MAAM,QAAQ;;AAGnC,QAAO"}
1
+ {"version":3,"file":"request.cjs","names":["pLimit"],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited `fetch()` request (429\n * response code). The default value is only used if the response does not include a `retry-after`\n * header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/** A record of URLs mapped to throttled task runners. */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/** A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their optional signal. */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (input: string, init?: RequestInitLike) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/** A subset of RequestInit properties to configure a `fetch()` request. */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/** The HTTP method to use for the request. */\n\tmethod?: string\n\n\t/** The request body to send with the request. */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/** An object literal to set the `fetch()` request's headers. */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/** The minimum required properties from Response. */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tarrayBuffer(): Promise<ArrayBuffer>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/** The minimum required properties from Headers. */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\nasync function memoizeResponse(response: ResponseLike): Promise<ResponseLike> {\n\t// Deduplicated responses are shared across multiple callers. Calling\n\t// response.clone() on a shared response can cause backpressure hangs\n\t// in Node.js, so we buffer the body as an ArrayBuffer upfront instead.\n\tconst buffer = await response.arrayBuffer()\n\n\tconst memoized: ResponseLike = {\n\t\tok: response.ok,\n\t\tstatus: response.status,\n\t\theaders: response.headers,\n\t\turl: response.url,\n\t\ttext: async () => new TextDecoder().decode(buffer),\n\t\tjson: async () => JSON.parse(new TextDecoder().decode(buffer)),\n\t\tarrayBuffer: async () => buffer,\n\t\tblob: async () => new Blob([buffer]),\n\t\tclone: () => memoized,\n\t}\n\n\treturn memoized\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init)\n\t\t\t\t.then(memoizeResponse)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter) ? DEFAULT_RETRY_AFTER : retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response\n}\n"],"mappings":";;;;;;;AAOA,MAAa,sBAAsB;;AAGnC,MAAM,oBAA4D,EAAE;;AAGpE,MAAM,oBAEF,EAAE;AAuEN,eAAe,gBAAgB,UAA+C;CAI7E,MAAM,SAAS,MAAM,SAAS,aAAa;CAE3C,MAAM,WAAyB;EAC9B,IAAI,SAAS;EACb,QAAQ,SAAS;EACjB,SAAS,SAAS;EAClB,KAAK,SAAS;EACd,MAAM,YAAY,IAAI,aAAa,CAAC,OAAO,OAAO;EAClD,MAAM,YAAY,KAAK,MAAM,IAAI,aAAa,CAAC,OAAO,OAAO,CAAC;EAC9D,aAAa,YAAY;EACzB,MAAM,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC;EACpC,aAAa;EACb;AAED,QAAO;;;;;;;;;;AAWR,eAAsB,QACrB,KACA,MACA,SACwB;CACxB,MAAM,YAAY,IAAI,UAAU;CAEhC,IAAI;AAGJ,KAAI,MAAM,KAMT,QAJgB,kBAAkB,IAAI,cAAcA,eAAAA,OAAO,EAC1D,UAAU,qBACV,CAAC,QAEiB,QAAQ,WAAW,KAAK,CAAC;MACtC;EAEN,MAAM,cAAc,kBAAkB,YAAY,IAAI,MAAM,OAAO;AACnE,MAAI,YACH,OAAM;OACA;AACN,SAAM,QAAQ,WAAW,KAAK,CAC5B,KAAK,gBAAgB,CACrB,cAAc;AACd,sBAAkB,YAAY,OAAO,MAAM,OAAO;AAClD,QAAI,kBAAkB,YAAY,SAAS,EAC1C,QAAO,kBAAkB;KAEzB;AAEH,IADa,kBAAkB,+BAAe,IAAI,KAAK,EACnD,IAAI,MAAM,QAAQ,IAAI;;;CAI5B,MAAM,WAAW,MAAM;AAGvB,KAAI,SAAS,WAAW,KAAK;EAC5B,MAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,cAAc,CAAC;EAC9D,MAAM,qBAAqB,OAAO,MAAM,WAAW,GAAG,sBAAsB,aAAa;AAEzF,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,mBAAmB,CAAC;AAEvE,SAAO,QAAQ,KAAK,MAAM,QAAQ;;AAGnC,QAAO"}
@@ -6,27 +6,18 @@
6
6
  */
7
7
  type FetchLike = (input: string, init?: RequestInitLike) => Promise<ResponseLike>;
8
8
  /**
9
- * An object that allows you to abort a `fetch()` request if needed via an
10
- * `AbortController` object
9
+ * An object that allows you to abort a `fetch()` request if needed via an `AbortController` object
11
10
  *
12
11
  * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
13
12
  */
14
13
  type AbortSignalLike = any;
15
- /**
16
- * A subset of RequestInit properties to configure a `fetch()` request.
17
- */
14
+ /** A subset of RequestInit properties to configure a `fetch()` request. */
18
15
  interface RequestInitLike extends Pick<RequestInit, "cache"> {
19
- /**
20
- * The HTTP method to use for the request.
21
- */
16
+ /** The HTTP method to use for the request. */
22
17
  method?: string;
23
- /**
24
- * The request body to send with the request.
25
- */
18
+ /** The request body to send with the request. */
26
19
  body?: any | FormData | string;
27
- /**
28
- * An object literal to set the `fetch()` request's headers.
29
- */
20
+ /** An object literal to set the `fetch()` request's headers. */
30
21
  headers?: Record<string, string>;
31
22
  /**
32
23
  * An AbortSignal to set the `fetch()` request's signal.
@@ -36,9 +27,7 @@ interface RequestInitLike extends Pick<RequestInit, "cache"> {
36
27
  */
37
28
  signal?: AbortSignalLike;
38
29
  }
39
- /**
40
- * The minimum required properties from Response.
41
- */
30
+ /** The minimum required properties from Response. */
42
31
  interface ResponseLike {
43
32
  ok: boolean;
44
33
  status: number;
@@ -50,9 +39,7 @@ interface ResponseLike {
50
39
  blob(): Promise<Blob>;
51
40
  clone(): ResponseLike;
52
41
  }
53
- /**
54
- * The minimum required properties from Headers.
55
- */
42
+ /** The minimum required properties from Headers. */
56
43
  interface HeadersLike {
57
44
  get(name: string): string | null;
58
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.cts","names":[],"sources":["../../src/lib/request.ts"],"mappings":";;;;;;KA2BY,SAAA,IACX,KAAA,UACA,IAAA,GAAO,eAAA,KACH,OAAA,CAAQ,YAAA;;;;;AAab;;KAAY,eAAA;;;AAUZ;UAAiB,eAAA,SAAwB,IAAA,CAAK,WAAA;;;;EAI7C,MAAA;EAwBS;;;EAhBT,IAAA,SAAa,QAAA;EAZ2B;;;EAiBxC,OAAA,GAAU,MAAA;EALG;;;;;;EAgBb,MAAA,GAAS,eAAA;AAAA;;;;UAMO,YAAA;EAChB,EAAA;EACA,MAAA;EACA,OAAA,EAAS,WAAA;EACT,GAAA;EAEA,IAAA,IAAQ,OAAA;EACR,IAAA,IAAQ,OAAA;EACR,WAAA,IAAe,OAAA,CAAQ,WAAA;EACvB,IAAA,IAAQ,OAAA,CAAQ,IAAA;EAChB,KAAA,IAAS,YAAA;AAAA;;;;UAMO,WAAA;EAChB,GAAA,CAAI,IAAA;AAAA"}
1
+ {"version":3,"file":"request.d.cts","names":[],"sources":["../../src/lib/request.ts"],"mappings":";;;;;;KAsBY,SAAA,IAAa,KAAA,UAAe,IAAA,GAAO,eAAA,KAAoB,OAAA,CAAQ,YAAA;;;;;AAY3E;KAAY,eAAA;;UAQK,eAAA,SAAwB,IAAA,CAAK,WAAA;EARnB;EAU1B,MAAA;EAFgC;EAQhC,IAAA,SAAa,QAAA;EARgC;EAW7C,OAAA,GAAU,MAAA;EAAA;;;;;;EAWV,MAAA,GAAS,eAAA;AAAA;;UAIO,YAAA;EAChB,EAAA;EACA,MAAA;EACA,OAAA,EAAS,WAAA;EACT,GAAA;EAEA,IAAA,IAAQ,OAAA;EACR,IAAA,IAAQ,OAAA;EACR,WAAA,IAAe,OAAA,CAAQ,WAAA;EACvB,IAAA,IAAQ,OAAA,CAAQ,IAAA;EAChB,KAAA,IAAS,YAAA;AAAA;;UAIO,WAAA;EAChB,GAAA,CAAI,IAAA;AAAA"}
@@ -6,27 +6,18 @@
6
6
  */
7
7
  type FetchLike = (input: string, init?: RequestInitLike) => Promise<ResponseLike>;
8
8
  /**
9
- * An object that allows you to abort a `fetch()` request if needed via an
10
- * `AbortController` object
9
+ * An object that allows you to abort a `fetch()` request if needed via an `AbortController` object
11
10
  *
12
11
  * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
13
12
  */
14
13
  type AbortSignalLike = any;
15
- /**
16
- * A subset of RequestInit properties to configure a `fetch()` request.
17
- */
14
+ /** A subset of RequestInit properties to configure a `fetch()` request. */
18
15
  interface RequestInitLike extends Pick<RequestInit, "cache"> {
19
- /**
20
- * The HTTP method to use for the request.
21
- */
16
+ /** The HTTP method to use for the request. */
22
17
  method?: string;
23
- /**
24
- * The request body to send with the request.
25
- */
18
+ /** The request body to send with the request. */
26
19
  body?: any | FormData | string;
27
- /**
28
- * An object literal to set the `fetch()` request's headers.
29
- */
20
+ /** An object literal to set the `fetch()` request's headers. */
30
21
  headers?: Record<string, string>;
31
22
  /**
32
23
  * An AbortSignal to set the `fetch()` request's signal.
@@ -36,9 +27,7 @@ interface RequestInitLike extends Pick<RequestInit, "cache"> {
36
27
  */
37
28
  signal?: AbortSignalLike;
38
29
  }
39
- /**
40
- * The minimum required properties from Response.
41
- */
30
+ /** The minimum required properties from Response. */
42
31
  interface ResponseLike {
43
32
  ok: boolean;
44
33
  status: number;
@@ -50,9 +39,7 @@ interface ResponseLike {
50
39
  blob(): Promise<Blob>;
51
40
  clone(): ResponseLike;
52
41
  }
53
- /**
54
- * The minimum required properties from Headers.
55
- */
42
+ /** The minimum required properties from Headers. */
56
43
  interface HeadersLike {
57
44
  get(name: string): string | null;
58
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","names":[],"sources":["../../src/lib/request.ts"],"mappings":";;;;;;KA2BY,SAAA,IACX,KAAA,UACA,IAAA,GAAO,eAAA,KACH,OAAA,CAAQ,YAAA;;;;;AAab;;KAAY,eAAA;;;AAUZ;UAAiB,eAAA,SAAwB,IAAA,CAAK,WAAA;;;;EAI7C,MAAA;EAwBS;;;EAhBT,IAAA,SAAa,QAAA;EAZ2B;;;EAiBxC,OAAA,GAAU,MAAA;EALG;;;;;;EAgBb,MAAA,GAAS,eAAA;AAAA;;;;UAMO,YAAA;EAChB,EAAA;EACA,MAAA;EACA,OAAA,EAAS,WAAA;EACT,GAAA;EAEA,IAAA,IAAQ,OAAA;EACR,IAAA,IAAQ,OAAA;EACR,WAAA,IAAe,OAAA,CAAQ,WAAA;EACvB,IAAA,IAAQ,OAAA,CAAQ,IAAA;EAChB,KAAA,IAAS,YAAA;AAAA;;;;UAMO,WAAA;EAChB,GAAA,CAAI,IAAA;AAAA"}
1
+ {"version":3,"file":"request.d.ts","names":[],"sources":["../../src/lib/request.ts"],"mappings":";;;;;;KAsBY,SAAA,IAAa,KAAA,UAAe,IAAA,GAAO,eAAA,KAAoB,OAAA,CAAQ,YAAA;;;;;AAY3E;KAAY,eAAA;;UAQK,eAAA,SAAwB,IAAA,CAAK,WAAA;EARnB;EAU1B,MAAA;EAFgC;EAQhC,IAAA,SAAa,QAAA;EARgC;EAW7C,OAAA,GAAU,MAAA;EAAA;;;;;;EAWV,MAAA,GAAS,eAAA;AAAA;;UAIO,YAAA;EAChB,EAAA;EACA,MAAA;EACA,OAAA,EAAS,WAAA;EACT,GAAA;EAEA,IAAA,IAAQ,OAAA;EACR,IAAA,IAAQ,OAAA;EACR,WAAA,IAAe,OAAA,CAAQ,WAAA;EACvB,IAAA,IAAQ,OAAA,CAAQ,IAAA;EAChB,KAAA,IAAS,YAAA;AAAA;;UAIO,WAAA;EAChB,GAAA,CAAI,IAAA;AAAA"}
@@ -1,19 +1,14 @@
1
1
  import { pLimit } from "./pLimit.js";
2
2
  //#region src/lib/request.ts
3
3
  /**
4
- * The default number of milliseconds to wait before retrying a rate-limited
5
- * `fetch()` request (429 response code). The default value is only used if the
6
- * response does not include a `retry-after` header.
4
+ * The default number of milliseconds to wait before retrying a rate-limited `fetch()` request (429
5
+ * response code). The default value is only used if the response does not include a `retry-after`
6
+ * header.
7
7
  */
8
8
  const DEFAULT_RETRY_AFTER = 1500;
9
- /**
10
- * A record of URLs mapped to throttled task runners.
11
- */
9
+ /** A record of URLs mapped to throttled task runners. */
12
10
  const THROTTLED_RUNNERS = {};
13
- /**
14
- * A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their
15
- * optional signal.
16
- */
11
+ /** A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their optional signal. */
17
12
  const DEDUPLICATED_JOBS = {};
18
13
  async function memoizeResponse(response) {
19
14
  const buffer = await response.arrayBuffer();
@@ -31,32 +26,26 @@ async function memoizeResponse(response) {
31
26
  return memoized;
32
27
  }
33
28
  /**
34
- * Makes an HTTP request with automatic retry for rate limits and request
35
- * deduplication.
29
+ * Makes an HTTP request with automatic retry for rate limits and request deduplication.
36
30
  *
37
31
  * @param url - The URL to request.
38
32
  * @param init - Fetch options.
39
33
  * @param fetchFn - The fetch function to use.
40
- *
41
34
  * @returns The response from the fetch request.
42
35
  */
43
36
  async function request(url, init, fetchFn) {
44
37
  const stringURL = url.toString();
45
38
  let job;
46
- if (init === null || init === void 0 ? void 0 : init.body) {
47
- var _url$hostname;
48
- job = (THROTTLED_RUNNERS[_url$hostname = url.hostname] || (THROTTLED_RUNNERS[_url$hostname] = pLimit({ interval: 1500 })))(() => fetchFn(stringURL, init));
49
- } else {
50
- var _DEDUPLICATED_JOBS$st;
51
- const existingJob = (_DEDUPLICATED_JOBS$st = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st === void 0 ? void 0 : _DEDUPLICATED_JOBS$st.get(init === null || init === void 0 ? void 0 : init.signal);
39
+ if (init?.body) job = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({ interval: DEFAULT_RETRY_AFTER }))(() => fetchFn(stringURL, init));
40
+ else {
41
+ const existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal);
52
42
  if (existingJob) job = existingJob;
53
43
  else {
54
44
  job = fetchFn(stringURL, init).then(memoizeResponse).finally(() => {
55
- var _DEDUPLICATED_JOBS$st2, _DEDUPLICATED_JOBS$st3;
56
- (_DEDUPLICATED_JOBS$st2 = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st2 === void 0 || _DEDUPLICATED_JOBS$st2.delete(init === null || init === void 0 ? void 0 : init.signal);
57
- if (((_DEDUPLICATED_JOBS$st3 = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st3 === void 0 ? void 0 : _DEDUPLICATED_JOBS$st3.size) === 0) delete DEDUPLICATED_JOBS[stringURL];
45
+ DEDUPLICATED_JOBS[stringURL]?.delete(init?.signal);
46
+ if (DEDUPLICATED_JOBS[stringURL]?.size === 0) delete DEDUPLICATED_JOBS[stringURL];
58
47
  });
59
- (DEDUPLICATED_JOBS[stringURL] || (DEDUPLICATED_JOBS[stringURL] = /* @__PURE__ */ new Map())).set(init === null || init === void 0 ? void 0 : init.signal, job);
48
+ (DEDUPLICATED_JOBS[stringURL] ||= /* @__PURE__ */ new Map()).set(init?.signal, job);
60
49
  }
61
50
  }
62
51
  const response = await job;
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","names":[],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited\n * `fetch()` request (429 response code). The default value is only used if the\n * response does not include a `retry-after` header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/**\n * A record of URLs mapped to throttled task runners.\n */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/**\n * A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their\n * optional signal.\n */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tarrayBuffer(): Promise<ArrayBuffer>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\nasync function memoizeResponse(response: ResponseLike): Promise<ResponseLike> {\n\t// Deduplicated responses are shared across multiple callers. Calling\n\t// response.clone() on a shared response can cause backpressure hangs\n\t// in Node.js, so we buffer the body as an ArrayBuffer upfront instead.\n\tconst buffer = await response.arrayBuffer()\n\n\tconst memoized: ResponseLike = {\n\t\tok: response.ok,\n\t\tstatus: response.status,\n\t\theaders: response.headers,\n\t\turl: response.url,\n\t\ttext: async () => new TextDecoder().decode(buffer),\n\t\tjson: async () => JSON.parse(new TextDecoder().decode(buffer)),\n\t\tarrayBuffer: async () => buffer,\n\t\tblob: async () => new Blob([buffer]),\n\t\tclone: () => memoized,\n\t}\n\n\treturn memoized\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request\n * deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n *\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init)\n\t\t\t\t.then(memoizeResponse)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter)\n\t\t\t? DEFAULT_RETRY_AFTER\n\t\t\t: retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response\n}\n"],"mappings":";;;;;;;AAOA,MAAa,sBAAsB;;;;AAKnC,MAAM,oBAA4D,EAAE;;;;;AAMpE,MAAM,oBAEF,EAAE;AAuFN,eAAe,gBAAgB,UAA+C;CAI7E,MAAM,SAAS,MAAM,SAAS,aAAa;CAE3C,MAAM,WAAyB;EAC9B,IAAI,SAAS;EACb,QAAQ,SAAS;EACjB,SAAS,SAAS;EAClB,KAAK,SAAS;EACd,MAAM,YAAY,IAAI,aAAa,CAAC,OAAO,OAAO;EAClD,MAAM,YAAY,KAAK,MAAM,IAAI,aAAa,CAAC,OAAO,OAAO,CAAC;EAC9D,aAAa,YAAY;EACzB,MAAM,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC;EACpC,aAAa;EACb;AAED,QAAO;;;;;;;;;;;;AAaR,eAAsB,QACrB,KACA,MACA,SACwB;CACxB,MAAM,YAAY,IAAI,UAAU;CAEhC,IAAI;AAGJ,KAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAI,KAAM,MAAM;;AAMf,SAJgB,kBAAA,gBAAkB,IAAI,cAAtB,kBAAA,iBAAoC,OAAO,EAC1D,UAAA,MACA,CAAC,SAEiB,QAAQ,WAAW,KAAK,CAAC;QACtC;;EAEN,MAAM,eAAA,wBAAc,kBAAkB,gBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAY,IAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAI,KAAM,OAAO;AACnE,MAAI,YACH,OAAM;OACA;AACN,SAAM,QAAQ,WAAW,KAAK,CAC5B,KAAK,gBAAgB,CACrB,cAAc;;AACd,KAAA,yBAAA,kBAAkB,gBAAA,QAAA,2BAAA,KAAA,KAAA,uBAAY,OAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAO,KAAM,OAAO;AAClD,UAAA,yBAAI,kBAAkB,gBAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAY,UAAS,EAC1C,QAAO,kBAAkB;KAEzB;AAEH,IADa,kBAAkB,eAAlB,kBAAkB,6BAAe,IAAI,KAAK,GACnD,IAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAI,KAAM,QAAQ,IAAI;;;CAI5B,MAAM,WAAW,MAAM;AAGvB,KAAI,SAAS,WAAW,KAAK;EAC5B,MAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,cAAc,CAAC;EAC9D,MAAM,qBAAqB,OAAO,MAAM,WAAW,GAChD,sBACA,aAAa;AAEhB,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,mBAAmB,CAAC;AAEvE,SAAO,QAAQ,KAAK,MAAM,QAAQ;;AAGnC,QAAO"}
1
+ {"version":3,"file":"request.js","names":[],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited `fetch()` request (429\n * response code). The default value is only used if the response does not include a `retry-after`\n * header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/** A record of URLs mapped to throttled task runners. */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/** A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their optional signal. */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (input: string, init?: RequestInitLike) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/** A subset of RequestInit properties to configure a `fetch()` request. */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/** The HTTP method to use for the request. */\n\tmethod?: string\n\n\t/** The request body to send with the request. */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/** An object literal to set the `fetch()` request's headers. */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/** The minimum required properties from Response. */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tarrayBuffer(): Promise<ArrayBuffer>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/** The minimum required properties from Headers. */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\nasync function memoizeResponse(response: ResponseLike): Promise<ResponseLike> {\n\t// Deduplicated responses are shared across multiple callers. Calling\n\t// response.clone() on a shared response can cause backpressure hangs\n\t// in Node.js, so we buffer the body as an ArrayBuffer upfront instead.\n\tconst buffer = await response.arrayBuffer()\n\n\tconst memoized: ResponseLike = {\n\t\tok: response.ok,\n\t\tstatus: response.status,\n\t\theaders: response.headers,\n\t\turl: response.url,\n\t\ttext: async () => new TextDecoder().decode(buffer),\n\t\tjson: async () => JSON.parse(new TextDecoder().decode(buffer)),\n\t\tarrayBuffer: async () => buffer,\n\t\tblob: async () => new Blob([buffer]),\n\t\tclone: () => memoized,\n\t}\n\n\treturn memoized\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init)\n\t\t\t\t.then(memoizeResponse)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter) ? DEFAULT_RETRY_AFTER : retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response\n}\n"],"mappings":";;;;;;;AAOA,MAAa,sBAAsB;;AAGnC,MAAM,oBAA4D,EAAE;;AAGpE,MAAM,oBAEF,EAAE;AAuEN,eAAe,gBAAgB,UAA+C;CAI7E,MAAM,SAAS,MAAM,SAAS,aAAa;CAE3C,MAAM,WAAyB;EAC9B,IAAI,SAAS;EACb,QAAQ,SAAS;EACjB,SAAS,SAAS;EAClB,KAAK,SAAS;EACd,MAAM,YAAY,IAAI,aAAa,CAAC,OAAO,OAAO;EAClD,MAAM,YAAY,KAAK,MAAM,IAAI,aAAa,CAAC,OAAO,OAAO,CAAC;EAC9D,aAAa,YAAY;EACzB,MAAM,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC;EACpC,aAAa;EACb;AAED,QAAO;;;;;;;;;;AAWR,eAAsB,QACrB,KACA,MACA,SACwB;CACxB,MAAM,YAAY,IAAI,UAAU;CAEhC,IAAI;AAGJ,KAAI,MAAM,KAMT,QAJgB,kBAAkB,IAAI,cAAc,OAAO,EAC1D,UAAU,qBACV,CAAC,QAEiB,QAAQ,WAAW,KAAK,CAAC;MACtC;EAEN,MAAM,cAAc,kBAAkB,YAAY,IAAI,MAAM,OAAO;AACnE,MAAI,YACH,OAAM;OACA;AACN,SAAM,QAAQ,WAAW,KAAK,CAC5B,KAAK,gBAAgB,CACrB,cAAc;AACd,sBAAkB,YAAY,OAAO,MAAM,OAAO;AAClD,QAAI,kBAAkB,YAAY,SAAS,EAC1C,QAAO,kBAAkB;KAEzB;AAEH,IADa,kBAAkB,+BAAe,IAAI,KAAK,EACnD,IAAI,MAAM,QAAQ,IAAI;;;CAI5B,MAAM,WAAW,MAAM;AAGvB,KAAI,SAAS,WAAW,KAAK;EAC5B,MAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,cAAc,CAAC;EAC9D,MAAM,qBAAqB,OAAO,MAAM,WAAW,GAAG,sBAAsB,aAAa;AAEzF,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,mBAAmB,CAAC;AAEvE,SAAO,QAAQ,KAAK,MAAM,QAAQ;;AAGnC,QAAO"}
@@ -1,16 +1,15 @@
1
1
  const require_richText = require("../types/value/richText.cjs");
2
2
  const require_link = require("../types/value/link.cjs");
3
+ const require_isFilled = require("../helpers/isFilled.cjs");
3
4
  const require_Asset = require("../types/migration/Asset.cjs");
4
5
  const require_Document = require("../types/migration/Document.cjs");
5
- const require_isFilled = require("../helpers/isFilled.cjs");
6
- const require_isMigrationValue = require("./isMigrationValue.cjs");
7
6
  const require_getOptionalLinkProperties = require("./getOptionalLinkProperties.cjs");
7
+ const require_isMigrationValue = require("./isMigrationValue.cjs");
8
8
  //#region src/lib/resolveMigrationDocumentData.ts
9
9
  /**
10
10
  * Resolves a migration content relationship to a content relationship field.
11
11
  *
12
12
  * @param relation - Content relationship to resolve.
13
- *
14
13
  * @returns Resolved content relationship field.
15
14
  */
16
15
  async function resolveMigrationContentRelationship(relation) {
@@ -42,22 +41,20 @@ async function resolveMigrationContentRelationship(relation) {
42
41
  * @param migrationAsset - Asset to resolve.
43
42
  * @param migration - Migration instance.
44
43
  * @param withThumbnails - Whether to include thumbnails.
45
- *
46
44
  * @returns Resolved image field.
47
45
  */
48
46
  const resolveMigrationImage = (image, migration, withThumbnails) => {
49
- var _migration$_assets$ge;
50
47
  const { id: master, ...thumbnails } = image instanceof require_Asset.PrismicMigrationAsset ? { id: image } : image;
51
- const asset = (_migration$_assets$ge = migration._assets.get(master.config.id)) === null || _migration$_assets$ge === void 0 ? void 0 : _migration$_assets$ge.asset;
48
+ const asset = migration._assets.get(master.config.id)?.asset;
52
49
  const maybeInitialField = master.originalField;
53
50
  if (asset) {
54
- const parameters = ((maybeInitialField === null || maybeInitialField === void 0 ? void 0 : maybeInitialField.url) || asset.url).split("?")[1];
51
+ const parameters = (maybeInitialField?.url || asset.url).split("?")[1];
55
52
  const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}`;
56
53
  const dimensions = {
57
54
  width: asset.width,
58
55
  height: asset.height
59
56
  };
60
- const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField === null || maybeInitialField === void 0 ? void 0 : maybeInitialField.edit : {
57
+ const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField?.edit : {
61
58
  x: 0,
62
59
  y: 0,
63
60
  zoom: 1,
@@ -85,7 +82,6 @@ const resolveMigrationImage = (image, migration, withThumbnails) => {
85
82
  *
86
83
  * @param rtImageNode - Migration rich text image node to resolve.
87
84
  * @param migration - Migration instance.
88
- *
89
85
  * @returns Resolved rich text image node.
90
86
  */
91
87
  const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
@@ -104,12 +100,10 @@ const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
104
100
  *
105
101
  * @param linkToMedia - Migration link to media to resolve.
106
102
  * @param migration - Migration instance.
107
- *
108
103
  * @returns Resolved link to media field.
109
104
  */
110
105
  const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
111
- var _migration$_assets$ge2;
112
- const asset = (_migration$_assets$ge2 = migration._assets.get(linkToMedia.id.config.id)) === null || _migration$_assets$ge2 === void 0 ? void 0 : _migration$_assets$ge2.asset;
106
+ const asset = migration._assets.get(linkToMedia.id.config.id)?.asset;
113
107
  const optionalLinkProperties = require_getOptionalLinkProperties.getOptionalLinkProperties(linkToMedia);
114
108
  if (asset) return {
115
109
  ...optionalLinkProperties,
@@ -122,12 +116,10 @@ const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
122
116
  };
123
117
  };
124
118
  /**
125
- * Resolves a migration document data to actual data ready to be sent to the
126
- * Migration API.
119
+ * Resolves a migration document data to actual data ready to be sent to the Migration API.
127
120
  *
128
121
  * @param input - Migration link to media to resolve.
129
122
  * @param migration - Migration instance.
130
- *
131
123
  * @returns Resolved data.
132
124
  */
133
125
  async function resolveMigrationDocumentData(input, migration) {
@@ -1 +1 @@
1
- {"version":3,"file":"resolveMigrationDocumentData.cjs","names":["PrismicMigrationDocument","LinkType","getOptionalLinkProperties","PrismicMigrationAsset","RichTextNodeType"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as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AAA,yBAAA,MAAsB,MAAM,CAC3B,QAAO,sBAAsB,OAAO,WAAW,KAAK;AAGrD,KAAA,yBAAA,YAA4B,MAAM,CACjC,QAAO,4BAA4B,OAAO,UAAU;AAGrD,KAAA,yBAAA,YAA4B,MAAM,CACjC,QAAO,4BAA4B,OAAO,UAAU;AAGrD,KAAI,OAAO,UAAU,WACpB,QAAO,MAAM,6BAA6B,MAAM,OAAO,EAAE,UAAU;AAIpE,KAAI,MAAM,QAAQ,MAAM,EAAE;EACzB,MAAM,MAAM,EAAE;AAEd,OAAK,MAAM,WAAW,MACrB,KAAI,KAAK,MAAM,6BAA6B,SAAS,UAAU,CAAC;AAGjE,SAAO,IAAI,OAAO,QAAQ;;AAG3B,KAAI,SAAS,OAAO,UAAU,UAAU;EACvC,MAAM,MAAoC,EAAE;AAE5C,OAAK,MAAM,OAAO,MACjB,KAAI,OAAO,MAAM,6BAChB,MAAM,MACN,UACA;AAGF,SAAO;;AAIR,QAAO"}
1
+ {"version":3,"file":"resolveMigrationDocumentData.cjs","names":["PrismicMigrationDocument","LinkType","getOptionalLinkProperties","PrismicMigrationAsset","RichTextNodeType"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\nimport type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\nimport * as isMigration from \"./isMigrationValue\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation ? getOptionalLinkProperties(relation) : undefined\n\n\tif (relation) {\n\t\tif (isMigration.contentRelationship(relation.id) || typeof relation.id !== \"string\") {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(rtImageNode.linkTo, migration)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMig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AAI,OAAO,UAAU,WACpB,QAAO,MAAM,6BAA6B,MAAM,OAAO,EAAE,UAAU;AAIpE,KAAI,MAAM,QAAQ,MAAM,EAAE;EACzB,MAAM,MAAM,EAAE;AAEd,OAAK,MAAM,WAAW,MACrB,KAAI,KAAK,MAAM,6BAA6B,SAAS,UAAU,CAAC;AAGjE,SAAO,IAAI,OAAO,QAAQ;;AAG3B,KAAI,SAAS,OAAO,UAAU,UAAU;EACvC,MAAM,MAAoC,EAAE;AAE5C,OAAK,MAAM,OAAO,MACjB,KAAI,OAAO,MAAM,6BAA6B,MAAM,MAA4B,UAAU;AAG3F,SAAO;;AAIR,QAAO"}
@@ -1,16 +1,15 @@
1
1
  import { RichTextNodeType } from "../types/value/richText.js";
2
2
  import { LinkType } from "../types/value/link.js";
3
+ import { link } from "../helpers/isFilled.js";
3
4
  import { PrismicMigrationAsset } from "../types/migration/Asset.js";
4
5
  import { PrismicMigrationDocument } from "../types/migration/Document.js";
5
- import { link } from "../helpers/isFilled.js";
6
- import { contentRelationship, image, linkToMedia, rtImageNode } from "./isMigrationValue.js";
7
6
  import { getOptionalLinkProperties } from "./getOptionalLinkProperties.js";
7
+ import { contentRelationship, image, linkToMedia, rtImageNode } from "./isMigrationValue.js";
8
8
  //#region src/lib/resolveMigrationDocumentData.ts
9
9
  /**
10
10
  * Resolves a migration content relationship to a content relationship field.
11
11
  *
12
12
  * @param relation - Content relationship to resolve.
13
- *
14
13
  * @returns Resolved content relationship field.
15
14
  */
16
15
  async function resolveMigrationContentRelationship(relation) {
@@ -42,22 +41,20 @@ async function resolveMigrationContentRelationship(relation) {
42
41
  * @param migrationAsset - Asset to resolve.
43
42
  * @param migration - Migration instance.
44
43
  * @param withThumbnails - Whether to include thumbnails.
45
- *
46
44
  * @returns Resolved image field.
47
45
  */
48
46
  const resolveMigrationImage = (image, migration, withThumbnails) => {
49
- var _migration$_assets$ge;
50
47
  const { id: master, ...thumbnails } = image instanceof PrismicMigrationAsset ? { id: image } : image;
51
- const asset = (_migration$_assets$ge = migration._assets.get(master.config.id)) === null || _migration$_assets$ge === void 0 ? void 0 : _migration$_assets$ge.asset;
48
+ const asset = migration._assets.get(master.config.id)?.asset;
52
49
  const maybeInitialField = master.originalField;
53
50
  if (asset) {
54
- const parameters = ((maybeInitialField === null || maybeInitialField === void 0 ? void 0 : maybeInitialField.url) || asset.url).split("?")[1];
51
+ const parameters = (maybeInitialField?.url || asset.url).split("?")[1];
55
52
  const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}`;
56
53
  const dimensions = {
57
54
  width: asset.width,
58
55
  height: asset.height
59
56
  };
60
- const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField === null || maybeInitialField === void 0 ? void 0 : maybeInitialField.edit : {
57
+ const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField?.edit : {
61
58
  x: 0,
62
59
  y: 0,
63
60
  zoom: 1,
@@ -85,7 +82,6 @@ const resolveMigrationImage = (image, migration, withThumbnails) => {
85
82
  *
86
83
  * @param rtImageNode - Migration rich text image node to resolve.
87
84
  * @param migration - Migration instance.
88
- *
89
85
  * @returns Resolved rich text image node.
90
86
  */
91
87
  const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
@@ -104,12 +100,10 @@ const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
104
100
  *
105
101
  * @param linkToMedia - Migration link to media to resolve.
106
102
  * @param migration - Migration instance.
107
- *
108
103
  * @returns Resolved link to media field.
109
104
  */
110
105
  const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
111
- var _migration$_assets$ge2;
112
- const asset = (_migration$_assets$ge2 = migration._assets.get(linkToMedia.id.config.id)) === null || _migration$_assets$ge2 === void 0 ? void 0 : _migration$_assets$ge2.asset;
106
+ const asset = migration._assets.get(linkToMedia.id.config.id)?.asset;
113
107
  const optionalLinkProperties = getOptionalLinkProperties(linkToMedia);
114
108
  if (asset) return {
115
109
  ...optionalLinkProperties,
@@ -122,12 +116,10 @@ const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
122
116
  };
123
117
  };
124
118
  /**
125
- * Resolves a migration document data to actual data ready to be sent to the
126
- * Migration API.
119
+ * Resolves a migration document data to actual data ready to be sent to the Migration API.
127
120
  *
128
121
  * @param input - Migration link to media to resolve.
129
122
  * @param migration - Migration instance.
130
- *
131
123
  * @returns Resolved data.
132
124
  */
133
125
  async function resolveMigrationDocumentData(input, migration) {
@@ -1 +1 @@
1
- {"version":3,"file":"resolveMigrationDocumentData.js","names":["isMigration.contentRelationship","isFilled.link","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,eAAsB,oCACrB,UACsE;AACtE,KAAI,OAAO,aAAa,WACvB,QAAO,oCAAoC,MAAM,UAAU,CAA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AAK,MAAM,WAAW,MACrB,KAAI,KAAK,MAAM,6BAA6B,SAAS,UAAU,CAAC;AAGjE,SAAO,IAAI,OAAO,QAAQ;;AAG3B,KAAI,SAAS,OAAO,UAAU,UAAU;EACvC,MAAM,MAAoC,EAAE;AAE5C,OAAK,MAAM,OAAO,MACjB,KAAI,OAAO,MAAM,6BAChB,MAAM,MACN,UACA;AAGF,SAAO;;AAIR,QAAO"}
1
+ {"version":3,"file":"resolveMigrationDocumentData.js","names":["isMigration.contentRelationship","isFilled.link","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\nimport type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\nimport * as isMigration from \"./isMigrationValue\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation ? getOptionalLinkProperties(relation) : undefined\n\n\tif (relation) {\n\t\tif (isMigration.contentRelationship(relation.id) || typeof relation.id !== \"string\") {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(rtImageNode.linkTo, migration)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(input[key as keyof typeof input], migration)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BA,eAAsB,oCACrB,UACsE;AACtE,KAAI,OAAO,aAAa,WACvB,QAAO,oCAAoC,MAAM,UAAU,CAAC;AAG7D,KAAI,oBAAoB,yBACvB,QAAO,SAAS,SAAS,KACtB;EAAE,WAAW,SAAS;EAAU,IAAI,SAAS,SAAS;EAAI,GAC1D,EAAE,WAAW,SAAS,KAAK;CAG/B,MAAM,y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../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { RichTextMapSerializer } from \"../richtext/types\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTAnyNode } from \"../types/value/richText\"\n\nimport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLStrictRichTextMapSerializer,\n} from \"../helpers/asHTML\"\nimport type { LinkResolverFunction } from \"../helpers/asLink\"\nimport { asLink } from \"../helpers/asLink\"\n\nimport { escapeHTML } from \"./escapeHTML\"\n\ntype Attributes = Record<string, string | boolean | null | undefined>\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes }\n\n\t// Respect `ltr` and `rtl` direction\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\t_attributes.dir = node.direction\n\t}\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label\n\t}\n\n\tconst result = []\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key]\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key)\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\")\n\t}\n\n\treturn result.join(\" \")\n}\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {}\n}\n\nexport const serializeStandardTag = <\n\tBlockType extends keyof RichTextMapSerializer<string>,\n>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(\n\t\t\tnode,\n\t\t\tgeneralAttributes,\n\t\t)}>${children}</${tag}>`\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n}\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(\n\t\t\tnode.text,\n\t\t)}</pre>`\n\t}\n}\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t}\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`\n\t}\n}\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t}\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`\n\t}\n}\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t}\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url\n\t\t\tattributes.target = node.data.target\n\t\t\tattributes.rel = \"noopener noreferrer\"\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver })\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`\n\t}\n}\n\nexport const serializeSpan = (): NonNullable<\n\tHTMLStrictRichTextMapSerializer[\"span\"]\n> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\"\n\t}\n}\n"],"mappings":";;;;AAcA,MAAM,oBAAoB,MAAiB,eAAmC;CAC7E,MAAM,cAAc,EAAE,GAAG,YAAY;AAGrC,KAAI,eAAe,QAAQ,KAAK,cAAc,MAC7C,aAAY,MAAM,KAAK;AAIxB,KAAI,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GACV,KAAK;GACL,CAAC;AAGH,SAAO,wBAAwB,SAAS;;;AAI1C,MAAa,kBACZ,0BAC2D;CAC3D,MAAM,oBAAoB,qBAAqB,sBAAsB;AAErE,SAAQ,EAAE,WAAW;AAQpB,SAAO,OAAO,iBAAiB,MAPZ;GAClB,GAAG;IACF,gBAAgB,KAAK,OAAO;IAC5B,qBAAqB,KAAK,OAAO;IACjC,yBAAyB,KAAK,OAAO;GACtC,CAE+C,CAAC,GAAG,KAAK,OAAO,KAAK;;;AAIvE,MAAa,sBACZ,cAIA,0BAC+D;CAC/D,MAAM,oBAAoB,qBAAqB,sBAAsB;AAErE,SAAQ,EAAE,MAAM,eAAuB;EACtC,MAAM,aAAa,EAClB,GAAG,mBACH;AAED,MAAI,KAAK,KAAK,cAAcC,aAAAA,SAAS,KAAK;AACzC,cAAW,OAAO,KAAK,KAAK;AAC5B,cAAW,SAAS,KAAK,KAAK;AAC9B,cAAW,MAAM;aACP,KAAK,KAAK,cAAcA,aAAAA,SAAS,SAC3C,YAAW,OAAOC,eAAAA,OAAO,KAAK,MAAM,EAAE,cAAc,CAAC;WAC3C,KAAK,KAAK,cAAcD,aAAAA,SAAS,MAC3C,YAAW,OAAO,KAAK,KAAK;AAG7B,SAAO,KAAK,iBAAiB,MAAM,WAAW,CAAC,GAAG,SAAS;;;AAI7D,MAAa,sBAER;AACJ,SAAQ,EAAE,WAAmB;AAC5B,SAAO,OAAOD,mBAAAA,WAAW,KAAK,CAAC,QAAQ,OAAO,SAAS,GAAG"}
1
+ {"version":3,"file":"serializerHelpers.cjs","names":["escapeHTML","LinkType","asLink"],"sources":["../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { HTMLRichTextMapSerializer, HTMLStrictRichTextMapSerializer } from \"../helpers/asHTML\"\nimport type { LinkResolverFunction } from \"../helpers/asLink\"\nimport { asLink } from \"../helpers/asLink\"\nimport type { RichTextMapSerializer } from \"../richtext/types\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTAnyNode } from \"../types/value/richText\"\nimport { escapeHTML } from \"./escapeHTML\"\n\ntype Attributes = Record<string, string | boolean | null | undefined>\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes }\n\n\t// Respect `ltr` and `rtl` direction\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\t_attributes.dir = node.direction\n\t}\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label\n\t}\n\n\tconst result = []\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key]\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key)\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\")\n\t}\n\n\treturn result.join(\" \")\n}\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {}\n}\n\nexport const serializeStandardTag = <BlockType extends keyof RichTextMapSerializer<string>>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(node, generalAttributes)}>${children}</${tag}>`\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n}\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(node.text)}</pre>`\n\t}\n}\n\nexport const serializeImage = (\n\tlinkResolver: LinkResolverFunction<string | null | undefined> | undefined | null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t}\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`\n\t}\n}\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t}\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`\n\t}\n}\n\nexport const serializeHyperlink = (\n\tlinkResolver: LinkResolverFunction<string | null | undefined> | undefined | null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t}\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url\n\t\t\tattributes.target = node.data.target\n\t\t\tattributes.rel = \"noopener noreferrer\"\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver })\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`\n\t}\n}\n\nexport const serializeSpan = (): NonNullable<HTMLStrictRichTextMapSerializer[\"span\"]> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\"\n\t}\n}\n"],"mappings":";;;;AASA,MAAM,oBAAoB,MAAiB,eAAmC;CAC7E,MAAM,cAAc,EAAE,GAAG,YAAY;AAGrC,KAAI,eAAe,QAAQ,KAAK,cAAc,MAC7C,aAAY,MAAM,KAAK;AAIxB,KAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,MACvD,aAAY,QAAQ,YAAY,QAC7B,GAAG,YAAY,MAAM,GAAG,KAAK,KAAK,UAClC,KAAK,KAAK;CAGd,MAAM,SAAS,EAAE;AAEjB,MAAK,MAAM,OAAO,aAAa;EAC9B,MAAM,QAAQ,YAAY;AAE1B,MAAI,MACH,KAAI,OAAO,UAAU,UACpB,QAAO,KAAK,IAAI;MAEhB,QAAO,KAAK,GAAG,IAAI,IAAIA,mBAAAA,WAAW,MAAM,CAAC,GAAG;;AAM/C,KAAI,OAA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