@prismicio/client 7.21.0-alpha.2 → 7.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/dist/Client.cjs +1262 -0
  2. package/dist/Client.cjs.map +1 -0
  3. package/dist/Client.d.ts +981 -0
  4. package/dist/Client.js +1262 -0
  5. package/dist/Client.js.map +1 -0
  6. package/dist/Migration.cjs +297 -0
  7. package/dist/Migration.cjs.map +1 -0
  8. package/dist/Migration.d.ts +213 -0
  9. package/dist/Migration.js +297 -0
  10. package/dist/Migration.js.map +1 -0
  11. package/dist/WriteClient.cjs +575 -0
  12. package/dist/WriteClient.cjs.map +1 -0
  13. package/dist/WriteClient.d.ts +281 -0
  14. package/dist/WriteClient.js +575 -0
  15. package/dist/WriteClient.js.map +1 -0
  16. package/dist/buildQueryURL.cjs +66 -0
  17. package/dist/buildQueryURL.cjs.map +1 -0
  18. package/dist/buildQueryURL.d.ts +217 -0
  19. package/dist/buildQueryURL.js +66 -0
  20. package/dist/buildQueryURL.js.map +1 -0
  21. package/dist/cookie.cjs +5 -0
  22. package/dist/cookie.cjs.map +1 -0
  23. package/dist/cookie.d.ts +5 -0
  24. package/dist/cookie.js +5 -0
  25. package/dist/cookie.js.map +1 -0
  26. package/dist/createClient.cjs +6 -0
  27. package/dist/createClient.cjs.map +1 -0
  28. package/dist/createClient.d.ts +35 -0
  29. package/dist/createClient.js +6 -0
  30. package/dist/createClient.js.map +1 -0
  31. package/dist/createMigration.cjs +6 -0
  32. package/dist/createMigration.cjs.map +1 -0
  33. package/dist/createMigration.d.ts +24 -0
  34. package/dist/createMigration.js +6 -0
  35. package/dist/createMigration.js.map +1 -0
  36. package/dist/createWriteClient.cjs +6 -0
  37. package/dist/createWriteClient.cjs.map +1 -0
  38. package/dist/createWriteClient.d.ts +32 -0
  39. package/dist/createWriteClient.js +6 -0
  40. package/dist/createWriteClient.js.map +1 -0
  41. package/dist/errors/ForbiddenError.cjs +7 -0
  42. package/dist/errors/ForbiddenError.cjs.map +1 -0
  43. package/dist/errors/ForbiddenError.d.ts +11 -0
  44. package/dist/errors/ForbiddenError.js +7 -0
  45. package/dist/errors/ForbiddenError.js.map +1 -0
  46. package/dist/errors/InvalidDataError.cjs +7 -0
  47. package/dist/errors/InvalidDataError.cjs.map +1 -0
  48. package/dist/errors/InvalidDataError.d.ts +3 -0
  49. package/dist/errors/InvalidDataError.js +7 -0
  50. package/dist/errors/InvalidDataError.js.map +1 -0
  51. package/dist/errors/NotFoundError.cjs +7 -0
  52. package/dist/errors/NotFoundError.cjs.map +1 -0
  53. package/dist/errors/NotFoundError.d.ts +3 -0
  54. package/dist/errors/NotFoundError.js +7 -0
  55. package/dist/errors/NotFoundError.js.map +1 -0
  56. package/dist/errors/ParsingError.cjs +7 -0
  57. package/dist/errors/ParsingError.cjs.map +1 -0
  58. package/dist/errors/ParsingError.d.ts +14 -0
  59. package/dist/errors/ParsingError.js +7 -0
  60. package/dist/errors/ParsingError.js.map +1 -0
  61. package/dist/errors/PreviewTokenExpired.cjs +7 -0
  62. package/dist/errors/PreviewTokenExpired.cjs.map +1 -0
  63. package/dist/errors/PreviewTokenExpired.d.ts +8 -0
  64. package/dist/errors/PreviewTokenExpired.js +7 -0
  65. package/dist/errors/PreviewTokenExpired.js.map +1 -0
  66. package/dist/errors/PrismicError.cjs +13 -0
  67. package/dist/errors/PrismicError.cjs.map +1 -0
  68. package/dist/errors/PrismicError.d.ts +5 -0
  69. package/dist/errors/PrismicError.js +13 -0
  70. package/dist/errors/PrismicError.js.map +1 -0
  71. package/dist/errors/RefExpiredError.cjs +7 -0
  72. package/dist/errors/RefExpiredError.cjs.map +1 -0
  73. package/dist/errors/RefExpiredError.d.ts +8 -0
  74. package/dist/errors/RefExpiredError.js +7 -0
  75. package/dist/errors/RefExpiredError.js.map +1 -0
  76. package/dist/errors/RefNotFoundError.cjs +7 -0
  77. package/dist/errors/RefNotFoundError.cjs.map +1 -0
  78. package/dist/errors/RefNotFoundError.d.ts +8 -0
  79. package/dist/errors/RefNotFoundError.js +7 -0
  80. package/dist/errors/RefNotFoundError.js.map +1 -0
  81. package/dist/errors/RepositoryNotFoundError.cjs +7 -0
  82. package/dist/errors/RepositoryNotFoundError.cjs.map +1 -0
  83. package/dist/errors/RepositoryNotFoundError.d.ts +3 -0
  84. package/dist/errors/RepositoryNotFoundError.js +7 -0
  85. package/dist/errors/RepositoryNotFoundError.js.map +1 -0
  86. package/dist/filter.cjs +247 -0
  87. package/dist/filter.cjs.map +1 -0
  88. package/dist/filter.d.ts +209 -0
  89. package/dist/filter.js +247 -0
  90. package/dist/filter.js.map +1 -0
  91. package/dist/getGraphQLEndpoint.cjs +13 -0
  92. package/dist/getGraphQLEndpoint.cjs.map +1 -0
  93. package/dist/getGraphQLEndpoint.d.ts +10 -0
  94. package/dist/getGraphQLEndpoint.js +13 -0
  95. package/dist/getGraphQLEndpoint.js.map +1 -0
  96. package/dist/getRepositoryEndpoint.cjs +13 -0
  97. package/dist/getRepositoryEndpoint.cjs.map +1 -0
  98. package/dist/getRepositoryEndpoint.d.ts +19 -0
  99. package/dist/getRepositoryEndpoint.js +13 -0
  100. package/dist/getRepositoryEndpoint.js.map +1 -0
  101. package/dist/getRepositoryName.cjs +17 -0
  102. package/dist/getRepositoryName.cjs.map +1 -0
  103. package/dist/getRepositoryName.d.ts +12 -0
  104. package/dist/getRepositoryName.js +17 -0
  105. package/dist/getRepositoryName.js.map +1 -0
  106. package/dist/getToolbarSrc.cjs +13 -0
  107. package/dist/getToolbarSrc.cjs.map +1 -0
  108. package/dist/getToolbarSrc.d.ts +34 -0
  109. package/dist/getToolbarSrc.js +13 -0
  110. package/dist/getToolbarSrc.js.map +1 -0
  111. package/dist/helpers/asDate.cjs +14 -0
  112. package/dist/helpers/asDate.cjs.map +1 -0
  113. package/dist/helpers/asDate.d.ts +24 -0
  114. package/dist/helpers/asDate.js +14 -0
  115. package/dist/helpers/asDate.js.map +1 -0
  116. package/dist/helpers/asHTML.cjs +86 -0
  117. package/dist/helpers/asHTML.cjs.map +1 -0
  118. package/dist/helpers/asHTML.d.ts +149 -0
  119. package/dist/helpers/asHTML.js +86 -0
  120. package/dist/helpers/asHTML.js.map +1 -0
  121. package/dist/helpers/asImagePixelDensitySrcSet.cjs +21 -0
  122. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -0
  123. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +54 -0
  124. package/dist/helpers/asImagePixelDensitySrcSet.js +21 -0
  125. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -0
  126. package/dist/helpers/asImageSrc.cjs +13 -0
  127. package/dist/helpers/asImageSrc.cjs.map +1 -0
  128. package/dist/helpers/asImageSrc.d.ts +29 -0
  129. package/dist/helpers/asImageSrc.js +13 -0
  130. package/dist/helpers/asImageSrc.js.map +1 -0
  131. package/dist/helpers/asImageWidthSrcSet.cjs +45 -0
  132. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -0
  133. package/dist/helpers/asImageWidthSrcSet.d.ts +62 -0
  134. package/dist/helpers/asImageWidthSrcSet.js +45 -0
  135. package/dist/helpers/asImageWidthSrcSet.js.map +1 -0
  136. package/dist/helpers/asLink.cjs +47 -0
  137. package/dist/helpers/asLink.cjs.map +1 -0
  138. package/dist/helpers/asLink.d.ts +78 -0
  139. package/dist/helpers/asLink.js +47 -0
  140. package/dist/helpers/asLink.js.map +1 -0
  141. package/dist/helpers/asLinkAttrs.cjs +28 -0
  142. package/dist/helpers/asLinkAttrs.cjs.map +1 -0
  143. package/dist/helpers/asLinkAttrs.d.ts +47 -0
  144. package/dist/helpers/asLinkAttrs.js +28 -0
  145. package/dist/helpers/asLinkAttrs.js.map +1 -0
  146. package/dist/helpers/asText.cjs +21 -0
  147. package/dist/helpers/asText.cjs.map +1 -0
  148. package/dist/helpers/asText.d.ts +57 -0
  149. package/dist/helpers/asText.js +21 -0
  150. package/dist/helpers/asText.js.map +1 -0
  151. package/dist/helpers/documentToLinkField.cjs +26 -0
  152. package/dist/helpers/documentToLinkField.cjs.map +1 -0
  153. package/dist/helpers/documentToLinkField.d.ts +17 -0
  154. package/dist/helpers/documentToLinkField.js +26 -0
  155. package/dist/helpers/documentToLinkField.js.map +1 -0
  156. package/dist/helpers/isFilled.cjs +77 -0
  157. package/dist/helpers/isFilled.cjs.map +1 -0
  158. package/dist/helpers/isFilled.d.ts +191 -0
  159. package/dist/helpers/isFilled.js +77 -0
  160. package/dist/helpers/isFilled.js.map +1 -0
  161. package/dist/helpers/mapSliceZone.cjs +42 -0
  162. package/dist/helpers/mapSliceZone.cjs.map +1 -0
  163. package/dist/helpers/mapSliceZone.d.ts +136 -0
  164. package/dist/helpers/mapSliceZone.js +42 -0
  165. package/dist/helpers/mapSliceZone.js.map +1 -0
  166. package/dist/index.cjs +94 -3880
  167. package/dist/index.cjs.map +1 -1
  168. package/dist/index.d.ts +129 -4349
  169. package/dist/index.js +99 -0
  170. package/dist/index.js.map +1 -0
  171. package/dist/isRepositoryEndpoint.cjs +12 -0
  172. package/dist/isRepositoryEndpoint.cjs.map +1 -0
  173. package/dist/isRepositoryEndpoint.d.ts +10 -0
  174. package/dist/isRepositoryEndpoint.js +12 -0
  175. package/dist/isRepositoryEndpoint.js.map +1 -0
  176. package/dist/isRepositoryName.cjs +7 -0
  177. package/dist/isRepositoryName.cjs.map +1 -0
  178. package/dist/isRepositoryName.d.ts +9 -0
  179. package/dist/isRepositoryName.js +7 -0
  180. package/dist/isRepositoryName.js.map +1 -0
  181. package/dist/lib/appendFilters.cjs +11 -0
  182. package/dist/lib/appendFilters.cjs.map +1 -0
  183. package/dist/lib/appendFilters.d.ts +18 -0
  184. package/dist/lib/appendFilters.js +11 -0
  185. package/dist/lib/appendFilters.js.map +1 -0
  186. package/dist/lib/castArray.cjs +7 -0
  187. package/dist/lib/castArray.cjs.map +1 -0
  188. package/dist/lib/castArray.d.ts +12 -0
  189. package/dist/lib/castArray.js +7 -0
  190. package/dist/lib/castArray.js.map +1 -0
  191. package/dist/lib/castThunk.cjs +7 -0
  192. package/dist/lib/castThunk.cjs.map +1 -0
  193. package/dist/lib/castThunk.d.ts +11 -0
  194. package/dist/lib/castThunk.js +7 -0
  195. package/dist/lib/castThunk.js.map +1 -0
  196. package/dist/lib/devMsg.cjs +8 -0
  197. package/dist/lib/devMsg.cjs.map +1 -0
  198. package/dist/lib/devMsg.d.ts +16 -0
  199. package/dist/lib/devMsg.js +8 -0
  200. package/dist/lib/devMsg.js.map +1 -0
  201. package/dist/lib/escapeHTML.cjs +43 -0
  202. package/dist/lib/escapeHTML.cjs.map +1 -0
  203. package/dist/lib/escapeHTML.d.ts +1 -0
  204. package/dist/lib/escapeHTML.js +43 -0
  205. package/dist/lib/escapeHTML.js.map +1 -0
  206. package/dist/lib/everyTagFilter.cjs +9 -0
  207. package/dist/lib/everyTagFilter.cjs.map +1 -0
  208. package/dist/lib/everyTagFilter.d.ts +9 -0
  209. package/dist/lib/everyTagFilter.js +9 -0
  210. package/dist/lib/everyTagFilter.js.map +1 -0
  211. package/dist/lib/findMasterRef.cjs +8 -0
  212. package/dist/lib/findMasterRef.cjs.map +1 -0
  213. package/dist/lib/findMasterRef.d.ts +11 -0
  214. package/dist/lib/findMasterRef.js +8 -0
  215. package/dist/lib/findMasterRef.js.map +1 -0
  216. package/dist/lib/findRef.cjs +12 -0
  217. package/dist/lib/findRef.cjs.map +1 -0
  218. package/dist/lib/findRef.d.ts +14 -0
  219. package/dist/lib/findRef.js +12 -0
  220. package/dist/lib/findRef.js.map +1 -0
  221. package/dist/lib/findRefByID.cjs +8 -0
  222. package/dist/lib/findRefByID.cjs.map +1 -0
  223. package/dist/lib/findRefByID.d.ts +12 -0
  224. package/dist/lib/findRefByID.js +8 -0
  225. package/dist/lib/findRefByID.js.map +1 -0
  226. package/dist/lib/findRefByLabel.cjs +8 -0
  227. package/dist/lib/findRefByLabel.cjs.map +1 -0
  228. package/dist/lib/findRefByLabel.d.ts +12 -0
  229. package/dist/lib/findRefByLabel.js +8 -0
  230. package/dist/lib/findRefByLabel.js.map +1 -0
  231. package/dist/lib/getOptionalLinkProperties.cjs +14 -0
  232. package/dist/lib/getOptionalLinkProperties.cjs.map +1 -0
  233. package/dist/lib/getOptionalLinkProperties.d.ts +12 -0
  234. package/dist/lib/getOptionalLinkProperties.js +14 -0
  235. package/dist/lib/getOptionalLinkProperties.js.map +1 -0
  236. package/dist/lib/getPreviewCookie.cjs +21 -0
  237. package/dist/lib/getPreviewCookie.cjs.map +1 -0
  238. package/dist/lib/getPreviewCookie.d.ts +9 -0
  239. package/dist/lib/getPreviewCookie.js +21 -0
  240. package/dist/lib/getPreviewCookie.js.map +1 -0
  241. package/dist/lib/isInternalURL.cjs +9 -0
  242. package/dist/lib/isInternalURL.cjs.map +1 -0
  243. package/dist/lib/isInternalURL.d.ts +8 -0
  244. package/dist/lib/isInternalURL.js +9 -0
  245. package/dist/lib/isInternalURL.js.map +1 -0
  246. package/dist/lib/isMigrationValue.cjs +24 -0
  247. package/dist/lib/isMigrationValue.cjs.map +1 -0
  248. package/dist/lib/isMigrationValue.d.ts +71 -0
  249. package/dist/lib/isMigrationValue.js +24 -0
  250. package/dist/lib/isMigrationValue.js.map +1 -0
  251. package/dist/lib/isValue.cjs +53 -0
  252. package/dist/lib/isValue.cjs.map +1 -0
  253. package/dist/lib/isValue.d.ts +78 -0
  254. package/dist/lib/isValue.js +53 -0
  255. package/dist/lib/isValue.js.map +1 -0
  256. package/dist/lib/minifyGraphQLQuery.cjs +7 -0
  257. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
  258. package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
  259. package/dist/lib/minifyGraphQLQuery.js +7 -0
  260. package/dist/lib/minifyGraphQLQuery.js.map +1 -0
  261. package/dist/lib/pLimit.cjs +48 -0
  262. package/dist/lib/pLimit.cjs.map +1 -0
  263. package/dist/lib/pLimit.d.ts +22 -0
  264. package/dist/lib/pLimit.js +48 -0
  265. package/dist/lib/pLimit.js.map +1 -0
  266. package/dist/lib/request.cjs +41 -0
  267. package/dist/lib/request.cjs.map +1 -0
  268. package/dist/lib/request.d.ts +73 -0
  269. package/dist/lib/request.js +41 -0
  270. package/dist/lib/request.js.map +1 -0
  271. package/dist/lib/resolveMigrationDocumentData.cjs +132 -0
  272. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -0
  273. package/dist/lib/resolveMigrationDocumentData.d.ts +54 -0
  274. package/dist/lib/resolveMigrationDocumentData.js +132 -0
  275. package/dist/lib/resolveMigrationDocumentData.js.map +1 -0
  276. package/dist/lib/serializerHelpers.cjs +113 -0
  277. package/dist/lib/serializerHelpers.cjs.map +1 -0
  278. package/dist/lib/serializerHelpers.d.ts +9 -0
  279. package/dist/lib/serializerHelpers.js +113 -0
  280. package/dist/lib/serializerHelpers.js.map +1 -0
  281. package/dist/lib/someTagsFilter.cjs +9 -0
  282. package/dist/lib/someTagsFilter.cjs.map +1 -0
  283. package/dist/lib/someTagsFilter.d.ts +9 -0
  284. package/dist/lib/someTagsFilter.js +9 -0
  285. package/dist/lib/someTagsFilter.js.map +1 -0
  286. package/dist/lib/throttledLog.cjs +17 -0
  287. package/dist/lib/throttledLog.cjs.map +1 -0
  288. package/dist/lib/throttledLog.d.ts +15 -0
  289. package/dist/lib/throttledLog.js +17 -0
  290. package/dist/lib/throttledLog.js.map +1 -0
  291. package/dist/lib/typeFilter.cjs +8 -0
  292. package/dist/lib/typeFilter.cjs.map +1 -0
  293. package/dist/lib/typeFilter.d.ts +8 -0
  294. package/dist/lib/typeFilter.js +8 -0
  295. package/dist/lib/typeFilter.js.map +1 -0
  296. package/dist/lib/validateAssetMetadata.cjs +28 -0
  297. package/dist/lib/validateAssetMetadata.cjs.map +1 -0
  298. package/dist/lib/validateAssetMetadata.d.ts +10 -0
  299. package/dist/lib/validateAssetMetadata.js +28 -0
  300. package/dist/lib/validateAssetMetadata.js.map +1 -0
  301. package/dist/package.json.cjs +7 -0
  302. package/dist/package.json.cjs.map +1 -0
  303. package/dist/package.json.js +7 -0
  304. package/dist/package.json.js.map +1 -0
  305. package/dist/richtext/asText.cjs +13 -0
  306. package/dist/richtext/asText.cjs.map +1 -0
  307. package/dist/richtext/asText.d.ts +12 -0
  308. package/dist/richtext/asText.js +13 -0
  309. package/dist/richtext/asText.js.map +1 -0
  310. package/dist/richtext/asTree.cjs +123 -0
  311. package/dist/richtext/asTree.cjs.map +1 -0
  312. package/dist/richtext/asTree.d.ts +14 -0
  313. package/dist/richtext/asTree.js +123 -0
  314. package/dist/richtext/asTree.js.map +1 -0
  315. package/dist/richtext/composeSerializers.cjs +17 -0
  316. package/dist/richtext/composeSerializers.cjs.map +1 -0
  317. package/dist/richtext/composeSerializers.d.ts +16 -0
  318. package/dist/richtext/composeSerializers.js +17 -0
  319. package/dist/richtext/composeSerializers.js.map +1 -0
  320. package/dist/richtext/index.d.ts +7 -78
  321. package/dist/richtext/serialize.cjs +19 -0
  322. package/dist/richtext/serialize.cjs.map +1 -0
  323. package/dist/richtext/serialize.d.ts +19 -0
  324. package/dist/richtext/serialize.js +19 -0
  325. package/dist/richtext/serialize.js.map +1 -0
  326. package/dist/richtext/types.cjs +11 -0
  327. package/dist/richtext/types.cjs.map +1 -0
  328. package/dist/richtext/types.d.ts +71 -0
  329. package/dist/richtext/types.js +11 -0
  330. package/dist/richtext/types.js.map +1 -0
  331. package/dist/richtext/wrapMapSerializer.cjs +24 -0
  332. package/dist/richtext/wrapMapSerializer.cjs.map +1 -0
  333. package/dist/richtext/wrapMapSerializer.d.ts +15 -0
  334. package/dist/richtext/wrapMapSerializer.js +24 -0
  335. package/dist/richtext/wrapMapSerializer.js.map +1 -0
  336. package/dist/richtext.cjs +15 -0
  337. package/dist/richtext.cjs.map +1 -0
  338. package/dist/richtext.js +15 -0
  339. package/dist/richtext.js.map +1 -0
  340. package/dist/types/api/asset/asset.d.ts +177 -0
  341. package/dist/types/api/asset/tag.d.ts +53 -0
  342. package/dist/types/api/integration.d.ts +28 -0
  343. package/dist/types/api/migration/document.d.ts +60 -0
  344. package/dist/types/api/query.d.ts +43 -0
  345. package/dist/types/api/ref.d.ts +32 -0
  346. package/dist/types/api/release.d.ts +11 -0
  347. package/dist/types/api/repository.d.ts +109 -0
  348. package/dist/types/api/tags.d.ts +9 -0
  349. package/dist/types/migration/Asset.cjs +30 -0
  350. package/dist/types/migration/Asset.cjs.map +1 -0
  351. package/dist/types/migration/Asset.d.ts +108 -0
  352. package/dist/types/migration/Asset.js +30 -0
  353. package/dist/types/migration/Asset.js.map +1 -0
  354. package/dist/types/migration/ContentRelationship.d.ts +16 -0
  355. package/dist/types/migration/Document.cjs +44 -0
  356. package/dist/types/migration/Document.cjs.map +1 -0
  357. package/dist/types/migration/Document.d.ts +94 -0
  358. package/dist/types/migration/Document.js +44 -0
  359. package/dist/types/migration/Document.js.map +1 -0
  360. package/dist/types/migration/Link.d.ts +19 -0
  361. package/dist/types/model/boolean.d.ts +15 -0
  362. package/dist/types/model/color.d.ts +13 -0
  363. package/dist/types/model/contentRelationship.d.ts +53 -0
  364. package/dist/types/model/customType.d.ts +48 -0
  365. package/dist/types/model/date.d.ts +14 -0
  366. package/dist/types/model/embed.d.ts +13 -0
  367. package/dist/types/model/geoPoint.d.ts +12 -0
  368. package/dist/types/model/group.d.ts +23 -0
  369. package/dist/types/model/image.d.ts +31 -0
  370. package/dist/types/model/integration.d.ts +14 -0
  371. package/dist/types/model/keyText.d.ts +13 -0
  372. package/dist/types/model/link.cjs +9 -0
  373. package/dist/types/model/link.cjs.map +1 -0
  374. package/dist/types/model/link.d.ts +28 -0
  375. package/dist/types/model/link.js +9 -0
  376. package/dist/types/model/link.js.map +1 -0
  377. package/dist/types/model/linkToMedia.d.ts +17 -0
  378. package/dist/types/model/number.d.ts +15 -0
  379. package/dist/types/model/range.d.ts +14 -0
  380. package/dist/types/model/richText.d.ts +37 -0
  381. package/dist/types/model/select.d.ts +18 -0
  382. package/dist/types/model/separator.d.ts +10 -0
  383. package/dist/types/model/sharedSlice.d.ts +16 -0
  384. package/dist/types/model/sharedSliceVariation.d.ts +19 -0
  385. package/dist/types/model/slice.cjs +8 -0
  386. package/dist/types/model/slice.cjs.map +1 -0
  387. package/dist/types/model/slice.d.ts +33 -0
  388. package/dist/types/model/slice.js +8 -0
  389. package/dist/types/model/slice.js.map +1 -0
  390. package/dist/types/model/sliceZone.cjs +8 -0
  391. package/dist/types/model/sliceZone.cjs.map +1 -0
  392. package/dist/types/model/sliceZone.d.ts +41 -0
  393. package/dist/types/model/sliceZone.js +8 -0
  394. package/dist/types/model/sliceZone.js.map +1 -0
  395. package/dist/types/model/table.d.ts +12 -0
  396. package/dist/types/model/timestamp.d.ts +14 -0
  397. package/dist/types/model/title.d.ts +7 -0
  398. package/dist/types/model/types.cjs +39 -0
  399. package/dist/types/model/types.cjs.map +1 -0
  400. package/dist/types/model/types.d.ts +76 -0
  401. package/dist/types/model/types.js +39 -0
  402. package/dist/types/model/types.js.map +1 -0
  403. package/dist/types/model/uid.d.ts +13 -0
  404. package/dist/types/value/boolean.d.ts +6 -0
  405. package/dist/types/value/color.d.ts +9 -0
  406. package/dist/types/value/contentRelationship.d.ts +31 -0
  407. package/dist/types/value/date.d.ts +9 -0
  408. package/dist/types/value/document.d.ts +114 -0
  409. package/dist/types/value/embed.cjs +10 -0
  410. package/dist/types/value/embed.cjs.map +1 -0
  411. package/dist/types/value/embed.d.ts +168 -0
  412. package/dist/types/value/embed.js +10 -0
  413. package/dist/types/value/embed.js.map +1 -0
  414. package/dist/types/value/geoPoint.d.ts +12 -0
  415. package/dist/types/value/group.d.ts +13 -0
  416. package/dist/types/value/image.d.ts +47 -0
  417. package/dist/types/value/integration.d.ts +16 -0
  418. package/dist/types/value/keyText.d.ts +9 -0
  419. package/dist/types/value/link.cjs +10 -0
  420. package/dist/types/value/link.cjs.map +1 -0
  421. package/dist/types/value/link.d.ts +68 -0
  422. package/dist/types/value/link.js +10 -0
  423. package/dist/types/value/link.js.map +1 -0
  424. package/dist/types/value/linkToMedia.d.ts +28 -0
  425. package/dist/types/value/number.d.ts +9 -0
  426. package/dist/types/value/richText.cjs +25 -0
  427. package/dist/types/value/richText.cjs.map +1 -0
  428. package/dist/types/value/richText.d.ts +215 -0
  429. package/dist/types/value/richText.js +25 -0
  430. package/dist/types/value/richText.js.map +1 -0
  431. package/dist/types/value/select.d.ts +10 -0
  432. package/dist/types/value/sharedSlice.d.ts +11 -0
  433. package/dist/types/value/sharedSliceVariation.d.ts +10 -0
  434. package/dist/types/value/slice.d.ts +13 -0
  435. package/dist/types/value/sliceZone.d.ts +12 -0
  436. package/dist/types/value/table.d.ts +91 -0
  437. package/dist/types/value/timestamp.d.ts +8 -0
  438. package/dist/types/value/title.d.ts +12 -0
  439. package/dist/types/value/types.d.ts +58 -0
  440. package/dist/types/webhook/apiUpdate.d.ts +52 -0
  441. package/dist/types/webhook/testTrigger.d.ts +9 -0
  442. package/dist/types/webhook/types.cjs +8 -0
  443. package/dist/types/webhook/types.cjs.map +1 -0
  444. package/dist/types/webhook/types.d.ts +18 -0
  445. package/dist/types/webhook/types.js +8 -0
  446. package/dist/types/webhook/types.js.map +1 -0
  447. package/package.json +34 -11
  448. package/src/WriteClient.ts +21 -32
  449. package/src/index.ts +1 -0
  450. package/src/types/model/contentRelationship.ts +1 -0
  451. package/dist/index.d.cts +0 -4424
  452. package/dist/index.d.mts +0 -4424
  453. package/dist/index.mjs +0 -3837
  454. package/dist/index.mjs.map +0 -1
  455. package/dist/richtext/index.cjs +0 -244
  456. package/dist/richtext/index.cjs.map +0 -1
  457. package/dist/richtext/index.d.cts +0 -78
  458. package/dist/richtext/index.d.mts +0 -78
  459. package/dist/richtext/index.mjs +0 -237
  460. package/dist/richtext/index.mjs.map +0 -1
  461. package/dist/shared/client.TSGr56lO.d.cts +0 -899
  462. package/dist/shared/client.TSGr56lO.d.mts +0 -899
  463. package/dist/shared/client.TSGr56lO.d.ts +0 -899
@@ -0,0 +1,132 @@
1
+ import { PrismicMigrationAsset } from "../types/migration/Asset.js";
2
+ import { PrismicMigrationDocument } from "../types/migration/Document.js";
3
+ import { LinkType } from "../types/value/link.js";
4
+ import { RichTextNodeType } from "../types/value/richText.js";
5
+ import { link } from "../helpers/isFilled.js";
6
+ import { contentRelationship, image, linkToMedia, rtImageNode } from "./isMigrationValue.js";
7
+ import { getOptionalLinkProperties } from "./getOptionalLinkProperties.js";
8
+ async function resolveMigrationContentRelationship(relation) {
9
+ if (typeof relation === "function") {
10
+ return resolveMigrationContentRelationship(await relation());
11
+ }
12
+ if (relation instanceof PrismicMigrationDocument) {
13
+ return relation.document.id ? { link_type: LinkType.Document, id: relation.document.id } : { link_type: LinkType.Any };
14
+ }
15
+ const optionalLinkProperties = relation && "link_type" in relation ? getOptionalLinkProperties(relation) : void 0;
16
+ if (relation) {
17
+ if (contentRelationship(relation.id) || typeof relation.id !== "string") {
18
+ return {
19
+ ...optionalLinkProperties,
20
+ ...await resolveMigrationContentRelationship(relation.id)
21
+ };
22
+ }
23
+ return {
24
+ ...optionalLinkProperties,
25
+ link_type: LinkType.Document,
26
+ id: relation.id
27
+ };
28
+ }
29
+ return {
30
+ ...optionalLinkProperties,
31
+ link_type: LinkType.Any
32
+ };
33
+ }
34
+ const resolveMigrationImage = (image2, migration, withThumbnails) => {
35
+ const { id: master, ...thumbnails } = image2 instanceof PrismicMigrationAsset ? { id: image2 } : image2;
36
+ const asset = migration._assets.get(master.config.id)?.asset;
37
+ const maybeInitialField = master.originalField;
38
+ if (asset) {
39
+ const parameters = (maybeInitialField?.url || asset.url).split("?")[1];
40
+ const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}`;
41
+ const dimensions = {
42
+ width: asset.width,
43
+ height: asset.height
44
+ };
45
+ const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField?.edit : { x: 0, y: 0, zoom: 1, background: "transparent" };
46
+ const alt = master.config.alt || asset.alt || null;
47
+ const resolvedThumbnails = {};
48
+ if (withThumbnails) {
49
+ for (const [name, thumbnail] of Object.entries(thumbnails)) {
50
+ const resolvedThumbnail = resolveMigrationImage(thumbnail, migration);
51
+ if (resolvedThumbnail) {
52
+ resolvedThumbnails[name] = resolvedThumbnail;
53
+ }
54
+ }
55
+ }
56
+ return {
57
+ id: asset.id,
58
+ url,
59
+ dimensions,
60
+ edit,
61
+ alt,
62
+ copyright: asset.credits || null,
63
+ ...resolvedThumbnails
64
+ };
65
+ }
66
+ };
67
+ const resolveMigrationRTImageNode = async (rtImageNode2, migration) => {
68
+ const image2 = resolveMigrationImage(rtImageNode2.id, migration);
69
+ if (image2) {
70
+ const linkTo = await resolveMigrationDocumentData(rtImageNode2.linkTo, migration);
71
+ return {
72
+ ...image2,
73
+ type: RichTextNodeType.image,
74
+ linkTo: link(linkTo) ? linkTo : void 0
75
+ };
76
+ }
77
+ };
78
+ const resolveMigrationLinkToMedia = (linkToMedia2, migration) => {
79
+ const asset = migration._assets.get(linkToMedia2.id.config.id)?.asset;
80
+ const optionalLinkProperties = getOptionalLinkProperties(linkToMedia2);
81
+ if (asset) {
82
+ return {
83
+ ...optionalLinkProperties,
84
+ id: asset.id,
85
+ link_type: LinkType.Media
86
+ };
87
+ }
88
+ return {
89
+ ...optionalLinkProperties,
90
+ link_type: LinkType.Any
91
+ };
92
+ };
93
+ async function resolveMigrationDocumentData(input, migration) {
94
+ if (contentRelationship(input)) {
95
+ return resolveMigrationContentRelationship(input);
96
+ }
97
+ if (image(input)) {
98
+ return resolveMigrationImage(input, migration, true);
99
+ }
100
+ if (linkToMedia(input)) {
101
+ return resolveMigrationLinkToMedia(input, migration);
102
+ }
103
+ if (rtImageNode(input)) {
104
+ return resolveMigrationRTImageNode(input, migration);
105
+ }
106
+ if (typeof input === "function") {
107
+ return await resolveMigrationDocumentData(await input(), migration);
108
+ }
109
+ if (Array.isArray(input)) {
110
+ const res = [];
111
+ for (const element of input) {
112
+ res.push(await resolveMigrationDocumentData(element, migration));
113
+ }
114
+ return res.filter(Boolean);
115
+ }
116
+ if (input && typeof input === "object") {
117
+ const res = {};
118
+ for (const key in input) {
119
+ res[key] = await resolveMigrationDocumentData(input[key], migration);
120
+ }
121
+ return res;
122
+ }
123
+ return input;
124
+ }
125
+ export {
126
+ resolveMigrationContentRelationship,
127
+ resolveMigrationDocumentData,
128
+ resolveMigrationImage,
129
+ resolveMigrationLinkToMedia,
130
+ resolveMigrationRTImageNode
131
+ };
132
+ //# sourceMappingURL=resolveMigrationDocumentData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveMigrationDocumentData.js","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"],"names":["isMigration.contentRelationship","image","rtImageNode","isFilled.link","linkToMedia","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"mappings":"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"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const link = require("../types/value/link.cjs");
4
+ const asLink = require("../helpers/asLink.cjs");
5
+ const escapeHTML = require("./escapeHTML.cjs");
6
+ const formatAttributes = (node, attributes) => {
7
+ const _attributes = { ...attributes };
8
+ if ("direction" in node && node.direction === "rtl") {
9
+ _attributes.dir = node.direction;
10
+ }
11
+ if ("data" in node && "label" in node.data && node.data.label) {
12
+ _attributes.class = _attributes.class ? `${_attributes.class} ${node.data.label}` : node.data.label;
13
+ }
14
+ const result = [];
15
+ for (const key in _attributes) {
16
+ const value = _attributes[key];
17
+ if (value) {
18
+ if (typeof value === "boolean") {
19
+ result.push(key);
20
+ } else {
21
+ result.push(`${key}="${escapeHTML.escapeHTML(value)}"`);
22
+ }
23
+ }
24
+ }
25
+ if (result.length) {
26
+ result.unshift("");
27
+ }
28
+ return result.join(" ");
29
+ };
30
+ const getGeneralAttributes = (serializerOrShorthand) => {
31
+ return serializerOrShorthand && typeof serializerOrShorthand !== "function" ? serializerOrShorthand : {};
32
+ };
33
+ const serializeStandardTag = (tag, serializerOrShorthand) => {
34
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
35
+ return (({ node, children }) => {
36
+ return `<${tag}${formatAttributes(node, generalAttributes)}>${children}</${tag}>`;
37
+ });
38
+ };
39
+ const serializePreFormatted = (serializerOrShorthand) => {
40
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
41
+ return ({ node }) => {
42
+ return `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML.escapeHTML(node.text)}</pre>`;
43
+ };
44
+ };
45
+ const serializeImage = (linkResolver, serializerOrShorthand) => {
46
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
47
+ return ({ node }) => {
48
+ const attributes = {
49
+ ...generalAttributes,
50
+ src: node.url,
51
+ alt: node.alt,
52
+ copyright: node.copyright
53
+ };
54
+ let imageTag = `<img${formatAttributes(node, attributes)} />`;
55
+ if (node.linkTo) {
56
+ imageTag = serializeHyperlink(linkResolver)({
57
+ type: "hyperlink",
58
+ node: {
59
+ type: "hyperlink",
60
+ data: node.linkTo,
61
+ start: 0,
62
+ end: 0
63
+ },
64
+ text: "",
65
+ children: imageTag,
66
+ key: ""
67
+ });
68
+ }
69
+ return `<p class="block-img">${imageTag}</p>`;
70
+ };
71
+ };
72
+ const serializeEmbed = (serializerOrShorthand) => {
73
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
74
+ return ({ node }) => {
75
+ const attributes = {
76
+ ...generalAttributes,
77
+ ["data-oembed"]: node.oembed.embed_url,
78
+ ["data-oembed-type"]: node.oembed.type,
79
+ ["data-oembed-provider"]: node.oembed.provider_name
80
+ };
81
+ return `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`;
82
+ };
83
+ };
84
+ const serializeHyperlink = (linkResolver, serializerOrShorthand) => {
85
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
86
+ return ({ node, children }) => {
87
+ const attributes = {
88
+ ...generalAttributes
89
+ };
90
+ if (node.data.link_type === link.LinkType.Web) {
91
+ attributes.href = node.data.url;
92
+ attributes.target = node.data.target;
93
+ attributes.rel = "noopener noreferrer";
94
+ } else if (node.data.link_type === link.LinkType.Document) {
95
+ attributes.href = asLink.asLink(node.data, { linkResolver });
96
+ } else if (node.data.link_type === link.LinkType.Media) {
97
+ attributes.href = node.data.url;
98
+ }
99
+ return `<a${formatAttributes(node, attributes)}>${children}</a>`;
100
+ };
101
+ };
102
+ const serializeSpan = () => {
103
+ return ({ text }) => {
104
+ return text ? escapeHTML.escapeHTML(text).replace(/\n/g, "<br />") : "";
105
+ };
106
+ };
107
+ exports.serializeEmbed = serializeEmbed;
108
+ exports.serializeHyperlink = serializeHyperlink;
109
+ exports.serializeImage = serializeImage;
110
+ exports.serializePreFormatted = serializePreFormatted;
111
+ exports.serializeSpan = serializeSpan;
112
+ exports.serializeStandardTag = serializeStandardTag;
113
+ //# sourceMappingURL=serializerHelpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializerHelpers.cjs","sources":["../../../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"],"names":["escapeHTML","LinkType","asLink"],"mappings":"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"}
@@ -0,0 +1,9 @@
1
+ import type { RichTextMapSerializer } from "../richtext/types.js";
2
+ import type { HTMLRichTextMapSerializer, HTMLStrictRichTextMapSerializer } from "../helpers/asHTML.js";
3
+ import type { LinkResolverFunction } from "../helpers/asLink.js";
4
+ export declare const serializeStandardTag: <BlockType extends keyof RichTextMapSerializer<string>>(tag: string, serializerOrShorthand?: HTMLRichTextMapSerializer[BlockType]) => NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>;
5
+ export declare const serializePreFormatted: (serializerOrShorthand?: HTMLRichTextMapSerializer["preformatted"]) => NonNullable<HTMLStrictRichTextMapSerializer["preformatted"]>;
6
+ export declare const serializeImage: (linkResolver: LinkResolverFunction<string | null | undefined> | undefined | null, serializerOrShorthand?: HTMLRichTextMapSerializer["image"]) => NonNullable<HTMLStrictRichTextMapSerializer["image"]>;
7
+ export declare const serializeEmbed: (serializerOrShorthand?: HTMLRichTextMapSerializer["embed"]) => NonNullable<HTMLStrictRichTextMapSerializer["embed"]>;
8
+ export declare const serializeHyperlink: (linkResolver: LinkResolverFunction<string | null | undefined> | undefined | null, serializerOrShorthand?: HTMLRichTextMapSerializer["hyperlink"]) => NonNullable<HTMLStrictRichTextMapSerializer["hyperlink"]>;
9
+ export declare const serializeSpan: () => NonNullable<HTMLStrictRichTextMapSerializer["span"]>;
@@ -0,0 +1,113 @@
1
+ import { LinkType } from "../types/value/link.js";
2
+ import { asLink } from "../helpers/asLink.js";
3
+ import { escapeHTML } from "./escapeHTML.js";
4
+ const formatAttributes = (node, attributes) => {
5
+ const _attributes = { ...attributes };
6
+ if ("direction" in node && node.direction === "rtl") {
7
+ _attributes.dir = node.direction;
8
+ }
9
+ if ("data" in node && "label" in node.data && node.data.label) {
10
+ _attributes.class = _attributes.class ? `${_attributes.class} ${node.data.label}` : node.data.label;
11
+ }
12
+ const result = [];
13
+ for (const key in _attributes) {
14
+ const value = _attributes[key];
15
+ if (value) {
16
+ if (typeof value === "boolean") {
17
+ result.push(key);
18
+ } else {
19
+ result.push(`${key}="${escapeHTML(value)}"`);
20
+ }
21
+ }
22
+ }
23
+ if (result.length) {
24
+ result.unshift("");
25
+ }
26
+ return result.join(" ");
27
+ };
28
+ const getGeneralAttributes = (serializerOrShorthand) => {
29
+ return serializerOrShorthand && typeof serializerOrShorthand !== "function" ? serializerOrShorthand : {};
30
+ };
31
+ const serializeStandardTag = (tag, serializerOrShorthand) => {
32
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
33
+ return (({ node, children }) => {
34
+ return `<${tag}${formatAttributes(node, generalAttributes)}>${children}</${tag}>`;
35
+ });
36
+ };
37
+ const serializePreFormatted = (serializerOrShorthand) => {
38
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
39
+ return ({ node }) => {
40
+ return `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(node.text)}</pre>`;
41
+ };
42
+ };
43
+ const serializeImage = (linkResolver, serializerOrShorthand) => {
44
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
45
+ return ({ node }) => {
46
+ const attributes = {
47
+ ...generalAttributes,
48
+ src: node.url,
49
+ alt: node.alt,
50
+ copyright: node.copyright
51
+ };
52
+ let imageTag = `<img${formatAttributes(node, attributes)} />`;
53
+ if (node.linkTo) {
54
+ imageTag = serializeHyperlink(linkResolver)({
55
+ type: "hyperlink",
56
+ node: {
57
+ type: "hyperlink",
58
+ data: node.linkTo,
59
+ start: 0,
60
+ end: 0
61
+ },
62
+ text: "",
63
+ children: imageTag,
64
+ key: ""
65
+ });
66
+ }
67
+ return `<p class="block-img">${imageTag}</p>`;
68
+ };
69
+ };
70
+ const serializeEmbed = (serializerOrShorthand) => {
71
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
72
+ return ({ node }) => {
73
+ const attributes = {
74
+ ...generalAttributes,
75
+ ["data-oembed"]: node.oembed.embed_url,
76
+ ["data-oembed-type"]: node.oembed.type,
77
+ ["data-oembed-provider"]: node.oembed.provider_name
78
+ };
79
+ return `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`;
80
+ };
81
+ };
82
+ const serializeHyperlink = (linkResolver, serializerOrShorthand) => {
83
+ const generalAttributes = getGeneralAttributes(serializerOrShorthand);
84
+ return ({ node, children }) => {
85
+ const attributes = {
86
+ ...generalAttributes
87
+ };
88
+ if (node.data.link_type === LinkType.Web) {
89
+ attributes.href = node.data.url;
90
+ attributes.target = node.data.target;
91
+ attributes.rel = "noopener noreferrer";
92
+ } else if (node.data.link_type === LinkType.Document) {
93
+ attributes.href = asLink(node.data, { linkResolver });
94
+ } else if (node.data.link_type === LinkType.Media) {
95
+ attributes.href = node.data.url;
96
+ }
97
+ return `<a${formatAttributes(node, attributes)}>${children}</a>`;
98
+ };
99
+ };
100
+ const serializeSpan = () => {
101
+ return ({ text }) => {
102
+ return text ? escapeHTML(text).replace(/\n/g, "<br />") : "";
103
+ };
104
+ };
105
+ export {
106
+ serializeEmbed,
107
+ serializeHyperlink,
108
+ serializeImage,
109
+ serializePreFormatted,
110
+ serializeSpan,
111
+ serializeStandardTag
112
+ };
113
+ //# sourceMappingURL=serializerHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializerHelpers.js","sources":["../../../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"],"names":[],"mappings":"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"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const filter = require("../filter.cjs");
4
+ const castArray = require("./castArray.cjs");
5
+ const someTagsFilter = (tags) => {
6
+ return filter.filter.any("document.tags", castArray.castArray(tags));
7
+ };
8
+ exports.someTagsFilter = someTagsFilter;
9
+ //# sourceMappingURL=someTagsFilter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"someTagsFilter.cjs","sources":["../../../src/lib/someTagsFilter.ts"],"sourcesContent":["import { filter } from \"../filter\"\n\nimport { castArray } from \"./castArray\"\n\n/**\n * Creates a filter to filter content by document tags. At least one matching\n * tag is required on the document.\n *\n * @param tags - Document tags to filter queried content.\n *\n * @returns A filter that can be used in a Prismic REST API V2 request.\n */\nexport const someTagsFilter = (tags: string | string[]): string => {\n\treturn filter.any(\"document.tags\", castArray(tags))\n}\n"],"names":["filter","castArray"],"mappings":";;;;AAYO,MAAM,iBAAiB,CAAC,SAAmC;AACjE,SAAOA,OAAAA,OAAO,IAAI,iBAAiBC,UAAAA,UAAU,IAAI,CAAC;AACnD;;"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Creates a filter to filter content by document tags. At least one matching
3
+ * tag is required on the document.
4
+ *
5
+ * @param tags - Document tags to filter queried content.
6
+ *
7
+ * @returns A filter that can be used in a Prismic REST API V2 request.
8
+ */
9
+ export declare const someTagsFilter: (tags: string | string[]) => string;
@@ -0,0 +1,9 @@
1
+ import { filter } from "../filter.js";
2
+ import { castArray } from "./castArray.js";
3
+ const someTagsFilter = (tags) => {
4
+ return filter.any("document.tags", castArray(tags));
5
+ };
6
+ export {
7
+ someTagsFilter
8
+ };
9
+ //# sourceMappingURL=someTagsFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"someTagsFilter.js","sources":["../../../src/lib/someTagsFilter.ts"],"sourcesContent":["import { filter } from \"../filter\"\n\nimport { castArray } from \"./castArray\"\n\n/**\n * Creates a filter to filter content by document tags. At least one matching\n * tag is required on the document.\n *\n * @param tags - Document tags to filter queried content.\n *\n * @returns A filter that can be used in a Prismic REST API V2 request.\n */\nexport const someTagsFilter = (tags: string | string[]): string => {\n\treturn filter.any(\"document.tags\", castArray(tags))\n}\n"],"names":[],"mappings":";;AAYO,MAAM,iBAAiB,CAAC,SAAmC;AACjE,SAAO,OAAO,IAAI,iBAAiB,UAAU,IAAI,CAAC;AACnD;"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const THROTTLE_THRESHOLD_MS = 5e3;
4
+ let lastMessage;
5
+ let lastCalledAt = 0;
6
+ const throttledLog = (message, config = {}) => {
7
+ const { level = "log" } = config;
8
+ if (message === lastMessage && Date.now() - lastCalledAt < THROTTLE_THRESHOLD_MS) {
9
+ lastCalledAt = Date.now();
10
+ return;
11
+ }
12
+ lastCalledAt = Date.now();
13
+ lastMessage = message;
14
+ console[level](message);
15
+ };
16
+ exports.throttledLog = throttledLog;
17
+ //# sourceMappingURL=throttledLog.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttledLog.cjs","sources":["../../../src/lib/throttledLog.ts"],"sourcesContent":["const THROTTLE_THRESHOLD_MS = 5000\n\nlet lastMessage: string | undefined\nlet lastCalledAt = 0\n\n/**\n * Logs a message. If the message is identical the immediate previous logged\n * message and that message was logged within 5 seconds of the current call, the\n * log is ignored. This throttle behavior prevents identical messages from\n * flooding the console.\n *\n * @param message - A message to log.\n * @param config - Configuration for the log.\n */\nexport const throttledLog = (\n\tmessage: string,\n\tconfig: {\n\t\t/**\n\t\t * The log level. Matches the global `console` log levels.\n\t\t */\n\t\tlevel?: \"log\" | \"warn\" | \"error\"\n\t} = {},\n): void => {\n\tconst { level = \"log\" } = config\n\n\tif (\n\t\tmessage === lastMessage &&\n\t\tDate.now() - lastCalledAt < THROTTLE_THRESHOLD_MS\n\t) {\n\t\tlastCalledAt = Date.now()\n\n\t\treturn\n\t}\n\n\tlastCalledAt = Date.now()\n\tlastMessage = message\n\n\t// eslint-disable-next-line no-console\n\tconsole[level](message)\n}\n"],"names":[],"mappings":";;AAAA,MAAM,wBAAwB;AAE9B,IAAI;AACJ,IAAI,eAAe;AAWZ,MAAM,eAAe,CAC3B,SACA,SAKI,OACK;AACT,QAAM,EAAE,QAAQ,MAAA,IAAU;AAE1B,MACC,YAAY,eACZ,KAAK,IAAA,IAAQ,eAAe,uBAC3B;AACD,mBAAe,KAAK,IAAA;AAEpB;AAAA,EACD;AAEA,iBAAe,KAAK,IAAA;AACpB,gBAAc;AAGd,UAAQ,KAAK,EAAE,OAAO;AACvB;;"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Logs a message. If the message is identical the immediate previous logged
3
+ * message and that message was logged within 5 seconds of the current call, the
4
+ * log is ignored. This throttle behavior prevents identical messages from
5
+ * flooding the console.
6
+ *
7
+ * @param message - A message to log.
8
+ * @param config - Configuration for the log.
9
+ */
10
+ export declare const throttledLog: (message: string, config?: {
11
+ /**
12
+ * The log level. Matches the global `console` log levels.
13
+ */
14
+ level?: "log" | "warn" | "error";
15
+ }) => void;
@@ -0,0 +1,17 @@
1
+ const THROTTLE_THRESHOLD_MS = 5e3;
2
+ let lastMessage;
3
+ let lastCalledAt = 0;
4
+ const throttledLog = (message, config = {}) => {
5
+ const { level = "log" } = config;
6
+ if (message === lastMessage && Date.now() - lastCalledAt < THROTTLE_THRESHOLD_MS) {
7
+ lastCalledAt = Date.now();
8
+ return;
9
+ }
10
+ lastCalledAt = Date.now();
11
+ lastMessage = message;
12
+ console[level](message);
13
+ };
14
+ export {
15
+ throttledLog
16
+ };
17
+ //# sourceMappingURL=throttledLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttledLog.js","sources":["../../../src/lib/throttledLog.ts"],"sourcesContent":["const THROTTLE_THRESHOLD_MS = 5000\n\nlet lastMessage: string | undefined\nlet lastCalledAt = 0\n\n/**\n * Logs a message. If the message is identical the immediate previous logged\n * message and that message was logged within 5 seconds of the current call, the\n * log is ignored. This throttle behavior prevents identical messages from\n * flooding the console.\n *\n * @param message - A message to log.\n * @param config - Configuration for the log.\n */\nexport const throttledLog = (\n\tmessage: string,\n\tconfig: {\n\t\t/**\n\t\t * The log level. Matches the global `console` log levels.\n\t\t */\n\t\tlevel?: \"log\" | \"warn\" | \"error\"\n\t} = {},\n): void => {\n\tconst { level = \"log\" } = config\n\n\tif (\n\t\tmessage === lastMessage &&\n\t\tDate.now() - lastCalledAt < THROTTLE_THRESHOLD_MS\n\t) {\n\t\tlastCalledAt = Date.now()\n\n\t\treturn\n\t}\n\n\tlastCalledAt = Date.now()\n\tlastMessage = message\n\n\t// eslint-disable-next-line no-console\n\tconsole[level](message)\n}\n"],"names":[],"mappings":"AAAA,MAAM,wBAAwB;AAE9B,IAAI;AACJ,IAAI,eAAe;AAWZ,MAAM,eAAe,CAC3B,SACA,SAKI,OACK;AACT,QAAM,EAAE,QAAQ,MAAA,IAAU;AAE1B,MACC,YAAY,eACZ,KAAK,IAAA,IAAQ,eAAe,uBAC3B;AACD,mBAAe,KAAK,IAAA;AAEpB;AAAA,EACD;AAEA,iBAAe,KAAK,IAAA;AACpB,gBAAc;AAGd,UAAQ,KAAK,EAAE,OAAO;AACvB;"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const filter = require("../filter.cjs");
4
+ const typeFilter = (documentType) => {
5
+ return filter.filter.at("document.type", documentType);
6
+ };
7
+ exports.typeFilter = typeFilter;
8
+ //# sourceMappingURL=typeFilter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeFilter.cjs","sources":["../../../src/lib/typeFilter.ts"],"sourcesContent":["import { filter } from \"../filter\"\n\n/**\n * Creates a filter to filter content by document type.\n *\n * @param documentType - The document type to filter queried content.\n *\n * @returns A filter that can be used in a Prismic REST API V2 request.\n */\nexport const typeFilter = (documentType: string): string => {\n\treturn filter.at(\"document.type\", documentType)\n}\n"],"names":["filter"],"mappings":";;;AASO,MAAM,aAAa,CAAC,iBAAgC;AAC1D,SAAOA,cAAO,GAAG,iBAAiB,YAAY;AAC/C;;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates a filter to filter content by document type.
3
+ *
4
+ * @param documentType - The document type to filter queried content.
5
+ *
6
+ * @returns A filter that can be used in a Prismic REST API V2 request.
7
+ */
8
+ export declare const typeFilter: (documentType: string) => string;
@@ -0,0 +1,8 @@
1
+ import { filter } from "../filter.js";
2
+ const typeFilter = (documentType) => {
3
+ return filter.at("document.type", documentType);
4
+ };
5
+ export {
6
+ typeFilter
7
+ };
8
+ //# sourceMappingURL=typeFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeFilter.js","sources":["../../../src/lib/typeFilter.ts"],"sourcesContent":["import { filter } from \"../filter\"\n\n/**\n * Creates a filter to filter content by document type.\n *\n * @param documentType - The document type to filter queried content.\n *\n * @returns A filter that can be used in a Prismic REST API V2 request.\n */\nexport const typeFilter = (documentType: string): string => {\n\treturn filter.at(\"document.type\", documentType)\n}\n"],"names":[],"mappings":";AASO,MAAM,aAAa,CAAC,iBAAgC;AAC1D,SAAO,OAAO,GAAG,iBAAiB,YAAY;AAC/C;"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const PrismicError = require("../errors/PrismicError.cjs");
4
+ const ASSET_NOTES_MAX_LENGTH = 500;
5
+ const ASSET_CREDITS_MAX_LENGTH = 500;
6
+ const ASSET_ALT_MAX_LENGTH = 500;
7
+ const ASSET_TAG_MIN_LENGTH = 3;
8
+ const ASSET_TAG_MAX_LENGTH = 20;
9
+ const validateAssetMetadata = ({ notes, credits, alt, tags }) => {
10
+ const errors = [];
11
+ if (notes && notes.length > ASSET_NOTES_MAX_LENGTH) {
12
+ errors.push(`\`notes\` must be at most ${ASSET_NOTES_MAX_LENGTH} characters`);
13
+ }
14
+ if (credits && credits.length > ASSET_CREDITS_MAX_LENGTH) {
15
+ errors.push(`\`credits\` must be at most ${ASSET_CREDITS_MAX_LENGTH} characters`);
16
+ }
17
+ if (alt && alt.length > ASSET_ALT_MAX_LENGTH) {
18
+ errors.push(`\`alt\` must be at most ${ASSET_ALT_MAX_LENGTH} characters`);
19
+ }
20
+ if (tags && tags.length && tags.some((tag) => tag.length < ASSET_TAG_MIN_LENGTH || tag.length > ASSET_TAG_MAX_LENGTH)) {
21
+ errors.push(`tags must be at least 3 characters long and 20 characters at most`);
22
+ }
23
+ if (errors.length) {
24
+ throw new PrismicError.PrismicError(`Errors validating asset metadata: ${errors.join(", ")}`, void 0, { notes, credits, alt, tags });
25
+ }
26
+ };
27
+ exports.validateAssetMetadata = validateAssetMetadata;
28
+ //# sourceMappingURL=validateAssetMetadata.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateAssetMetadata.cjs","sources":["../../../src/lib/validateAssetMetadata.ts"],"sourcesContent":["import { PrismicError } from \"../errors/PrismicError\"\n\nimport type { CreateAssetParams } from \"../WriteClient\"\n\n/**\n * Max length for asset notes accepted by the API.\n */\nconst ASSET_NOTES_MAX_LENGTH = 500\n\n/**\n * Max length for asset credits accepted by the API.\n */\nconst ASSET_CREDITS_MAX_LENGTH = 500\n\n/**\n * Max length for asset alt text accepted by the API.\n */\nconst ASSET_ALT_MAX_LENGTH = 500\n\n/**\n * Min length for asset tags accepted by the API.\n */\nconst ASSET_TAG_MIN_LENGTH = 3\n\n/**\n * Max length for asset tags accepted by the API.\n */\nconst ASSET_TAG_MAX_LENGTH = 20\n\n/**\n * Validates an asset's metadata, throwing an error if any of the metadata are\n * invalid.\n *\n * @param assetMetadata - The asset metadata to validate.\n *\n * @internal\n */\nexport const validateAssetMetadata = ({\n\tnotes,\n\tcredits,\n\talt,\n\ttags,\n}: CreateAssetParams): void => {\n\tconst errors: string[] = []\n\n\tif (notes && notes.length > ASSET_NOTES_MAX_LENGTH) {\n\t\terrors.push(\n\t\t\t`\\`notes\\` must be at most ${ASSET_NOTES_MAX_LENGTH} characters`,\n\t\t)\n\t}\n\n\tif (credits && credits.length > ASSET_CREDITS_MAX_LENGTH) {\n\t\terrors.push(\n\t\t\t`\\`credits\\` must be at most ${ASSET_CREDITS_MAX_LENGTH} characters`,\n\t\t)\n\t}\n\n\tif (alt && alt.length > ASSET_ALT_MAX_LENGTH) {\n\t\terrors.push(`\\`alt\\` must be at most ${ASSET_ALT_MAX_LENGTH} characters`)\n\t}\n\n\tif (\n\t\ttags &&\n\t\ttags.length &&\n\t\ttags.some(\n\t\t\t(tag) =>\n\t\t\t\ttag.length < ASSET_TAG_MIN_LENGTH || tag.length > ASSET_TAG_MAX_LENGTH,\n\t\t)\n\t) {\n\t\terrors.push(\n\t\t\t`tags must be at least 3 characters long and 20 characters at most`,\n\t\t)\n\t}\n\n\tif (errors.length) {\n\t\tthrow new PrismicError(\n\t\t\t`Errors validating asset metadata: ${errors.join(\", \")}`,\n\t\t\tundefined,\n\t\t\t{ notes, credits, alt, tags },\n\t\t)\n\t}\n}\n"],"names":["PrismicError"],"mappings":";;;AAOA,MAAM,yBAAyB;AAK/B,MAAM,2BAA2B;AAKjC,MAAM,uBAAuB;AAK7B,MAAM,uBAAuB;AAK7B,MAAM,uBAAuB;AAUtB,MAAM,wBAAwB,CAAC,EACrC,OACA,SACA,KACA,WAC6B;AAC7B,QAAM,SAAmB,CAAA;AAEzB,MAAI,SAAS,MAAM,SAAS,wBAAwB;AACnD,WAAO,KACN,6BAA6B,sBAAsB,aAAa;AAAA,EAElE;AAEA,MAAI,WAAW,QAAQ,SAAS,0BAA0B;AACzD,WAAO,KACN,+BAA+B,wBAAwB,aAAa;AAAA,EAEtE;AAEA,MAAI,OAAO,IAAI,SAAS,sBAAsB;AAC7C,WAAO,KAAK,2BAA2B,oBAAoB,aAAa;AAAA,EACzE;AAEA,MACC,QACA,KAAK,UACL,KAAK,KACJ,CAAC,QACA,IAAI,SAAS,wBAAwB,IAAI,SAAS,oBAAoB,GAEvE;AACD,WAAO,KACN,mEAAmE;AAAA,EAErE;AAEA,MAAI,OAAO,QAAQ;AAClB,UAAM,IAAIA,aAAAA,aACT,qCAAqC,OAAO,KAAK,IAAI,CAAC,IACtD,QACA,EAAE,OAAO,SAAS,KAAK,MAAM;AAAA,EAE/B;AACD;;"}
@@ -0,0 +1,10 @@
1
+ import type { CreateAssetParams } from "../WriteClient.js";
2
+ /**
3
+ * Validates an asset's metadata, throwing an error if any of the metadata are
4
+ * invalid.
5
+ *
6
+ * @param assetMetadata - The asset metadata to validate.
7
+ *
8
+ * @internal
9
+ */
10
+ export declare const validateAssetMetadata: ({ notes, credits, alt, tags, }: CreateAssetParams) => void;