@prismicio/client 7.20.2-alpha.0 → 7.20.3

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 (276) hide show
  1. package/dist/Client.cjs +120 -132
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.ts +7 -7
  4. package/dist/Client.js +120 -132
  5. package/dist/Client.js.map +1 -1
  6. package/dist/Migration.cjs +83 -101
  7. package/dist/Migration.cjs.map +1 -1
  8. package/dist/Migration.d.ts +9 -9
  9. package/dist/Migration.js +83 -101
  10. package/dist/Migration.js.map +1 -1
  11. package/dist/WriteClient.cjs +115 -92
  12. package/dist/WriteClient.cjs.map +1 -1
  13. package/dist/WriteClient.d.ts +6 -6
  14. package/dist/WriteClient.js +115 -92
  15. package/dist/WriteClient.js.map +1 -1
  16. package/dist/buildQueryURL.cjs.map +1 -1
  17. package/dist/buildQueryURL.d.ts +29 -21
  18. package/dist/buildQueryURL.js.map +1 -1
  19. package/dist/createClient.cjs.map +1 -1
  20. package/dist/createClient.d.ts +13 -10
  21. package/dist/createClient.js.map +1 -1
  22. package/dist/createMigration.cjs.map +1 -1
  23. package/dist/createMigration.d.ts +2 -2
  24. package/dist/createMigration.js.map +1 -1
  25. package/dist/createWriteClient.cjs.map +1 -1
  26. package/dist/createWriteClient.d.ts +2 -2
  27. package/dist/errors/ForbiddenError.d.ts +1 -1
  28. package/dist/errors/InvalidDataError.d.ts +1 -1
  29. package/dist/errors/NotFoundError.d.ts +1 -1
  30. package/dist/errors/ParsingError.d.ts +1 -1
  31. package/dist/errors/PreviewTokenExpired.d.ts +1 -1
  32. package/dist/errors/PrismicError.cjs +2 -5
  33. package/dist/errors/PrismicError.cjs.map +1 -1
  34. package/dist/errors/PrismicError.js +2 -5
  35. package/dist/errors/PrismicError.js.map +1 -1
  36. package/dist/errors/RefExpiredError.d.ts +1 -1
  37. package/dist/errors/RefNotFoundError.d.ts +1 -1
  38. package/dist/errors/RepositoryNotFoundError.d.ts +1 -1
  39. package/dist/filter.cjs.map +1 -1
  40. package/dist/filter.js.map +1 -1
  41. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  42. package/dist/getGraphQLEndpoint.js.map +1 -1
  43. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  44. package/dist/getRepositoryEndpoint.d.ts +9 -2
  45. package/dist/getRepositoryEndpoint.js.map +1 -1
  46. package/dist/getRepositoryName.cjs.map +1 -1
  47. package/dist/getRepositoryName.js.map +1 -1
  48. package/dist/getToolbarSrc.cjs.map +1 -1
  49. package/dist/getToolbarSrc.js.map +1 -1
  50. package/dist/helpers/asDate.cjs.map +1 -1
  51. package/dist/helpers/asDate.d.ts +13 -6
  52. package/dist/helpers/asDate.js.map +1 -1
  53. package/dist/helpers/asHTML.cjs +22 -22
  54. package/dist/helpers/asHTML.cjs.map +1 -1
  55. package/dist/helpers/asHTML.d.ts +37 -29
  56. package/dist/helpers/asHTML.js +22 -22
  57. package/dist/helpers/asHTML.js.map +1 -1
  58. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  59. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +17 -16
  60. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  61. package/dist/helpers/asImageSrc.cjs.map +1 -1
  62. package/dist/helpers/asImageSrc.d.ts +12 -11
  63. package/dist/helpers/asImageSrc.js.map +1 -1
  64. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  65. package/dist/helpers/asImageWidthSrcSet.d.ts +19 -18
  66. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  67. package/dist/helpers/asLink.cjs.map +1 -1
  68. package/dist/helpers/asLink.d.ts +36 -35
  69. package/dist/helpers/asLink.js.map +1 -1
  70. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  71. package/dist/helpers/asLinkAttrs.d.ts +11 -14
  72. package/dist/helpers/asLinkAttrs.js.map +1 -1
  73. package/dist/helpers/asText.cjs.map +1 -1
  74. package/dist/helpers/asText.d.ts +21 -11
  75. package/dist/helpers/asText.js.map +1 -1
  76. package/dist/helpers/documentToLinkField.cjs +1 -2
  77. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  78. package/dist/helpers/documentToLinkField.d.ts +2 -2
  79. package/dist/helpers/documentToLinkField.js +1 -2
  80. package/dist/helpers/documentToLinkField.js.map +1 -1
  81. package/dist/helpers/isFilled.cjs +1 -1
  82. package/dist/helpers/isFilled.cjs.map +1 -1
  83. package/dist/helpers/isFilled.d.ts +35 -34
  84. package/dist/helpers/isFilled.js +1 -1
  85. package/dist/helpers/isFilled.js.map +1 -1
  86. package/dist/helpers/mapSliceZone.cjs.map +1 -1
  87. package/dist/helpers/mapSliceZone.d.ts +11 -11
  88. package/dist/helpers/mapSliceZone.js.map +1 -1
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.ts +120 -120
  91. package/dist/index.js.map +1 -1
  92. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  93. package/dist/isRepositoryEndpoint.d.ts +2 -2
  94. package/dist/isRepositoryEndpoint.js.map +1 -1
  95. package/dist/isRepositoryName.cjs.map +1 -1
  96. package/dist/isRepositoryName.js.map +1 -1
  97. package/dist/lib/appendFilters.cjs.map +1 -1
  98. package/dist/lib/appendFilters.js.map +1 -1
  99. package/dist/lib/castArray.cjs.map +1 -1
  100. package/dist/lib/castArray.js.map +1 -1
  101. package/dist/lib/castThunk.cjs.map +1 -1
  102. package/dist/lib/castThunk.js.map +1 -1
  103. package/dist/lib/devMsg.cjs.map +1 -1
  104. package/dist/lib/devMsg.js.map +1 -1
  105. package/dist/lib/escapeHTML.cjs.map +1 -1
  106. package/dist/lib/escapeHTML.js.map +1 -1
  107. package/dist/lib/everyTagFilter.cjs.map +1 -1
  108. package/dist/lib/everyTagFilter.js.map +1 -1
  109. package/dist/lib/findMasterRef.cjs.map +1 -1
  110. package/dist/lib/findMasterRef.d.ts +1 -1
  111. package/dist/lib/findMasterRef.js.map +1 -1
  112. package/dist/lib/findRef.cjs.map +1 -1
  113. package/dist/lib/findRef.d.ts +1 -1
  114. package/dist/lib/findRef.js.map +1 -1
  115. package/dist/lib/findRefByID.cjs.map +1 -1
  116. package/dist/lib/findRefByID.d.ts +1 -1
  117. package/dist/lib/findRefByID.js.map +1 -1
  118. package/dist/lib/findRefByLabel.cjs.map +1 -1
  119. package/dist/lib/findRefByLabel.d.ts +1 -1
  120. package/dist/lib/findRefByLabel.js.map +1 -1
  121. package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
  122. package/dist/lib/getOptionalLinkProperties.d.ts +1 -1
  123. package/dist/lib/getOptionalLinkProperties.js.map +1 -1
  124. package/dist/lib/getPreviewCookie.cjs.map +1 -1
  125. package/dist/lib/getPreviewCookie.js.map +1 -1
  126. package/dist/lib/isInternalURL.cjs.map +1 -1
  127. package/dist/lib/isInternalURL.js.map +1 -1
  128. package/dist/lib/isMigrationValue.cjs.map +1 -1
  129. package/dist/lib/isMigrationValue.d.ts +8 -8
  130. package/dist/lib/isMigrationValue.js.map +1 -1
  131. package/dist/lib/isValue.cjs.map +1 -1
  132. package/dist/lib/isValue.d.ts +10 -10
  133. package/dist/lib/isValue.js.map +1 -1
  134. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
  135. package/dist/lib/minifyGraphQLQuery.js.map +1 -1
  136. package/dist/lib/pLimit.cjs +3 -4
  137. package/dist/lib/pLimit.cjs.map +1 -1
  138. package/dist/lib/pLimit.js +3 -4
  139. package/dist/lib/pLimit.js.map +1 -1
  140. package/dist/lib/request.cjs +8 -10
  141. package/dist/lib/request.cjs.map +1 -1
  142. package/dist/lib/request.js +8 -10
  143. package/dist/lib/request.js.map +1 -1
  144. package/dist/lib/resolveMigrationDocumentData.cjs +4 -6
  145. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
  146. package/dist/lib/resolveMigrationDocumentData.d.ts +8 -8
  147. package/dist/lib/resolveMigrationDocumentData.js +4 -6
  148. package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
  149. package/dist/lib/serializerHelpers.cjs +2 -2
  150. package/dist/lib/serializerHelpers.cjs.map +1 -1
  151. package/dist/lib/serializerHelpers.d.ts +3 -3
  152. package/dist/lib/serializerHelpers.js +2 -2
  153. package/dist/lib/serializerHelpers.js.map +1 -1
  154. package/dist/lib/someTagsFilter.cjs.map +1 -1
  155. package/dist/lib/someTagsFilter.js.map +1 -1
  156. package/dist/lib/throttledLog.cjs.map +1 -1
  157. package/dist/lib/throttledLog.js.map +1 -1
  158. package/dist/lib/typeFilter.cjs.map +1 -1
  159. package/dist/lib/typeFilter.js.map +1 -1
  160. package/dist/lib/validateAssetMetadata.cjs.map +1 -1
  161. package/dist/lib/validateAssetMetadata.d.ts +1 -1
  162. package/dist/lib/validateAssetMetadata.js.map +1 -1
  163. package/dist/package.json.cjs +1 -1
  164. package/dist/package.json.js +1 -1
  165. package/dist/richtext/asText.cjs.map +1 -1
  166. package/dist/richtext/asText.d.ts +6 -6
  167. package/dist/richtext/asText.js.map +1 -1
  168. package/dist/richtext/asTree.cjs.map +1 -1
  169. package/dist/richtext/asTree.d.ts +2 -2
  170. package/dist/richtext/asTree.js.map +1 -1
  171. package/dist/richtext/composeSerializers.cjs.map +1 -1
  172. package/dist/richtext/composeSerializers.d.ts +1 -1
  173. package/dist/richtext/composeSerializers.js.map +1 -1
  174. package/dist/richtext/index.d.ts +7 -7
  175. package/dist/richtext/serialize.cjs.map +1 -1
  176. package/dist/richtext/serialize.d.ts +10 -10
  177. package/dist/richtext/serialize.js.map +1 -1
  178. package/dist/richtext/types.cjs.map +1 -1
  179. package/dist/richtext/types.d.ts +7 -7
  180. package/dist/richtext/types.js.map +1 -1
  181. package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
  182. package/dist/richtext/wrapMapSerializer.d.ts +1 -1
  183. package/dist/richtext/wrapMapSerializer.js.map +1 -1
  184. package/dist/types/api/asset/asset.d.ts +1 -1
  185. package/dist/types/api/integration.d.ts +1 -1
  186. package/dist/types/api/migration/document.d.ts +1 -1
  187. package/dist/types/api/query.d.ts +1 -1
  188. package/dist/types/api/release.d.ts +1 -1
  189. package/dist/types/api/repository.d.ts +1 -1
  190. package/dist/types/migration/Asset.cjs +12 -15
  191. package/dist/types/migration/Asset.cjs.map +1 -1
  192. package/dist/types/migration/Asset.d.ts +7 -7
  193. package/dist/types/migration/Asset.js +12 -15
  194. package/dist/types/migration/Asset.js.map +1 -1
  195. package/dist/types/migration/ContentRelationship.d.ts +3 -3
  196. package/dist/types/migration/Document.cjs +24 -27
  197. package/dist/types/migration/Document.cjs.map +1 -1
  198. package/dist/types/migration/Document.d.ts +9 -9
  199. package/dist/types/migration/Document.js +24 -27
  200. package/dist/types/migration/Document.js.map +1 -1
  201. package/dist/types/migration/Link.d.ts +1 -1
  202. package/dist/types/model/boolean.d.ts +1 -1
  203. package/dist/types/model/color.d.ts +1 -1
  204. package/dist/types/model/contentRelationship.d.ts +3 -2
  205. package/dist/types/model/customType.d.ts +1 -1
  206. package/dist/types/model/date.d.ts +1 -1
  207. package/dist/types/model/embed.d.ts +1 -1
  208. package/dist/types/model/geoPoint.d.ts +1 -1
  209. package/dist/types/model/group.d.ts +1 -1
  210. package/dist/types/model/image.d.ts +1 -1
  211. package/dist/types/model/integration.d.ts +1 -1
  212. package/dist/types/model/keyText.d.ts +1 -1
  213. package/dist/types/model/link.d.ts +1 -1
  214. package/dist/types/model/linkToMedia.d.ts +2 -2
  215. package/dist/types/model/number.d.ts +1 -1
  216. package/dist/types/model/range.d.ts +1 -1
  217. package/dist/types/model/richText.d.ts +1 -1
  218. package/dist/types/model/select.d.ts +1 -1
  219. package/dist/types/model/separator.d.ts +1 -1
  220. package/dist/types/model/sharedSlice.d.ts +2 -2
  221. package/dist/types/model/sharedSliceVariation.d.ts +1 -1
  222. package/dist/types/model/slice.d.ts +3 -3
  223. package/dist/types/model/sliceZone.d.ts +2 -2
  224. package/dist/types/model/table.d.ts +1 -1
  225. package/dist/types/model/timestamp.d.ts +1 -1
  226. package/dist/types/model/title.d.ts +1 -1
  227. package/dist/types/model/types.d.ts +22 -22
  228. package/dist/types/model/uid.d.ts +1 -1
  229. package/dist/types/value/color.d.ts +1 -1
  230. package/dist/types/value/contentRelationship.d.ts +3 -3
  231. package/dist/types/value/date.d.ts +1 -1
  232. package/dist/types/value/document.d.ts +4 -4
  233. package/dist/types/value/embed.d.ts +1 -1
  234. package/dist/types/value/geoPoint.d.ts +1 -1
  235. package/dist/types/value/group.d.ts +1 -1
  236. package/dist/types/value/image.d.ts +1 -1
  237. package/dist/types/value/integration.d.ts +1 -1
  238. package/dist/types/value/keyText.d.ts +1 -1
  239. package/dist/types/value/link.d.ts +5 -5
  240. package/dist/types/value/linkToMedia.d.ts +2 -2
  241. package/dist/types/value/number.d.ts +1 -1
  242. package/dist/types/value/richText.d.ts +3 -3
  243. package/dist/types/value/select.d.ts +1 -1
  244. package/dist/types/value/sharedSlice.d.ts +1 -1
  245. package/dist/types/value/sharedSliceVariation.d.ts +1 -1
  246. package/dist/types/value/slice.d.ts +1 -1
  247. package/dist/types/value/sliceZone.d.ts +3 -3
  248. package/dist/types/value/table.d.ts +2 -2
  249. package/dist/types/value/timestamp.d.ts +2 -2
  250. package/dist/types/value/title.d.ts +2 -2
  251. package/dist/types/value/types.d.ts +18 -18
  252. package/dist/types/webhook/apiUpdate.d.ts +1 -1
  253. package/dist/types/webhook/testTrigger.d.ts +1 -1
  254. package/dist/types/webhook/types.d.ts +2 -2
  255. package/package.json +11 -11
  256. package/src/WriteClient.ts +32 -21
  257. package/src/buildQueryURL.ts +29 -21
  258. package/src/createClient.ts +11 -8
  259. package/src/getRepositoryEndpoint.ts +9 -2
  260. package/src/helpers/asDate.ts +11 -4
  261. package/src/helpers/asHTML.ts +34 -26
  262. package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
  263. package/src/helpers/asImageSrc.ts +11 -10
  264. package/src/helpers/asImageWidthSrcSet.ts +18 -17
  265. package/src/helpers/asLink.ts +33 -32
  266. package/src/helpers/asLinkAttrs.ts +6 -9
  267. package/src/helpers/asText.ts +20 -10
  268. package/src/helpers/isFilled.ts +15 -14
  269. package/src/helpers/mapSliceZone.ts +10 -10
  270. package/src/index.ts +2 -2
  271. package/src/isRepositoryEndpoint.ts +2 -2
  272. package/src/richtext/asText.ts +5 -5
  273. package/src/richtext/serialize.ts +8 -8
  274. package/src/richtext/types.ts +6 -6
  275. package/src/types/migration/Asset.ts +10 -2
  276. package/src/types/model/contentRelationship.ts +1 -0
@@ -5,28 +5,26 @@ const DEFAULT_RETRY_AFTER = 1500;
5
5
  const THROTTLED_RUNNERS = {};
6
6
  const DEDUPLICATED_JOBS = {};
7
7
  async function request(url, init, fetchFn) {
8
- var _a, _b;
9
8
  const stringURL = url.toString();
10
9
  let job;
11
- if (init == null ? void 0 : init.body) {
12
- const runner = THROTTLED_RUNNERS[_a = url.hostname] || (THROTTLED_RUNNERS[_a] = pLimit.pLimit({
10
+ if (init?.body) {
11
+ const runner = THROTTLED_RUNNERS[url.hostname] ||= pLimit.pLimit({
13
12
  interval: DEFAULT_RETRY_AFTER
14
- }));
13
+ });
15
14
  job = runner(() => fetchFn(stringURL, init));
16
15
  } else {
17
- const existingJob = (_b = DEDUPLICATED_JOBS[stringURL]) == null ? void 0 : _b.get(init == null ? void 0 : init.signal);
16
+ const existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal);
18
17
  if (existingJob) {
19
18
  job = existingJob;
20
19
  } else {
21
20
  job = fetchFn(stringURL, init).finally(() => {
22
- var _a2, _b2;
23
- (_a2 = DEDUPLICATED_JOBS[stringURL]) == null ? void 0 : _a2.delete(init == null ? void 0 : init.signal);
24
- if (((_b2 = DEDUPLICATED_JOBS[stringURL]) == null ? void 0 : _b2.size) === 0) {
21
+ DEDUPLICATED_JOBS[stringURL]?.delete(init?.signal);
22
+ if (DEDUPLICATED_JOBS[stringURL]?.size === 0) {
25
23
  delete DEDUPLICATED_JOBS[stringURL];
26
24
  }
27
25
  });
28
- const map = DEDUPLICATED_JOBS[stringURL] || (DEDUPLICATED_JOBS[stringURL] = /* @__PURE__ */ new Map());
29
- map.set(init == null ? void 0 : init.signal, job);
26
+ const map = DEDUPLICATED_JOBS[stringURL] ||= /* @__PURE__ */ new Map();
27
+ map.set(init?.signal, job);
30
28
  }
31
29
  }
32
30
  const response = await job;
@@ -1 +1 @@
1
- {"version":3,"file":"request.cjs","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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\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\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).finally(() => {\n\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t}\n\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.clone()\n}\n"],"names":["pLimit","_a","_b"],"mappings":";;;AAOO,MAAM,sBAAsB;AAKnC,MAAM,oBAA4D,CAAA;AAMlE,MAAM,oBAEF,CAAA;AAgGkB,eAAA,QACrB,KACA,MACA,SAAkB;;AAEZ,QAAA,YAAY,IAAI;AAElB,MAAA;AAGJ,MAAI,6BAAM,MAAM;AAEf,UAAM,SAAU,uBAAkB,IAAI,cAAtB,wBAAoCA,OAAAA,OAAO;AAAA,MAC1D,UAAU;AAAA,IAAA,CACV;AAED,UAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,CAAC;AAAA,EAAA,OACrC;AAEN,UAAM,eAAc,uBAAkB,SAAS,MAA3B,mBAA8B,IAAI,6BAAM;AAC5D,QAAI,aAAa;AACV,YAAA;AAAA,IAAA,OACA;AACN,YAAM,QAAQ,WAAW,IAAI,EAAE,QAAQ,MAAK;;AAC3C,SAAAC,MAAA,kBAAkB,SAAS,MAA3B,gBAAAA,IAA8B,OAAO,6BAAM;AAC3C,cAAIC,MAAA,kBAAkB,SAAS,MAA3B,gBAAAA,IAA8B,UAAS,GAAG;AAC7C,iBAAO,kBAAkB,SAAS;AAAA,QAAA;AAAA,MACnC,CACA;AACD,YAAM,MAAO,oFAAqC,IAAK;AACnD,UAAA,IAAI,6BAAM,QAAQ,GAAG;AAAA,IAAA;AAAA,EAC1B;AAGD,QAAM,WAAW,MAAM;AAGnB,MAAA,SAAS,WAAW,KAAK;AAC5B,UAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,aAAa,CAAC;AAC7D,UAAM,qBAAqB,OAAO,MAAM,UAAU,IAC/C,sBACA,aAAa;AAEhB,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,kBAAkB,CAAC;AAE/D,WAAA,QAAQ,KAAK,MAAM,OAAO;AAAA,EAAA;AAGlC,SAAO,SAAS,MAAK;AACtB;;;"}
1
+ {"version":3,"file":"request.cjs","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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\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\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).finally(() => {\n\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t}\n\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.clone()\n}\n"],"names":["pLimit"],"mappings":";;;AAOO,MAAM,sBAAsB;AAKnC,MAAM,oBAA4D,CAAA;AAMlE,MAAM,oBAEF,CAAA;AAgGJ,eAAsB,QACrB,KACA,MACA,SAAkB;AAElB,QAAM,YAAY,IAAI,SAAA;AAEtB,MAAI;AAGJ,MAAI,MAAM,MAAM;AAEf,UAAM,SAAU,kBAAkB,IAAI,QAAQ,MAAMA,OAAAA,OAAO;AAAA,MAC1D,UAAU;AAAA,IAAA,CACV;AAED,UAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,CAAC;AAAA,EAC5C,OAAO;AAEN,UAAM,cAAc,kBAAkB,SAAS,GAAG,IAAI,MAAM,MAAM;AAClE,QAAI,aAAa;AAChB,YAAM;AAAA,IACP,OAAO;AACN,YAAM,QAAQ,WAAW,IAAI,EAAE,QAAQ,MAAK;AAC3C,0BAAkB,SAAS,GAAG,OAAO,MAAM,MAAM;AACjD,YAAI,kBAAkB,SAAS,GAAG,SAAS,GAAG;AAC7C,iBAAO,kBAAkB,SAAS;AAAA,QACnC;AAAA,MACD,CAAC;AACD,YAAM,MAAO,kBAAkB,SAAS,0BAAU,IAAA;AAClD,UAAI,IAAI,MAAM,QAAQ,GAAG;AAAA,IAC1B;AAAA,EACD;AAEA,QAAM,WAAW,MAAM;AAGvB,MAAI,SAAS,WAAW,KAAK;AAC5B,UAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,aAAa,CAAC;AAC7D,UAAM,qBAAqB,OAAO,MAAM,UAAU,IAC/C,sBACA,aAAa;AAEhB,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,kBAAkB,CAAC;AAEtE,WAAO,QAAQ,KAAK,MAAM,OAAO;AAAA,EAClC;AAEA,SAAO,SAAS,MAAA;AACjB;;;"}
@@ -3,28 +3,26 @@ const DEFAULT_RETRY_AFTER = 1500;
3
3
  const THROTTLED_RUNNERS = {};
4
4
  const DEDUPLICATED_JOBS = {};
5
5
  async function request(url, init, fetchFn) {
6
- var _a, _b;
7
6
  const stringURL = url.toString();
8
7
  let job;
9
- if (init == null ? void 0 : init.body) {
10
- const runner = THROTTLED_RUNNERS[_a = url.hostname] || (THROTTLED_RUNNERS[_a] = pLimit({
8
+ if (init?.body) {
9
+ const runner = THROTTLED_RUNNERS[url.hostname] ||= pLimit({
11
10
  interval: DEFAULT_RETRY_AFTER
12
- }));
11
+ });
13
12
  job = runner(() => fetchFn(stringURL, init));
14
13
  } else {
15
- const existingJob = (_b = DEDUPLICATED_JOBS[stringURL]) == null ? void 0 : _b.get(init == null ? void 0 : init.signal);
14
+ const existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal);
16
15
  if (existingJob) {
17
16
  job = existingJob;
18
17
  } else {
19
18
  job = fetchFn(stringURL, init).finally(() => {
20
- var _a2, _b2;
21
- (_a2 = DEDUPLICATED_JOBS[stringURL]) == null ? void 0 : _a2.delete(init == null ? void 0 : init.signal);
22
- if (((_b2 = DEDUPLICATED_JOBS[stringURL]) == null ? void 0 : _b2.size) === 0) {
19
+ DEDUPLICATED_JOBS[stringURL]?.delete(init?.signal);
20
+ if (DEDUPLICATED_JOBS[stringURL]?.size === 0) {
23
21
  delete DEDUPLICATED_JOBS[stringURL];
24
22
  }
25
23
  });
26
- const map = DEDUPLICATED_JOBS[stringURL] || (DEDUPLICATED_JOBS[stringURL] = /* @__PURE__ */ new Map());
27
- map.set(init == null ? void 0 : init.signal, job);
24
+ const map = DEDUPLICATED_JOBS[stringURL] ||= /* @__PURE__ */ new Map();
25
+ map.set(init?.signal, job);
28
26
  }
29
27
  }
30
28
  const response = await job;
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\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\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).finally(() => {\n\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t}\n\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.clone()\n}\n"],"names":["_a","_b"],"mappings":";AAOO,MAAM,sBAAsB;AAKnC,MAAM,oBAA4D,CAAA;AAMlE,MAAM,oBAEF,CAAA;AAgGkB,eAAA,QACrB,KACA,MACA,SAAkB;;AAEZ,QAAA,YAAY,IAAI;AAElB,MAAA;AAGJ,MAAI,6BAAM,MAAM;AAEf,UAAM,SAAU,uBAAkB,IAAI,cAAtB,wBAAoC,OAAO;AAAA,MAC1D,UAAU;AAAA,IAAA,CACV;AAED,UAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,CAAC;AAAA,EAAA,OACrC;AAEN,UAAM,eAAc,uBAAkB,SAAS,MAA3B,mBAA8B,IAAI,6BAAM;AAC5D,QAAI,aAAa;AACV,YAAA;AAAA,IAAA,OACA;AACN,YAAM,QAAQ,WAAW,IAAI,EAAE,QAAQ,MAAK;;AAC3C,SAAAA,MAAA,kBAAkB,SAAS,MAA3B,gBAAAA,IAA8B,OAAO,6BAAM;AAC3C,cAAIC,MAAA,kBAAkB,SAAS,MAA3B,gBAAAA,IAA8B,UAAS,GAAG;AAC7C,iBAAO,kBAAkB,SAAS;AAAA,QAAA;AAAA,MACnC,CACA;AACD,YAAM,MAAO,oFAAqC,IAAK;AACnD,UAAA,IAAI,6BAAM,QAAQ,GAAG;AAAA,IAAA;AAAA,EAC1B;AAGD,QAAM,WAAW,MAAM;AAGnB,MAAA,SAAS,WAAW,KAAK;AAC5B,UAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,aAAa,CAAC;AAC7D,UAAM,qBAAqB,OAAO,MAAM,UAAU,IAC/C,sBACA,aAAa;AAEhB,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,kBAAkB,CAAC;AAE/D,WAAA,QAAQ,KAAK,MAAM,OAAO;AAAA,EAAA;AAGlC,SAAO,SAAS,MAAK;AACtB;"}
1
+ {"version":3,"file":"request.js","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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/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// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\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\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).finally(() => {\n\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t}\n\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.clone()\n}\n"],"names":[],"mappings":";AAOO,MAAM,sBAAsB;AAKnC,MAAM,oBAA4D,CAAA;AAMlE,MAAM,oBAEF,CAAA;AAgGJ,eAAsB,QACrB,KACA,MACA,SAAkB;AAElB,QAAM,YAAY,IAAI,SAAA;AAEtB,MAAI;AAGJ,MAAI,MAAM,MAAM;AAEf,UAAM,SAAU,kBAAkB,IAAI,QAAQ,MAAM,OAAO;AAAA,MAC1D,UAAU;AAAA,IAAA,CACV;AAED,UAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,CAAC;AAAA,EAC5C,OAAO;AAEN,UAAM,cAAc,kBAAkB,SAAS,GAAG,IAAI,MAAM,MAAM;AAClE,QAAI,aAAa;AAChB,YAAM;AAAA,IACP,OAAO;AACN,YAAM,QAAQ,WAAW,IAAI,EAAE,QAAQ,MAAK;AAC3C,0BAAkB,SAAS,GAAG,OAAO,MAAM,MAAM;AACjD,YAAI,kBAAkB,SAAS,GAAG,SAAS,GAAG;AAC7C,iBAAO,kBAAkB,SAAS;AAAA,QACnC;AAAA,MACD,CAAC;AACD,YAAM,MAAO,kBAAkB,SAAS,0BAAU,IAAA;AAClD,UAAI,IAAI,MAAM,QAAQ,GAAG;AAAA,IAC1B;AAAA,EACD;AAEA,QAAM,WAAW,MAAM;AAGvB,MAAI,SAAS,WAAW,KAAK;AAC5B,UAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,aAAa,CAAC;AAC7D,UAAM,qBAAqB,OAAO,MAAM,UAAU,IAC/C,sBACA,aAAa;AAEhB,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,kBAAkB,CAAC;AAEtE,WAAO,QAAQ,KAAK,MAAM,OAAO;AAAA,EAClC;AAEA,SAAO,SAAS,MAAA;AACjB;"}
@@ -34,18 +34,17 @@ async function resolveMigrationContentRelationship(relation) {
34
34
  };
35
35
  }
36
36
  const resolveMigrationImage = (image, migration, withThumbnails) => {
37
- var _a;
38
37
  const { id: master, ...thumbnails } = image instanceof Asset.PrismicMigrationAsset ? { id: image } : image;
39
- const asset = (_a = migration._assets.get(master.config.id)) == null ? void 0 : _a.asset;
38
+ const asset = migration._assets.get(master.config.id)?.asset;
40
39
  const maybeInitialField = master.originalField;
41
40
  if (asset) {
42
- const parameters = ((maybeInitialField == null ? void 0 : maybeInitialField.url) || asset.url).split("?")[1];
41
+ const parameters = (maybeInitialField?.url || asset.url).split("?")[1];
43
42
  const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}`;
44
43
  const dimensions = {
45
44
  width: asset.width,
46
45
  height: asset.height
47
46
  };
48
- const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField == null ? void 0 : maybeInitialField.edit : { x: 0, y: 0, zoom: 1, background: "transparent" };
47
+ const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField?.edit : { x: 0, y: 0, zoom: 1, background: "transparent" };
49
48
  const alt = master.config.alt || asset.alt || null;
50
49
  const resolvedThumbnails = {};
51
50
  if (withThumbnails) {
@@ -79,8 +78,7 @@ const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
79
78
  }
80
79
  };
81
80
  const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
82
- var _a;
83
- const asset = (_a = migration._assets.get(linkToMedia.id.config.id)) == null ? void 0 : _a.asset;
81
+ const asset = migration._assets.get(linkToMedia.id.config.id)?.asset;
84
82
  const optionalLinkProperties = getOptionalLinkProperties.getOptionalLinkProperties(linkToMedia);
85
83
  if (asset) {
86
84
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"resolveMigrationDocumentData.cjs","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":["PrismicMigrationDocument","LinkType","getOptionalLinkProperties","isMigration.contentRelationship","PrismicMigrationAsset","RichTextNodeType","isFilled.link","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"mappings":";;;;;;;;;AAgCA,eAAsB,oCACrB,UAAiD;AAE7C,MAAA,OAAO,aAAa,YAAY;AAC5B,WAAA,oCAAoC,MAAM,UAAU;AAAA,EAAA;AAG5D,MAAI,oBAAoBA,SAAAA,0BAA0B;AACjD,WAAO,SAAS,SAAS,KACtB,EAAE,WAAWC,KAAS,SAAA,UAAU,IAAI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,SAAS;AAAA,EAAA;AAGhD,MAAA,OAAO,UAAU,YAAY;AAChC,WAAO,MAAM,6BAA6B,MAAM,MAAA,GAAS,SAAS;AAAA,EAAA;AAI/D,MAAA,MAAM,QAAQ,KAAK,GAAG;AACzB,UAAM,MAAM,CAAA;AAEZ,eAAW,WAAW,OAAO;AAC5B,UAAI,KAAK,MAAM,6BAA6B,SAAS,SAAS,CAAC;AAAA,IAAA;AAGzD,WAAA,IAAI,OAAO,OAAO;AAAA,EAAA;AAGtB,MAAA,SAAS,OAAO,UAAU,UAAU;AACvC,UAAM,MAAoC,CAAA;AAE1C,eAAW,OAAO,OAAO;AACxB,UAAI,GAAG,IAAI,MAAM,6BAChB,MAAM,GAAyB,GAC/B,SAAS;AAAA,IAAA;AAIJ,WAAA;AAAA,EAAA;AAID,SAAA;AACR;;;;;;"}
1
+ {"version":3,"file":"resolveMigrationDocumentData.cjs","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":["PrismicMigrationDocument","LinkType","getOptionalLinkProperties","isMigration.contentRelationship","PrismicMigrationAsset","RichTextNodeType","isFilled.link","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"mappings":";;;;;;;;;AAgCA,eAAsB,oCACrB,UAAiD;AAEjD,MAAI,OAAO,aAAa,YAAY;AACnC,WAAO,oCAAoC,MAAM,UAAU;AAAA,EAC5D;AAEA,MAAI,oBAAoBA,SAAAA,0BAA0B;AACjD,WAAO,SAAS,SAAS,KACtB,EAAE,WAAWC,KAAAA,SAAS,UAAU,IAAI,SAAS,SAAS,GAAA,IACtD,EAAE,WAAWA,KAAAA,SAAS,IAAA;AAAA,EAC1B;AAEA,QAAM,yBACL,YAAY,eAAe,WACxBC,0BAAAA,0BAA0B,QAAQ,IAClC;AAEJ,MAAI,UAAU;AACb,QACCC,iBAAAA,oBAAgC,SAAS,EAAE,KAC3C,OAAO,SAAS,OAAO,UACtB;AACD,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAI,MAAM,oCAAoC,SAAS,EAAE;AAAA,MAAA;AAAA,IAE3D;AAKA,WAAO;AAAA,MACN,GAAG;AAAA,MACH,WAAWF,KAAAA,SAAS;AAAA,MACpB,IAAI,SAAS;AAAA,IAAA;AAAA,EAEf;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,WAAWA,KAAAA,SAAS;AAAA,EAAA;AAEtB;AAWO,MAAM,wBAAwB,CACpC,OACA,WACA,mBACsC;AACtC,QAAM,EAAE,IAAI,QAAQ,GAAG,WAAA,IACtB,iBAAiBG,MAAAA,wBAAwB,EAAE,IAAI,MAAA,IAAU;AAE1D,QAAM,QAAQ,UAAU,QAAQ,IAAI,OAAO,OAAO,EAAE,GAAG;AACvD,QAAM,oBAAoB,OAAO;AAEjC,MAAI,OAAO;AACV,UAAM,cAAc,mBAAmB,OAAO,MAAM,K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V,WAAO;AAAA,MACN,GAAG;AAAA,MACH,IAAI,MAAM;AAAA,MACV,WAAWD,KAAAA,SAAS;AAAA,IAAA;AAAA,EAEtB;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,WAAWA,KAAAA,SAAS;AAAA,EAAA;AAEtB;AAWA,eAAsB,6BACrB,OACA,WAAoB;AAGpB,MAAIE,iBAAAA,oBAAgC,KAAK,GAAG;AAC3C,WAAO,oCAAoC,KAAK;AAAA,EACjD;AAEA,MAAII,iBAAAA,MAAkB,KAAK,GAAG;AAC7B,WAAO,sBAAsB,OAAO,WAAW,IAAI;AAAA,EACpD;AAEA,MAAIC,iBAAAA,YAAwB,KAAK,GAAG;AACnC,WAAO,4BAA4B,OAAO,SAAS;AAAA,EACpD;AAEA,MAAIC,iBAAAA,YAAwB,KAAK,GAAG;AACnC,WAAO,4BAA4B,OAAO,SAAS;AAAA,EACpD;AAEA,MAAI,OAAO,UAAU,YAAY;AAChC,WAAO,MAAM,6BAA6B,MAAM,MAAA,GAAS,SAAS;AAAA,EACnE;AAGA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,UAAM,MAAM,CAAA;AAEZ,eAAW,WAAW,OAAO;AAC5B,UAAI,KAAK,MAAM,6BAA6B,SAAS,SAAS,CAAC;AAAA,IAChE;AAEA,WAAO,IAAI,OAAO,OAAO;AAAA,EAC1B;AAEA,MAAI,SAAS,OAAO,UAAU,UAAU;AACvC,UAAM,MAAoC,CAAA;AAE1C,eAAW,OAAO,OAAO;AACxB,UAAI,GAAG,IAAI,MAAM,6BAChB,MAAM,GAAyB,GAC/B,SAAS;AAAA,IAEX;AAEA,WAAO;AAAA,EACR;AAGA,SAAO;AACR;;;;;;"}
@@ -1,11 +1,11 @@
1
- import type { MigrationLinkToMediaField } from "../types/migration/Asset";
2
- import { type MigrationImage, type MigrationLinkToMedia, type MigrationRTImageNode } from "../types/migration/Asset";
3
- import type { MigrationContentRelationship, MigrationContentRelationshipField } from "../types/migration/ContentRelationship";
4
- import type { MaybeLink } from "../types/migration/Link";
5
- import type { FilledImageFieldImage } from "../types/value/image";
6
- import type { OptionalLinkProperties } from "../types/value/link";
7
- import type { RTImageNode } from "../types/value/richText";
8
- import type { Migration } from "../Migration";
1
+ import type { MigrationLinkToMediaField } from "../types/migration/Asset.js";
2
+ import { type MigrationImage, type MigrationLinkToMedia, type MigrationRTImageNode } from "../types/migration/Asset.js";
3
+ import type { MigrationContentRelationship, MigrationContentRelationshipField } from "../types/migration/ContentRelationship.js";
4
+ import type { MaybeLink } from "../types/migration/Link.js";
5
+ import type { FilledImageFieldImage } from "../types/value/image.js";
6
+ import type { OptionalLinkProperties } from "../types/value/link.js";
7
+ import type { RTImageNode } from "../types/value/richText.js";
8
+ import type { Migration } from "../Migration.js";
9
9
  /**
10
10
  * Resolves a migration content relationship to a content relationship field.
11
11
  *
@@ -32,18 +32,17 @@ async function resolveMigrationContentRelationship(relation) {
32
32
  };
33
33
  }
34
34
  const resolveMigrationImage = (image2, migration, withThumbnails) => {
35
- var _a;
36
35
  const { id: master, ...thumbnails } = image2 instanceof PrismicMigrationAsset ? { id: image2 } : image2;
37
- const asset = (_a = migration._assets.get(master.config.id)) == null ? void 0 : _a.asset;
36
+ const asset = migration._assets.get(master.config.id)?.asset;
38
37
  const maybeInitialField = master.originalField;
39
38
  if (asset) {
40
- const parameters = ((maybeInitialField == null ? void 0 : maybeInitialField.url) || asset.url).split("?")[1];
39
+ const parameters = (maybeInitialField?.url || asset.url).split("?")[1];
41
40
  const url = `${asset.url.split("?")[0]}${parameters ? `?${parameters}` : ""}`;
42
41
  const dimensions = {
43
42
  width: asset.width,
44
43
  height: asset.height
45
44
  };
46
- const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField == null ? void 0 : maybeInitialField.edit : { x: 0, y: 0, zoom: 1, background: "transparent" };
45
+ const edit = maybeInitialField && "edit" in maybeInitialField ? maybeInitialField?.edit : { x: 0, y: 0, zoom: 1, background: "transparent" };
47
46
  const alt = master.config.alt || asset.alt || null;
48
47
  const resolvedThumbnails = {};
49
48
  if (withThumbnails) {
@@ -77,8 +76,7 @@ const resolveMigrationRTImageNode = async (rtImageNode2, migration) => {
77
76
  }
78
77
  };
79
78
  const resolveMigrationLinkToMedia = (linkToMedia2, migration) => {
80
- var _a;
81
- const asset = (_a = migration._assets.get(linkToMedia2.id.config.id)) == null ? void 0 : _a.asset;
79
+ const asset = migration._assets.get(linkToMedia2.id.config.id)?.asset;
82
80
  const optionalLinkProperties = getOptionalLinkProperties(linkToMedia2);
83
81
  if (asset) {
84
82
  return {
@@ -1 +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.rtIm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AwB,KAAK,GAAG;AAC5B,WAAA,4BAA4B,OAAO,SAAS;AAAA,EAAA;AAGhD,MAAAC,YAAwB,KAAK,GAAG;AAC5B,WAAA,4BAA4B,OAAO,SAAS;AAAA,EAAA;AAGhD,MAAA,OAAO,UAAU,YAAY;AAChC,WAAO,MAAM,6BAA6B,MAAM,MAAA,GAAS,SAAS;AAAA,EAAA;AAI/D,MAAA,MAAM,QAAQ,KAAK,GAAG;AACzB,UAAM,MAAM,CAAA;AAEZ,eAAW,WAAW,OAAO;AAC5B,UAAI,KAAK,MAAM,6BAA6B,SAAS,SAAS,CAAC;AAAA,IAAA;AAGzD,WAAA,IAAI,OAAO,OAAO;AAAA,EAAA;AAGtB,MAAA,SAAS,OAAO,UAAU,UAAU;AACvC,UAAM,MAAoC,CAAA;AAE1C,eAAW,OAAO,OAAO;AACxB,UAAI,GAAG,IAAI,MAAM,6BAChB,MAAM,GAAyB,GAC/B,SAAS;AAAA,IAAA;AAIJ,WAAA;AAAA,EAAA;AAID,SAAA;AACR;"}
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":";;;;;;;AAgCA,eAAsB,oCACrB,UAAiD;AAEjD,MAAI,OAAO,aAAa,YAAY;AACnC,WAAO,oCAAoC,MAAM,UAAU;AAAA,EAC5D;AAEA,MAAI,oBAAoB,0BAA0B;AACjD,WAAO,SAAS,SAAS,KACtB,EAAE,WAAW,SAAS,UAAU,IAAI,SAAS,SAAS,GAAA,IACtD,EAAE,WAAW,SAAS,IAAA;AAAA,EAC1B;AAEA,QAAM,yBACL,YAAY,eAAe,WACxB,0BAA0B,QAAQ,IAClC;AAEJ,MAAI,UAAU;AACb,QACCA,oBAAgC,SAAS,EAAE,KAC3C,OAAO,SAAS,OAAO,UACtB;AACD,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAI,MAAM,oCAAoC,SAAS,EAAE;AAAA,MAAA;AAAA,IAE3D;AAKA,WAAO;AAAA,MACN,GAAG;AAAA,MACH,WAAW,SAAS;AAAA,MACpB,IAAI,SAAS;AAAA,IAAA;AAAA,EAEf;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,WAAW,SAAS;AAAA,EAAA;AAEtB;AAWO,MAAM,wBAAwB,CACpCC,QACA,WACA,mBACsC;AACtC,QAAM,EAAE,IAAI,QAAQ,GAAG,WAAA,IACtBA,kBAAiB,wBAAwB,EAAE,IAAIA,OAAA,IAAUA;AAE1D,QAAM,QAAQ,UAAU,QAAQ,IAAI,OAAO,OAAO,EAAE,GAAG;AACvD,QAAM,oBAAoB,OAAO;AAEjC,MAAI,OAAO;AACV,UAAM,cAAc,mBAAmB,OAAO,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AAA,MACN,GAAG;AAAA,MACH,IAAI,MAAM;AAAA,MACV,WAAW,SAAS;AAAA,IAAA;AAAA,EAEtB;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,WAAW,SAAS;AAAA,EAAA;AAEtB;AAWA,eAAsB,6BACrB,OACA,WAAoB;AAGpB,MAAIJ,oBAAgC,KAAK,GAAG;AAC3C,WAAO,oCAAoC,KAAK;AAAA,EACjD;AAEA,MAAIK,MAAkB,KAAK,GAAG;AAC7B,WAAO,sBAAsB,OAAO,WAAW,IAAI;AAAA,EACpD;AAEA,MAAIC,YAAwB,KAAK,GAAG;AACnC,WAAO,4BAA4B,OAAO,SAAS;AAAA,EACpD;AAEA,MAAIC,YAAwB,KAAK,GAAG;AACnC,WAAO,4BAA4B,OAAO,SAAS;AAAA,EACpD;AAEA,MAAI,OAAO,UAAU,YAAY;AAChC,WAAO,MAAM,6BAA6B,MAAM,MAAA,GAAS,SAAS;AAAA,EACnE;AAGA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,UAAM,MAAM,CAAA;AAEZ,eAAW,WAAW,OAAO;AAC5B,UAAI,KAAK,MAAM,6BAA6B,SAAS,SAAS,CAAC;AAAA,IAChE;AAEA,WAAO,IAAI,OAAO,OAAO;AAAA,EAC1B;AAEA,MAAI,SAAS,OAAO,UAAU,UAAU;AACvC,UAAM,MAAoC,CAAA;AAE1C,eAAW,OAAO,OAAO;AACxB,UAAI,GAAG,IAAI,MAAM,6BAChB,MAAM,GAAyB,GAC/B,SAAS;AAAA,IAEX;AAEA,WAAO;AAAA,EACR;AAGA,SAAO;AACR;"}
@@ -32,9 +32,9 @@ const getGeneralAttributes = (serializerOrShorthand) => {
32
32
  };
33
33
  const serializeStandardTag = (tag, serializerOrShorthand) => {
34
34
  const generalAttributes = getGeneralAttributes(serializerOrShorthand);
35
- return ({ node, children }) => {
35
+ return (({ node, children }) => {
36
36
  return `<${tag}${formatAttributes(node, generalAttributes)}>${children}</${tag}>`;
37
- };
37
+ });
38
38
  };
39
39
  const serializePreFormatted = (serializerOrShorthand) => {
40
40
  const generalAttributes = getGeneralAttributes(serializerOrShorthand);
@@ -1 +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","asL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AAK,cAAcA,KAAAA,SAAS,UAAU;AACrD,iBAAW,OAAOC,OAAO,OAAA,KAAK,MAAM,EAAE,cAAc;AAAA,IAC1C,WAAA,KAAK,KAAK,cAAcD,KAAAA,SAAS,OAAO;AACvC,iBAAA,OAAO,KAAK,KAAK;AAAA,IAAA;AAG7B,WAAO,KAAK,iBAAiB,MAAM,UAAU,CAAC,IAAI,QAAQ;AAAA,EAC3D;AACD;AAEO,MAAM,gBAAgB,MAEzB;AACI,SAAA,CAAC,EAAE,WAAkB;AAC3B,WAAO,OAAOD,WAAAA,WAAW,IAAI,EAAE,QAAQ,OAAO,QAAQ,IAAI;AAAA,EAC3D;AACD;;;;;;;"}
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":";;;;;AAcA,MAAM,mBAAmB,CAAC,MAAiB,eAAkC;AAC5E,QAAM,cAAc,EAAE,GAAG,WAAA;AAGzB,MAAI,eAAe,QAAQ,KAAK,cAAc,OAAO;AACpD,gBAAY,MAAM,KAAK;AAAA,EACxB;AAGA,MAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,OAAO;AAC9D,gBAAY,QAAQ,YAAY,QAC7B,GAAG,YAAY,KAAK,IAAI,KAAK,KAAK,KAAK,KACvC,KAAK,KAAK;AAAA,EACd;AAEA,QAAM,SAAS,CAAA;AAEf,aAAW,OAAO,aAAa;AAC9B,UAAM,QAAQ,YAAY,GAAG;AAE7B,QAAI,OAAO;AACV,UAAI,OAAO,UAAU,WAAW;AAC/B,eAAO,KAAK,GAAG;AAAA,MAChB,OAAO;AACN,eAAO,KAAK,GAAG,GAAG,KAAKA,sBAAW,KAAK,CAAC,GAAG;AAAA,MAC5C;AAAA,IACD;AAAA,EACD;AAGA,MAAI,OAAO,QAAQ;AAClB,WAAO,QAAQ,EAAE;AAAA,EAClB;AAEA,SAAO,OAAO,KAAK,GAAG;AACvB;AAEA,MAAM,uBAAuB,CAC5B,0BACe;AACf,SAAO,yBAAyB,OAAO,0BAA0B,aAC9D,wBACA,CAAA;AACJ;AAEO,MAAM,uBAAuB,CAGnC,KACA,0BAC4D;AAC5D,QAAM,oBAAoB,qBAAqB,qBAAqB;AAEpE,UAAQ,CAAC,EAAE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,KAAK,OAAO,IAAI;AAAA,EACrE;AACD;AAEO,MAAM,qBAAqB,CACjC,cAIA,0BAC8D;AAC9D,QAAM,oBAAoB,qBAAqB,qBAAqB;AAEpE,SAAO,CAAC,EAAE,MAAM,eAAsB;AACrC,UAAM,aAAa;AAAA,MAClB,GAAG;AAAA,IAAA;AAGJ,QAAI,KAAK,KAAK,cAAcC,KAAAA,SAAS,KAAK;AACzC,iBAAW,OAAO,KAAK,KAAK;AAC5B,iBAAW,SAAS,KAAK,KAAK;AAC9B,iBAAW,MAAM;AAAA,IAClB,WAAW,KAAK,KAAK,cAAcA,KAAAA,SAAS,UAAU;AACrD,iBAAW,OAAOC,OAAAA,OAAO,KAAK,MAAM,EAAE,cAAc;AAAA,IACrD,WAAW,KAAK,KAAK,cAAcD,KAAAA,SAAS,OAAO;AAClD,iBAAW,OAAO,KAAK,KAAK;AAAA,IAC7B;AAEA,WAAO,KAAK,iBAAiB,MAAM,UAAU,CAAC,IAAI,QAAQ;AAAA,EAC3D;AACD;AAEO,MAAM,gBAAgB,MAEzB;AACH,SAAO,CAAC,EAAE,WAAkB;AAC3B,WAAO,OAAOD,WAAAA,WAAW,IAAI,EAAE,QAAQ,OAAO,QAAQ,IAAI;AAAA,EAC3D;AACD;;;;;;;"}
@@ -1,6 +1,6 @@
1
- import type { RichTextMapSerializer } from "../richtext/types";
2
- import type { HTMLRichTextMapSerializer, HTMLStrictRichTextMapSerializer } from "../helpers/asHTML";
3
- import type { LinkResolverFunction } from "../helpers/asLink";
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
4
  export declare const serializeStandardTag: <BlockType extends keyof RichTextMapSerializer<string>>(tag: string, serializerOrShorthand?: HTMLRichTextMapSerializer[BlockType]) => NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>;
5
5
  export declare const serializePreFormatted: (serializerOrShorthand?: HTMLRichTextMapSerializer["preformatted"]) => NonNullable<HTMLStrictRichTextMapSerializer["preformatted"]>;
6
6
  export declare const serializeImage: (linkResolver: LinkResolverFunction<string | null | undefined> | undefined | null, serializerOrShorthand?: HTMLRichTextMapSerializer["image"]) => NonNullable<HTMLStrictRichTextMapSerializer["image"]>;
@@ -30,9 +30,9 @@ const getGeneralAttributes = (serializerOrShorthand) => {
30
30
  };
31
31
  const serializeStandardTag = (tag, serializerOrShorthand) => {
32
32
  const generalAttributes = getGeneralAttributes(serializerOrShorthand);
33
- return ({ node, children }) => {
33
+ return (({ node, children }) => {
34
34
  return `<${tag}${formatAttributes(node, generalAttributes)}>${children}</${tag}>`;
35
- };
35
+ });
36
36
  };
37
37
  const serializePreFormatted = (serializerOrShorthand) => {
38
38
  const generalAttributes = getGeneralAttributes(serializerOrShorthand);
@@ -1 +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":";;;AAcA,MAAM,mBAAmB,CAAC,MAAiB,eAAkC;AACtE,QAAA,cAAc,EAAE,GAAG;AAGzB,MAAI,eAAe,QAAQ,KAAK,cAAc,OAAO;AACpD,gBAAY,MAAM,KAAK;AAAA,EAAA;AAIxB,MAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,OAAO;AAC9D,gBAAY,QAAQ,YAAY,QAC7B,GAAG,YAAY,KAAK,IAAI,KAAK,KAAK,KAAK,KACvC,KAAK,KAAK;AAAA,EAAA;AAGd,QAAM,SAAS,CAAA;AAEf,aAAW,OAAO,aAAa;AACxB,UAAA,QAAQ,YAAY,GAAG;AAE7B,QAAI,OAAO;AACN,UAAA,OAAO,UAAU,WAAW;AAC/B,eAAO,KAAK,GAAG;AAAA,MAAA,OACT;AACN,eAAO,KAAK,GAAG,GAAG,KAAK,WAAW,KAAK,CAAC,GAAG;AAAA,MAAA;AAAA,IAC5C;AAAA,EACD;AAID,MAAI,OAAO,QAAQ;AAClB,WAAO,QAAQ,EAAE;AAAA,EAAA;AAGX,SAAA,OAAO,KAAK,GAAG;AACvB;AAEA,MAAM,uBAAuB,CAC5B,0BACe;AACf,SAAO,yBAAyB,OAAO,0BAA0B,aAC9D,wBACA;AACJ;AAEa,MAAA,uBAAuB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K,OAAO;AAAA;AAGhC,WAAA,OAAO,iBAAiB,MAAM,UAAU,CAAC,IAAI,KAAK,OAAO,IAAI;AAAA,EACrE;AACD;AAEa,MAAA,qBAAqB,CACjC,cAIA,0BAC8D;AACxD,QAAA,oBAAoB,qBAAqB,qBAAqB;AAEpE,SAAO,CAAC,EAAE,MAAM,eAAsB;AACrC,UAAM,aAAa;AAAA,MAClB,GAAG;AAAA;AAGJ,QAAI,KAAK,KAAK,cAAc,SAAS,KAAK;AAC9B,iBAAA,OAAO,KAAK,KAAK;AACjB,iBAAA,SAAS,KAAK,KAAK;AAC9B,iBAAW,MAAM;AAAA,IACP,WAAA,KAAK,KAAK,cAAc,SAAS,UAAU;AACrD,iBAAW,OAAO,OAAO,KAAK,MAAM,EAAE,cAAc;AAAA,IAC1C,WAAA,KAAK,KAAK,cAAc,SAAS,OAAO;AACvC,iBAAA,OAAO,KAAK,KAAK;AAAA,IAAA;AAG7B,WAAO,KAAK,iBAAiB,MAAM,UAAU,CAAC,IAAI,QAAQ;AAAA,EAC3D;AACD;AAEO,MAAM,gBAAgB,MAEzB;AACI,SAAA,CAAC,EAAE,WAAkB;AAC3B,WAAO,OAAO,WAAW,IAAI,EAAE,QAAQ,OAAO,QAAQ,IAAI;AAAA,EAC3D;AACD;"}
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":";;;AAcA,MAAM,mBAAmB,CAAC,MAAiB,eAAkC;AAC5E,QAAM,cAAc,EAAE,GAAG,WAAA;AAGzB,MAAI,eAAe,QAAQ,KAAK,cAAc,OAAO;AACpD,gBAAY,MAAM,KAAK;AAAA,EACxB;AAGA,MAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,OAAO;AAC9D,gBAAY,QAAQ,YAAY,QAC7B,GAAG,YAAY,KAAK,IAAI,KAAK,KAAK,KAAK,KACvC,KAAK,KAAK;AAAA,EACd;AAEA,QAAM,SAAS,CAAA;AAEf,aAAW,OAAO,aAAa;AAC9B,UAAM,QAAQ,YAAY,GAAG;AAE7B,QAAI,OAAO;AACV,UAAI,OAAO,UAAU,WAAW;AAC/B,eAAO,KAAK,GAAG;AAAA,MAChB,OAAO;AACN,eAAO,KAAK,GAAG,GAAG,KAAK,WAAW,KAA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C;AACD;AAEO,MAAM,iBAAiB,CAC7B,0BAC0D;AAC1D,QAAM,oBAAoB,qBAAqB,qBAAqB;AAEpE,SAAO,CAAC,EAAE,WAAU;AACnB,UAAM,aAAa;AAAA,MAClB,GAAG;AAAA,MACH,CAAC,aAAa,GAAG,KAAK,OAAO;AAAA,MAC7B,CAAC,kBAAkB,GAAG,KAAK,OAAO;AAAA,MAClC,CAAC,sBAAsB,GAAG,KAAK,OAAO;AAAA,IAAA;AAGvC,WAAO,OAAO,iBAAiB,MAAM,UAAU,CAAC,IAAI,KAAK,OAAO,IAAI;AAAA,EACrE;AACD;AAEO,MAAM,qBAAqB,CACjC,cAIA,0BAC8D;AAC9D,QAAM,oBAAoB,qBAAqB,qBAAqB;AAEpE,SAAO,CAAC,EAAE,MAAM,eAAsB;AACrC,UAAM,aAAa;AAAA,MAClB,GAAG;AAAA,IAAA;AAGJ,QAAI,KAAK,KAAK,cAAc,SAAS,KAAK;AACzC,iBAAW,OAAO,KAAK,KAAK;AAC5B,iBAAW,SAAS,KAAK,KAAK;AAC9B,iBAAW,MAAM;AAAA,IAClB,WAAW,KAAK,KAAK,cAAc,SAAS,UAAU;AACrD,iBAAW,OAAO,OAAO,KAAK,MAAM,EAAE,cAAc;AAAA,IACrD,WAAW,KAAK,KAAK,cAAc,SAAS,OAAO;AAClD,iBAAW,OAAO,KAAK,KAAK;AAAA,IAC7B;AAEA,WAAO,KAAK,iBAAiB,MAAM,UAAU,CAAC,IAAI,QAAQ;AAAA,EAC3D;AACD;AAEO,MAAM,gBAAgB,MAEzB;AACH,SAAO,CAAC,EAAE,WAAkB;AAC3B,WAAO,OAAO,WAAW,IAAI,EAAE,QAAQ,OAAO,QAAQ,IAAI;AAAA,EAC3D;AACD;"}
@@ -1 +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":";;;;AAYa,MAAA,iBAAiB,CAAC,SAAmC;AACjE,SAAOA,OAAO,OAAA,IAAI,iBAAiBC,UAAA,UAAU,IAAI,CAAC;AACnD;;"}
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;;"}
@@ -1 +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":";;AAYa,MAAA,iBAAiB,CAAC,SAAmC;AACjE,SAAO,OAAO,IAAI,iBAAiB,UAAU,IAAI,CAAC;AACnD;"}
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;"}
@@ -1 +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;AACH,QAAA,EAAE,QAAQ,MAAA,IAAU;AAE1B,MACC,YAAY,eACZ,KAAK,IAAK,IAAG,eAAe,uBAC3B;AACD,mBAAe,KAAK;AAEpB;AAAA,EAAA;AAGD,iBAAe,KAAK;AACN,gBAAA;AAGN,UAAA,KAAK,EAAE,OAAO;AACvB;;"}
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;;"}
@@ -1 +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;AACH,QAAA,EAAE,QAAQ,MAAA,IAAU;AAE1B,MACC,YAAY,eACZ,KAAK,IAAK,IAAG,eAAe,uBAC3B;AACD,mBAAe,KAAK;AAEpB;AAAA,EAAA;AAGD,iBAAe,KAAK;AACN,gBAAA;AAGN,UAAA,KAAK,EAAE,OAAO;AACvB;"}
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;"}
@@ -1 +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":";;;AASa,MAAA,aAAa,CAAC,iBAAgC;AACnD,SAAAA,cAAO,GAAG,iBAAiB,YAAY;AAC/C;;"}
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;;"}
@@ -1 +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":";AASa,MAAA,aAAa,CAAC,iBAAgC;AACnD,SAAA,OAAO,GAAG,iBAAiB,YAAY;AAC/C;"}
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;"}
@@ -1 +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;AAErB,MAAA,SAAS,MAAM,SAAS,wBAAwB;AAC5C,WAAA,KACN,6BAA6B,sBAAsB,aAAa;AAAA,EAAA;AAI9D,MAAA,WAAW,QAAQ,SAAS,0BAA0B;AAClD,WAAA,KACN,+BAA+B,wBAAwB,aAAa;AAAA,EAAA;AAIlE,MAAA,OAAO,IAAI,SAAS,sBAAsB;AACtC,WAAA,KAAK,2BAA2B,oBAAoB,aAAa;AAAA,EAAA;AAGzE,MACC,QACA,KAAK,UACL,KAAK,KACJ,CAAC,QACA,IAAI,SAAS,wBAAwB,IAAI,SAAS,oBAAoB,GAEvE;AACD,WAAO,KACN,mEAAmE;AAAA,EAAA;AAIrE,MAAI,OAAO,QAAQ;AAClB,UAAM,IAAIA,aAAAA,aACT,qCAAqC,OAAO,KAAK,IAAI,CAAC,IACtD,QACA,EAAE,OAAO,SAAS,KAAK,MAAM;AAAA,EAAA;AAGhC;;"}
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;;"}
@@ -1,4 +1,4 @@
1
- import type { CreateAssetParams } from "../WriteClient";
1
+ import type { CreateAssetParams } from "../WriteClient.js";
2
2
  /**
3
3
  * Validates an asset's metadata, throwing an error if any of the metadata are
4
4
  * invalid.
@@ -1 +1 @@
1
- {"version":3,"file":"validateAssetMetadata.js","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":[],"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;AAErB,MAAA,SAAS,MAAM,SAAS,wBAAwB;AAC5C,WAAA,KACN,6BAA6B,sBAAsB,aAAa;AAAA,EAAA;AAI9D,MAAA,WAAW,QAAQ,SAAS,0BAA0B;AAClD,WAAA,KACN,+BAA+B,wBAAwB,aAAa;AAAA,EAAA;AAIlE,MAAA,OAAO,IAAI,SAAS,sBAAsB;AACtC,WAAA,KAAK,2BAA2B,oBAAoB,aAAa;AAAA,EAAA;AAGzE,MACC,QACA,KAAK,UACL,KAAK,KACJ,CAAC,QACA,IAAI,SAAS,wBAAwB,IAAI,SAAS,oBAAoB,GAEvE;AACD,WAAO,KACN,mEAAmE;AAAA,EAAA;AAIrE,MAAI,OAAO,QAAQ;AAClB,UAAM,IAAI,aACT,qCAAqC,OAAO,KAAK,IAAI,CAAC,IACtD,QACA,EAAE,OAAO,SAAS,KAAK,MAAM;AAAA,EAAA;AAGhC;"}
1
+ {"version":3,"file":"validateAssetMetadata.js","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":[],"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,IAAI,aACT,qCAAqC,OAAO,KAAK,IAAI,CAAC,IACtD,QACA,EAAE,OAAO,SAAS,KAAK,MAAM;AAAA,EAE/B;AACD;"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const name = "@prismicio/client";
4
- const version = "7.20.2-alpha.0";
4
+ const version = "7.20.3";
5
5
  exports.name = name;
6
6
  exports.version = version;
7
7
  //# sourceMappingURL=package.json.cjs.map
@@ -1,5 +1,5 @@
1
1
  const name = "@prismicio/client";
2
- const version = "7.20.2-alpha.0";
2
+ const version = "7.20.3";
3
3
  export {
4
4
  name,
5
5
  version