@seedprotocol/sdk 0.7.3-next.613.g79a8dfd → 0.7.4-next.711.gce2b766

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 (239) hide show
  1. package/dist/{db-CQt-gcAl.js → BasePathResolver-Cm4apKRb.js} +2041 -127
  2. package/dist/BasePathResolver-Cm4apKRb.js.map +1 -0
  3. package/dist/{ClientManager-DDA9956Y.js → ClientManager-i3nJASkg.js} +664 -277
  4. package/dist/ClientManager-i3nJASkg.js.map +1 -0
  5. package/dist/{Item-D4FigtYS.js → Item-DBFchXpC.js} +495 -219
  6. package/dist/Item-DBFchXpC.js.map +1 -0
  7. package/dist/{ModelProperty-BDt6AU2h.js → ModelProperty-BS49g01Y.js} +167 -47
  8. package/dist/ModelProperty-BS49g01Y.js.map +1 -0
  9. package/dist/{Schema-B8xqLWkL.js → Schema-CpMNEnUO.js} +53 -42
  10. package/dist/Schema-CpMNEnUO.js.map +1 -0
  11. package/dist/{SchemaValidationService-BPxkfDLU.js → SchemaValidationService-DieV4KL-.js} +13 -14
  12. package/dist/{SchemaValidationService-BPxkfDLU.js.map → SchemaValidationService-DieV4KL-.js.map} +1 -1
  13. package/dist/{backfillMetadataPropertyIds-DuTPcv8t.js → backfillMetadataPropertyIds-DSoOoTnX.js} +14 -7
  14. package/dist/{backfillMetadataPropertyIds-DuTPcv8t.js.map → backfillMetadataPropertyIds-DSoOoTnX.js.map} +1 -1
  15. package/dist/{configurePlatform-YcOiDQBZ.js → configurePlatform-D0lQGAMQ.js} +8 -7
  16. package/dist/{configurePlatform-YcOiDQBZ.js.map → configurePlatform-D0lQGAMQ.js.map} +1 -1
  17. package/dist/detachRowsBeforeDelete-S0q-DJPT.js +50 -0
  18. package/dist/detachRowsBeforeDelete-S0q-DJPT.js.map +1 -0
  19. package/dist/{eas-CpOD74Ke.js → eas-6pjU-OuX.js} +9 -8
  20. package/dist/eas-6pjU-OuX.js.map +1 -0
  21. package/dist/{getItem-B_OoFkd7.js → getItem-CxBNZ-WL.js} +13 -11
  22. package/dist/{getItem-B_OoFkd7.js.map → getItem-CxBNZ-WL.js.map} +1 -1
  23. package/dist/{getPublishPayload-Xl3sRkR-.js → getPublishPayload-CTCvRUoU.js} +50 -18
  24. package/dist/getPublishPayload-CTCvRUoU.js.map +1 -0
  25. package/dist/getPublishUploads-SFHCbf_y.js +648 -0
  26. package/dist/getPublishUploads-SFHCbf_y.js.map +1 -0
  27. package/dist/{index-Xl1_4Lmb.js → index-8O3Uow-Y.js} +125 -57
  28. package/dist/index-8O3Uow-Y.js.map +1 -0
  29. package/dist/{index-CSOQFAOn.js → index-AVFTVp1m.js} +2 -2
  30. package/dist/index-AVFTVp1m.js.map +1 -0
  31. package/dist/index-Cvt5UBz4.js +30 -0
  32. package/dist/index-Cvt5UBz4.js.map +1 -0
  33. package/dist/{index.browser-CjTe0vt1.js → index.browser-DBhxRoe8.js} +554 -165
  34. package/dist/index.browser-DBhxRoe8.js.map +1 -0
  35. package/dist/{index.node-Cfa7npS6.js → index.node-CJhlcNHM.js} +25 -13
  36. package/dist/index.node-CJhlcNHM.js.map +1 -0
  37. package/dist/main.js +30 -47
  38. package/dist/main.js.map +1 -1
  39. package/dist/mimeTypes-DHAHC4eZ.js +204 -0
  40. package/dist/mimeTypes-DHAHC4eZ.js.map +1 -0
  41. package/dist/node.js +19 -21
  42. package/dist/node.js.map +1 -1
  43. package/dist/platform.browser.js +13 -11
  44. package/dist/platform.browser.js.map +1 -1
  45. package/dist/platform.node.js +18 -5
  46. package/dist/platform.node.js.map +1 -1
  47. package/dist/{property-BrXkY1Rg.js → property-DwPD283A.js} +14 -12
  48. package/dist/property-DwPD283A.js.map +1 -0
  49. package/dist/{publishDraftGraph-X0Wr9txE.js → publishDraftGraph-BOn3_Occ.js} +6 -9
  50. package/dist/{publishDraftGraph-X0Wr9txE.js.map → publishDraftGraph-BOn3_Occ.js.map} +1 -1
  51. package/dist/{resetAmbiguousLegacyItemData-Ci6PM_vC.js → resetAmbiguousLegacyItemData-BkYmBeJc.js} +14 -3
  52. package/dist/{resetAmbiguousLegacyItemData-Ci6PM_vC.js.map → resetAmbiguousLegacyItemData-BkYmBeJc.js.map} +1 -1
  53. package/dist/{resolveModelForSyncedSeed-DFVdnYq8.js → resolveModelForSyncedSeed-BL24nLa7.js} +2 -2
  54. package/dist/{resolveModelForSyncedSeed-DFVdnYq8.js.map → resolveModelForSyncedSeed-BL24nLa7.js.map} +1 -1
  55. package/dist/src/Item/Item.d.ts +21 -3
  56. package/dist/src/Item/Item.d.ts.map +1 -1
  57. package/dist/src/Item/service/actors/runPublish.d.ts +11 -2
  58. package/dist/src/Item/service/actors/runPublish.d.ts.map +1 -1
  59. package/dist/src/Item/service/itemMachineSingle.d.ts +12 -2
  60. package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
  61. package/dist/src/ItemProperty/ItemProperty.d.ts +5 -3
  62. package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
  63. package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
  64. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
  65. package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
  66. package/dist/src/Model/Model.d.ts +10 -4
  67. package/dist/src/Model/Model.d.ts.map +1 -1
  68. package/dist/src/Model/index.d.ts +2 -2
  69. package/dist/src/ModelProperty/ModelProperty.d.ts +10 -2
  70. package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
  71. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +3 -0
  72. package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
  73. package/dist/src/Schema/Schema.d.ts +2 -2
  74. package/dist/src/Schema/Schema.d.ts.map +1 -1
  75. package/dist/src/Schema/index.d.ts +0 -1
  76. package/dist/src/Schema/index.d.ts.map +1 -1
  77. package/dist/src/browser/helpers/FileManager.d.ts +4 -1
  78. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  79. package/dist/src/browser/helpers/tolerantWebAccess.d.ts +79 -4
  80. package/dist/src/browser/helpers/tolerantWebAccess.d.ts.map +1 -1
  81. package/dist/src/browser/workers/FileDownloader.d.ts +19 -4
  82. package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
  83. package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
  84. package/dist/src/client/ClientManager.d.ts +30 -11
  85. package/dist/src/client/ClientManager.d.ts.map +1 -1
  86. package/dist/src/client/actors/platformClassesInit.d.ts +6 -0
  87. package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
  88. package/dist/src/client/actors/processSchemaFiles.d.ts.map +1 -1
  89. package/dist/src/client/actors/saveConfig.d.ts +13 -6
  90. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  91. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  92. package/dist/src/db/migrateLegacyItemStorageRows.d.ts +57 -0
  93. package/dist/src/db/migrateLegacyItemStorageRows.d.ts.map +1 -0
  94. package/dist/src/db/read/getCompositeChildPaths.d.ts +13 -0
  95. package/dist/src/db/read/getCompositeChildPaths.d.ts.map +1 -0
  96. package/dist/src/db/read/getItems.d.ts.map +1 -1
  97. package/dist/src/db/read/getPublishPayload.d.ts +1 -1
  98. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  99. package/dist/src/db/read/getPublishUploads.d.ts +32 -3
  100. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  101. package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
  102. package/dist/src/db/write/claimUnpublishedDrafts.d.ts +2 -0
  103. package/dist/src/db/write/claimUnpublishedDrafts.d.ts.map +1 -1
  104. package/dist/src/db/write/convertVerbatimItemStorageRow.d.ts +44 -0
  105. package/dist/src/db/write/convertVerbatimItemStorageRow.d.ts.map +1 -0
  106. package/dist/src/db/write/createNewItem.d.ts.map +1 -1
  107. package/dist/src/eventBus.d.ts +5 -0
  108. package/dist/src/eventBus.d.ts.map +1 -1
  109. package/dist/src/events/files/download.d.ts.map +1 -1
  110. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +3 -3
  111. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  112. package/dist/src/helpers/FileManager/IFileManager.d.ts +25 -1
  113. package/dist/src/helpers/FileManager/IFileManager.d.ts.map +1 -1
  114. package/dist/src/helpers/arweaveContentTags.d.ts +33 -0
  115. package/dist/src/helpers/arweaveContentTags.d.ts.map +1 -0
  116. package/dist/src/helpers/cachedPropertyRefresh.d.ts +12 -0
  117. package/dist/src/helpers/cachedPropertyRefresh.d.ts.map +1 -0
  118. package/dist/src/helpers/compositeUpload.d.ts +28 -0
  119. package/dist/src/helpers/compositeUpload.d.ts.map +1 -0
  120. package/dist/src/helpers/db.d.ts +3 -0
  121. package/dist/src/helpers/db.d.ts.map +1 -1
  122. package/dist/src/helpers/easSdk.d.ts +16 -0
  123. package/dist/src/helpers/easSdk.d.ts.map +1 -0
  124. package/dist/src/helpers/entity/detachRowsBeforeDelete.d.ts +16 -0
  125. package/dist/src/helpers/entity/detachRowsBeforeDelete.d.ts.map +1 -0
  126. package/dist/src/helpers/entity/entityDestroy.d.ts +2 -0
  127. package/dist/src/helpers/entity/entityDestroy.d.ts.map +1 -1
  128. package/dist/src/helpers/itemStorageFile.d.ts +57 -0
  129. package/dist/src/helpers/itemStorageFile.d.ts.map +1 -0
  130. package/dist/src/helpers/mapWithConcurrency.d.ts +7 -0
  131. package/dist/src/helpers/mapWithConcurrency.d.ts.map +1 -0
  132. package/dist/src/helpers/mimeTypes.d.ts +43 -0
  133. package/dist/src/helpers/mimeTypes.d.ts.map +1 -0
  134. package/dist/src/helpers/ownership.d.ts +28 -4
  135. package/dist/src/helpers/ownership.d.ts.map +1 -1
  136. package/dist/src/helpers/property/index.d.ts +37 -51
  137. package/dist/src/helpers/property/index.d.ts.map +1 -1
  138. package/dist/src/helpers/publishConfig.d.ts +27 -8
  139. package/dist/src/helpers/publishConfig.d.ts.map +1 -1
  140. package/dist/src/helpers/storageDir.d.ts +16 -0
  141. package/dist/src/helpers/storageDir.d.ts.map +1 -0
  142. package/dist/src/helpers/tabCoordinator.d.ts +5 -1
  143. package/dist/src/helpers/tabCoordinator.d.ts.map +1 -1
  144. package/dist/src/helpers/tabEvents.d.ts +23 -2
  145. package/dist/src/helpers/tabEvents.d.ts.map +1 -1
  146. package/dist/src/helpers/updateSchema.d.ts +5 -0
  147. package/dist/src/helpers/updateSchema.d.ts.map +1 -1
  148. package/dist/src/helpers/waitForEntityIdle.d.ts +5 -0
  149. package/dist/src/helpers/waitForEntityIdle.d.ts.map +1 -1
  150. package/dist/src/imports/json.d.ts +9 -0
  151. package/dist/src/imports/json.d.ts.map +1 -1
  152. package/dist/src/index.d.ts +11 -7
  153. package/dist/src/index.d.ts.map +1 -1
  154. package/dist/src/interfaces/IItem.d.ts +7 -1
  155. package/dist/src/interfaces/IItem.d.ts.map +1 -1
  156. package/dist/src/node/db/Db.d.ts.map +1 -1
  157. package/dist/src/node/helpers/PathResolver.d.ts.map +1 -1
  158. package/dist/src/node/index.d.ts +8 -1
  159. package/dist/src/node/index.d.ts.map +1 -1
  160. package/dist/src/platform/index.browser.d.ts +2 -0
  161. package/dist/src/platform/index.browser.d.ts.map +1 -1
  162. package/dist/src/platform/index.node.d.ts +2 -0
  163. package/dist/src/platform/index.node.d.ts.map +1 -1
  164. package/dist/src/types/fileManager.d.ts +3 -14
  165. package/dist/src/types/fileManager.d.ts.map +1 -1
  166. package/dist/src/types/index.d.ts +12 -1
  167. package/dist/src/types/index.d.ts.map +1 -1
  168. package/dist/src/types/machines.d.ts +2 -0
  169. package/dist/src/types/machines.d.ts.map +1 -1
  170. package/dist/src/types/property.d.ts +8 -0
  171. package/dist/src/types/property.d.ts.map +1 -1
  172. package/dist/src/types/publish.d.ts +14 -0
  173. package/dist/src/types/publish.d.ts.map +1 -1
  174. package/dist/{syncDbWithEas-BU-jZ5bJ.js → syncDbWithEas-Bv2Fe38J.js} +17 -17
  175. package/dist/{syncDbWithEas-BU-jZ5bJ.js.map → syncDbWithEas-Bv2Fe38J.js.map} +1 -1
  176. package/dist/tabEvents-9s2WCYw-.js +335 -0
  177. package/dist/tabEvents-9s2WCYw-.js.map +1 -0
  178. package/dist/tolerantWebAccess-iUu80pAP.js +551 -0
  179. package/dist/tolerantWebAccess-iUu80pAP.js.map +1 -0
  180. package/dist/{updateSeedRevokedAt-iLpzae1i.js → updateSeedRevokedAt-zBfi931j.js} +3 -3
  181. package/dist/{updateSeedRevokedAt-iLpzae1i.js.map → updateSeedRevokedAt-zBfi931j.js.map} +1 -1
  182. package/package.json +11 -12
  183. package/src/node/easLodashRegister.js +4 -0
  184. package/dist/BasePathResolver-BdxCSIzn.js +0 -679
  185. package/dist/BasePathResolver-BdxCSIzn.js.map +0 -1
  186. package/dist/ClientManager-DDA9956Y.js.map +0 -1
  187. package/dist/Item-D4FigtYS.js.map +0 -1
  188. package/dist/ModelProperty-BDt6AU2h.js.map +0 -1
  189. package/dist/Schema-B8xqLWkL.js.map +0 -1
  190. package/dist/cjs/ModelProperty-B-cZm1yU.js +0 -1977
  191. package/dist/cjs/ModelProperty-B-cZm1yU.js.map +0 -1
  192. package/dist/cjs/Schema-STP972Xw.js +0 -5256
  193. package/dist/cjs/Schema-STP972Xw.js.map +0 -1
  194. package/dist/cjs/SchemaValidationService-CKNW1bKg.js +0 -778
  195. package/dist/cjs/SchemaValidationService-CKNW1bKg.js.map +0 -1
  196. package/dist/cjs/backfillMetadataPropertyIds-CP3y1skt.js +0 -89
  197. package/dist/cjs/backfillMetadataPropertyIds-CP3y1skt.js.map +0 -1
  198. package/dist/cjs/eas-CAnUC4wd.js +0 -138
  199. package/dist/cjs/eas-CAnUC4wd.js.map +0 -1
  200. package/dist/cjs/getItem-CWgb3e9G.js +0 -58
  201. package/dist/cjs/getItem-CWgb3e9G.js.map +0 -1
  202. package/dist/cjs/getPublishPayload-BsZWiJ03.js +0 -1603
  203. package/dist/cjs/getPublishPayload-BsZWiJ03.js.map +0 -1
  204. package/dist/cjs/getPublishUploads-BQr8aMVP.js +0 -495
  205. package/dist/cjs/getPublishUploads-BQr8aMVP.js.map +0 -1
  206. package/dist/cjs/index-nA5PxBSs.js +0 -70
  207. package/dist/cjs/index-nA5PxBSs.js.map +0 -1
  208. package/dist/cjs/index-usKaANAq.js +0 -22171
  209. package/dist/cjs/index-usKaANAq.js.map +0 -1
  210. package/dist/cjs/index.browser-BSf8HpnU.js +0 -22
  211. package/dist/cjs/index.browser-BSf8HpnU.js.map +0 -1
  212. package/dist/cjs/property-xMwPhQ5N.js +0 -327
  213. package/dist/cjs/property-xMwPhQ5N.js.map +0 -1
  214. package/dist/cjs/publishDraftGraph-BRWlR1KO.js +0 -403
  215. package/dist/cjs/publishDraftGraph-BRWlR1KO.js.map +0 -1
  216. package/dist/cjs/resetAmbiguousLegacyItemData-8nfkj9rz.js +0 -116
  217. package/dist/cjs/resetAmbiguousLegacyItemData-8nfkj9rz.js.map +0 -1
  218. package/dist/cjs/resolveModelForSyncedSeed-kYRuDWYw.js +0 -49
  219. package/dist/cjs/resolveModelForSyncedSeed-kYRuDWYw.js.map +0 -1
  220. package/dist/cjs/syncDbWithEas-DqRhV8o2.js +0 -886
  221. package/dist/cjs/syncDbWithEas-DqRhV8o2.js.map +0 -1
  222. package/dist/db-CQt-gcAl.js.map +0 -1
  223. package/dist/eas-CpOD74Ke.js.map +0 -1
  224. package/dist/getPublishPayload-Xl3sRkR-.js.map +0 -1
  225. package/dist/getPublishUploads-DHP01KgU.js +0 -484
  226. package/dist/getPublishUploads-DHP01KgU.js.map +0 -1
  227. package/dist/index-BGt4_oPO.js +0 -31
  228. package/dist/index-BGt4_oPO.js.map +0 -1
  229. package/dist/index-CSOQFAOn.js.map +0 -1
  230. package/dist/index-Xl1_4Lmb.js.map +0 -1
  231. package/dist/index.browser-CjTe0vt1.js.map +0 -1
  232. package/dist/index.node-Cfa7npS6.js.map +0 -1
  233. package/dist/main.cjs +0 -84
  234. package/dist/main.cjs.map +0 -1
  235. package/dist/property-BrXkY1Rg.js.map +0 -1
  236. package/dist/tabEvents-BZJMY5uK.js +0 -1344
  237. package/dist/tabEvents-BZJMY5uK.js.map +0 -1
  238. package/dist/tolerantWebAccess-BZ2RA_mb.js +0 -160
  239. package/dist/tolerantWebAccess-BZ2RA_mb.js.map +0 -1
@@ -0,0 +1,648 @@
1
+ import { N as resolveSeedIdsFromRefString, O as normalizeRelationPropertyValue, Q as isPublishedSeedRef, i as isDataType, M as ModelPropertyDataTypes, R as getStorageDirForDataType, J as BaseFileManager, E as BaseDb, o as htmlEmbeddedImageCoPublish, S as getContentSha256, U as buildArweaveContentTags, V as getItemStorageSubdir, W as getItemStorageLocalFileName, m as metadata } from './BasePathResolver-Cm4apKRb.js';
2
+ import { BaseArweaveClient } from '@seedprotocol/arweave';
3
+ import { g as getPublishDraftGraph, a as getSegmentedItemProperties } from './publishDraftGraph-BOn3_Occ.js';
4
+ import debug from 'debug';
5
+ import { I as Item, c as compareMetadataRowsLatestFirst } from './Item-DBFchXpC.js';
6
+ import { eq, and } from 'drizzle-orm';
7
+ import 'pluralize';
8
+ import { r as resolveUploadMimeType } from './mimeTypes-DHAHC4eZ.js';
9
+ import { i as isVerbatimItemStorageDraftRow, c as convertVerbatimItemStorageRow } from './ClientManager-i3nJASkg.js';
10
+ import '@seedprotocol/eas';
11
+ import 'xstate';
12
+ import '@sinclair/typebox';
13
+ import 'drizzle-orm/sqlite-core';
14
+ import 'drizzle-orm/casing';
15
+ import 'lodash-es';
16
+ import 'nanoid';
17
+ import 'nanoid-dictionary';
18
+ import '@seedprotocol/query';
19
+ import '@noble/hashes/sha256';
20
+ import '@noble/hashes/sha3';
21
+ import '@noble/hashes/utils';
22
+ import './index-8O3Uow-Y.js';
23
+ import './model-DGMe-TTm.js';
24
+ import './property-DwPD283A.js';
25
+ import 'rxjs';
26
+ import './tabEvents-9s2WCYw-.js';
27
+
28
+ /**
29
+ * `Promise.all(items.map(fn))` with at most `limit` calls in flight. Results keep the input order.
30
+ * Rejects with the first error (by time); after that no new calls start, though calls already in
31
+ * flight run to completion.
32
+ */
33
+ async function mapWithConcurrency(items, limit, fn) {
34
+ const results = new Array(items.length);
35
+ const workerCount = Math.max(1, Math.min(Math.floor(limit) || 1, items.length));
36
+ let next = 0;
37
+ let failed = false;
38
+ const worker = async () => {
39
+ while (!failed && next < items.length) {
40
+ const index = next++;
41
+ try {
42
+ results[index] = await fn(items[index], index);
43
+ }
44
+ catch (error) {
45
+ failed = true;
46
+ throw error;
47
+ }
48
+ }
49
+ };
50
+ await Promise.all(Array.from({ length: workerCount }, worker));
51
+ return results;
52
+ }
53
+
54
+ /**
55
+ * Composite uploads: several ItemStorage files of one item in a single Arweave transaction.
56
+ *
57
+ * Producer: `getPublishUploads.ts` (`processUploadPropertyData`), for an item with a
58
+ * `storageTransactionId` property and ItemStorage properties (e.g. a Post's `html` and `json`).
59
+ * Consumer: the download worker (`browser/workers/filesDownload.ts`), which keeps its own copy of
60
+ * {@link decodeCompositeUpload} because it runs from a string; a test keeps the two in step.
61
+ *
62
+ * Format (unchanged for text children, so composites already on Arweave still read):
63
+ *
64
+ * ===FILE_SEPARATOR===<name>===FILE_SEPARATOR===<utf-8 text> (repeated per child)
65
+ *
66
+ * A child that is not valid UTF-8 text (or whose text contains the separator) is written as
67
+ * base64 under the name `<name>;base64`. Composites written before this suffix existed converted
68
+ * every child to text, which corrupted binary children; those bytes cannot be recovered.
69
+ */
70
+ const COMPOSITE_SEPARATOR = '===FILE_SEPARATOR===';
71
+ const COMPOSITE_BASE64_SUFFIX = ';base64';
72
+ const bytesToBase64 = (bytes) => {
73
+ let binary = '';
74
+ const chunk = 0x8000;
75
+ for (let i = 0; i < bytes.length; i += chunk) {
76
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
77
+ }
78
+ return btoa(binary);
79
+ };
80
+ /** The child's text when it can travel as text: valid UTF-8, no NUL bytes, no separator. */
81
+ const childAsText = (bytes) => {
82
+ if (bytes.includes(0))
83
+ return undefined;
84
+ let text;
85
+ try {
86
+ text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
87
+ }
88
+ catch {
89
+ return undefined;
90
+ }
91
+ return text.includes(COMPOSITE_SEPARATOR) ? undefined : text;
92
+ };
93
+ const encodeCompositeUpload = (children) => {
94
+ let composite = '';
95
+ for (const { name, bytes } of children) {
96
+ const text = childAsText(bytes);
97
+ composite +=
98
+ text !== undefined
99
+ ? `${COMPOSITE_SEPARATOR}${name}${COMPOSITE_SEPARATOR}${text}`
100
+ : `${COMPOSITE_SEPARATOR}${name}${COMPOSITE_BASE64_SUFFIX}${COMPOSITE_SEPARATOR}${bytesToBase64(bytes)}`;
101
+ }
102
+ return new TextEncoder().encode(composite);
103
+ };
104
+ new TextEncoder().encode(COMPOSITE_SEPARATOR);
105
+
106
+ const logger = debug('seedSdk:item:getPublishUploads');
107
+ /** L1 transactions {@link getPublishUploads} creates at once (each asks the gateway for price and anchor). */
108
+ const CREATE_TRANSACTION_CONCURRENCY = 4;
109
+ const toUint8Array = async (data) => {
110
+ if (typeof Blob !== 'undefined' && data instanceof Blob) {
111
+ return new Uint8Array(await data.arrayBuffer());
112
+ }
113
+ return new Uint8Array(data);
114
+ };
115
+ /** A local file's bytes plus its MIME type: the Blob's own type, else the name's extension, else a sniff of the bytes. */
116
+ const readUploadFile = async (filePath, fileName = filePath) => {
117
+ const data = await BaseFileManager.readFileAsBuffer(filePath);
118
+ const bytes = await toUint8Array(data);
119
+ const sourceType = typeof Blob !== 'undefined' && data instanceof Blob ? data.type : undefined;
120
+ return { bytes, contentType: resolveUploadMimeType({ sourceType, fileName, bytes }) };
121
+ };
122
+ /**
123
+ * The one place an upload's bytes become a {@link PublishUploadData}: everything after this
124
+ * (Content-SHA-256, tags, the L1 transaction or the bundler DataItem, signing) works from what it
125
+ * returns. A future private-publish option that encrypts content belongs here, before the hash and
126
+ * tags are computed, so both publish paths pick it up.
127
+ */
128
+ const buildPublishUploadData = (data, contentType, target, options) => {
129
+ const contentHash = getContentSha256(data);
130
+ return {
131
+ data,
132
+ contentHash,
133
+ contentType,
134
+ tags: buildArweaveContentTags(contentHash, contentType, options?.arweaveUploadTags),
135
+ ...target,
136
+ };
137
+ };
138
+ const DATA_URI_IMAGE = /^data:(image\/[a-zA-Z0-9.+-]+);base64,([\s\S]*)$/i;
139
+ function decodeDataUriImage(dataUri) {
140
+ const m = DATA_URI_IMAGE.exec((dataUri ?? '').trim());
141
+ if (!m)
142
+ return null;
143
+ try {
144
+ const mimeType = m[1].toLowerCase().trim();
145
+ const base64 = m[2].replace(/\s/g, '');
146
+ const binary = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
147
+ return { mimeType, bytes: binary };
148
+ }
149
+ catch {
150
+ return null;
151
+ }
152
+ }
153
+ const getStorageSeedUploadData = async (itemStorageSeedProperties, options) => {
154
+ const uploads = [];
155
+ for (const itemProperty of itemStorageSeedProperties) {
156
+ const snapshot = itemProperty.getService().getSnapshot();
157
+ const context = 'context' in snapshot ? snapshot.context : null;
158
+ if (!context) {
159
+ continue;
160
+ }
161
+ const propertyValue = context.propertyValue;
162
+ const refResolvedValue = context.refResolvedValue;
163
+ if (!refResolvedValue) {
164
+ continue;
165
+ }
166
+ // propertyValue is the storage seed's seedLocalId; use it for the upload so processRelationOrImageProperty can match
167
+ const { seedLocalId } = resolveSeedIdsFromRefString(normalizeRelationPropertyValue(propertyValue) ?? '');
168
+ if (!seedLocalId) {
169
+ continue;
170
+ }
171
+ const dataType = itemProperty.propertyDef?.refValueType ??
172
+ itemProperty.propertyDef?.dataType ??
173
+ 'Image';
174
+ if (isDataType(dataType, ModelPropertyDataTypes.Html)) {
175
+ if (options?.deferHtmlStorageSeedLocalIds?.includes(seedLocalId)) {
176
+ continue;
177
+ }
178
+ if (options?.onlyHtmlStorageSeedLocalIds?.length &&
179
+ !options.onlyHtmlStorageSeedLocalIds.includes(seedLocalId)) {
180
+ continue;
181
+ }
182
+ }
183
+ else if (options?.onlyHtmlStorageSeedLocalIds?.length) {
184
+ continue;
185
+ }
186
+ const baseDir = getStorageDirForDataType(dataType);
187
+ const filePath = `${baseDir}/${refResolvedValue}`;
188
+ const exists = await BaseFileManager.pathExists(filePath);
189
+ if (!exists) {
190
+ continue;
191
+ }
192
+ const { bytes: fileContents, contentType } = await readUploadFile(filePath, refResolvedValue);
193
+ uploads.push(buildPublishUploadData(fileContents, contentType, {
194
+ itemPropertyName: itemProperty.propertyName,
195
+ itemPropertyLocalId: itemProperty.localId,
196
+ seedLocalId,
197
+ versionLocalId: itemProperty.versionLocalId,
198
+ }, options));
199
+ }
200
+ return uploads;
201
+ };
202
+ async function appendCoPublishedImageUploadData(item, uploads, options) {
203
+ const appDb = BaseDb.getAppDb();
204
+ if (!appDb || options?.onlyHtmlStorageSeedLocalIds?.length)
205
+ return uploads;
206
+ const rows = await appDb
207
+ .select()
208
+ .from(htmlEmbeddedImageCoPublish)
209
+ .where(eq(htmlEmbeddedImageCoPublish.parentSeedLocalId, item.seedLocalId));
210
+ const seen = new Set(uploads.map((u) => u.seedLocalId));
211
+ for (const row of rows) {
212
+ if (seen.has(row.imageSeedLocalId))
213
+ continue;
214
+ const imageItem = await Item.find({ seedLocalId: row.imageSeedLocalId, modelName: 'Image' });
215
+ if (!imageItem)
216
+ continue;
217
+ const st = imageItem.internalProperties['storageTransactionId'] ??
218
+ imageItem.allProperties['storageTransactionId'];
219
+ const stSnap = st?.getService().getSnapshot();
220
+ const stCtx = stSnap && 'context' in stSnap ? stSnap.context : undefined;
221
+ const stValue = typeof stCtx?.propertyValue === 'string'
222
+ ? (stCtx.propertyValue ?? '')
223
+ : '';
224
+ const decoded = decodeDataUriImage(stValue);
225
+ const more = [];
226
+ if (decoded && st && st.localId && st.versionLocalId) {
227
+ more.push(buildPublishUploadData(decoded.bytes, decoded.mimeType, {
228
+ itemPropertyName: st.propertyName,
229
+ itemPropertyLocalId: st.localId,
230
+ seedLocalId: imageItem.seedLocalId,
231
+ versionLocalId: st.versionLocalId,
232
+ }, options));
233
+ }
234
+ for (const u of more) {
235
+ if (!seen.has(u.seedLocalId)) {
236
+ uploads.push(u);
237
+ seen.add(u.seedLocalId);
238
+ }
239
+ }
240
+ }
241
+ return uploads;
242
+ }
243
+ const isUsablePath = (filePath) => !!filePath && !filePath.endsWith('undefined') && !filePath.endsWith('null');
244
+ /** The newest metadata row of an ItemStorage property, read from the DB (not the live query). */
245
+ const getLatestItemStorageRow = async (childProperty) => {
246
+ const appDb = BaseDb.getAppDb();
247
+ const seedLocalId = childProperty.seedLocalId;
248
+ const propertyName = childProperty.storagePropertyName || childProperty.propertyName;
249
+ if (!appDb || !seedLocalId || !propertyName)
250
+ return undefined;
251
+ const where = [eq(metadata.seedLocalId, seedLocalId), eq(metadata.propertyName, propertyName)];
252
+ if (childProperty.versionLocalId)
253
+ where.push(eq(metadata.versionLocalId, childProperty.versionLocalId));
254
+ const rows = await appDb.select().from(metadata).where(and(...where));
255
+ return [...rows].sort(compareMetadataRowsLatestFirst)[0];
256
+ };
257
+ /**
258
+ * Write a legacy ItemStorage draft row's verbatim content to `<seedUid or seedLocalId><extension>`
259
+ * and record it on the row (refResolvedValue, localStorageDir) and in the property context. The
260
+ * row's propertyValue is cleared once the file is written, so the row has the same shape as one a
261
+ * save makes and a later edit of the file never leaves stale text behind it.
262
+ */
263
+ const migrateVerbatimItemStorageRow = async (childProperty, row) => {
264
+ const seedId = row.seedUid || childProperty.seedUid || row.seedLocalId || childProperty.seedLocalId;
265
+ if (!seedId || !row.localId)
266
+ return undefined;
267
+ const propertyDef = childProperty.propertyDef;
268
+ const converted = await convertVerbatimItemStorageRow(row.localId, {
269
+ seedId,
270
+ localStorageDir: propertyDef?.localStorageDir || row.localStorageDir,
271
+ filenameSuffix: propertyDef?.filenameSuffix,
272
+ });
273
+ if (!converted)
274
+ return undefined;
275
+ const { fileName, filePath, localStorageDir, content } = converted;
276
+ // The content is still the value: keep it as renderValue (the property may show it from propertyValue).
277
+ childProperty.getService().send({
278
+ type: 'updateContext',
279
+ refResolvedValue: fileName,
280
+ localStorageDir,
281
+ renderValue: content,
282
+ });
283
+ logger(`resolveItemStorageChildFile: wrote verbatim ${childProperty.propertyName} content to ${filePath}`);
284
+ return filePath;
285
+ };
286
+ /**
287
+ * Local file of one ItemStorage child of a composite upload. Tries, in order: the property's
288
+ * localStoragePath (context set by save / hydration / the live query), its newest metadata row's
289
+ * refResolvedValue + localStorageDir, then (for a local draft whose propertyValue is the content
290
+ * itself, as rows made before Item.create saved ItemStorage values) that content written to its
291
+ * file, then (for a local draft, or no row) the name
292
+ * saveItemStorage gives a new file (`<seedUid or seedLocalId><extension>` in the model's storage
293
+ * directory). A published or derived row is never swapped for a local file of another name: that
294
+ * file would be older content.
295
+ *
296
+ * `missingLocalEdit` lists the paths tried when nothing exists although the newest row is a saved
297
+ * local edit (no attestation uid, not derived from one, refResolvedValue set by saveItemStorage):
298
+ * that edit's file should be there. A published or derived row without a file (e.g. content not
299
+ * downloaded, or a property the composite never had) is skipped as before.
300
+ */
301
+ const resolveItemStorageChildFile = async (childProperty) => {
302
+ const tried = [];
303
+ const tryPath = async (filePath) => {
304
+ if (!isUsablePath(filePath) || tried.includes(filePath))
305
+ return undefined;
306
+ tried.push(filePath);
307
+ return (await BaseFileManager.pathExists(filePath)) ? filePath : undefined;
308
+ };
309
+ const fromContext = await tryPath(childProperty.localStoragePath);
310
+ if (fromContext)
311
+ return { filePath: fromContext };
312
+ const row = await getLatestItemStorageRow(childProperty).catch((error) => {
313
+ logger('resolveItemStorageChildFile: metadata lookup failed', error);
314
+ return undefined;
315
+ });
316
+ const propertyDef = childProperty.propertyDef;
317
+ const dir = getItemStorageSubdir(propertyDef?.localStorageDir || row?.localStorageDir);
318
+ if (row?.refResolvedValue) {
319
+ const fromRow = await tryPath(BaseFileManager.getFilesPath(dir, row.refResolvedValue));
320
+ if (fromRow)
321
+ return { filePath: fromRow };
322
+ }
323
+ const isLocalDraft = !!row && !row.uid && row.derivedFromUid == null;
324
+ // A local draft holding the content itself (no file reference): what Item.create / createNewItem
325
+ // stored for ItemStorage values before they went through the save pipeline. Write it to the file a
326
+ // save would have, point the row and the property at it, and upload that.
327
+ if (row && isVerbatimItemStorageDraftRow(row)) {
328
+ const migrated = await migrateVerbatimItemStorageRow(childProperty, row).catch((error) => {
329
+ logger('resolveItemStorageChildFile: writing verbatim ItemStorage content failed', error);
330
+ return undefined;
331
+ });
332
+ if (migrated)
333
+ return { filePath: migrated };
334
+ }
335
+ const suffix = propertyDef?.filenameSuffix;
336
+ const seedIds = !row || isLocalDraft
337
+ ? [row?.seedUid, childProperty.seedUid, row?.seedLocalId, childProperty.seedLocalId]
338
+ : [];
339
+ for (const seedId of seedIds) {
340
+ if (!seedId)
341
+ continue;
342
+ const derived = await tryPath(BaseFileManager.getFilesPath(dir, getItemStorageLocalFileName(seedId, suffix)));
343
+ if (derived)
344
+ return { filePath: derived };
345
+ }
346
+ // saveItemStorage sets refResolvedValue on the draft row once the file is written. A draft row
347
+ // without one is the empty row createNewItem makes for every model property: nothing to upload.
348
+ return isLocalDraft && !!row?.refResolvedValue ? { missingLocalEdit: tried } : {};
349
+ };
350
+ /**
351
+ * True if publish would include at least one Arweave upload (local file / storage seed present).
352
+ * Does not create Arweave transactions or hit the network — use for routing (e.g. skip EAS-only)
353
+ * when {@link getPublishUploads} would fail early (e.g. gateway unreachable during tx creation).
354
+ */
355
+ async function storageSeedHasUploadCandidates(itemStorageSeedProperties) {
356
+ for (const itemProperty of itemStorageSeedProperties) {
357
+ const snapshot = itemProperty.getService().getSnapshot();
358
+ const context = 'context' in snapshot ? snapshot.context : null;
359
+ if (!context) {
360
+ continue;
361
+ }
362
+ const propertyValue = context.propertyValue;
363
+ const refResolvedValue = context.refResolvedValue;
364
+ if (!refResolvedValue) {
365
+ continue;
366
+ }
367
+ const { seedLocalId } = resolveSeedIdsFromRefString(normalizeRelationPropertyValue(propertyValue) ?? '');
368
+ if (!seedLocalId) {
369
+ continue;
370
+ }
371
+ const dataType = itemProperty.propertyDef?.refValueType ??
372
+ itemProperty.propertyDef?.dataType ??
373
+ 'Image';
374
+ const baseDir = getStorageDirForDataType(dataType);
375
+ const filePath = `${baseDir}/${refResolvedValue}`;
376
+ if (await BaseFileManager.pathExists(filePath)) {
377
+ return true;
378
+ }
379
+ }
380
+ return false;
381
+ }
382
+ async function uploadPropertyWouldUpload(uploadProperty, relatedItemProperty) {
383
+ for (const childProperty of uploadProperty.childProperties) {
384
+ // Not strict: a local edit whose file is missing still means "would upload", so the publish
385
+ // goes ahead and fails loudly in processUploadPropertyData instead of skipping the upload.
386
+ const resolved = await resolveItemStorageChildFile(childProperty);
387
+ if (resolved.filePath || resolved.missingLocalEdit) {
388
+ return true;
389
+ }
390
+ }
391
+ if (relatedItemProperty && relatedItemProperty.localStoragePath) {
392
+ const filePath = relatedItemProperty.localStoragePath;
393
+ if (!filePath || filePath.endsWith('undefined')) {
394
+ return false;
395
+ }
396
+ return await BaseFileManager.pathExists(filePath);
397
+ }
398
+ return false;
399
+ }
400
+ async function itemOwnUploadCandidates(item, relatedItemProperty, recurseStorageRelations) {
401
+ const { itemUploadProperties, itemRelationProperties, itemImageProperties } = await getSegmentedItemProperties(item);
402
+ for (const uploadProperty of itemUploadProperties) {
403
+ if (await uploadPropertyWouldUpload(uploadProperty, relatedItemProperty)) {
404
+ return true;
405
+ }
406
+ }
407
+ if (await storageSeedHasUploadCandidates(itemImageProperties)) {
408
+ return true;
409
+ }
410
+ if (!recurseStorageRelations)
411
+ return false;
412
+ const storageProperties = new Set(itemImageProperties);
413
+ for (const relationProperty of itemRelationProperties) {
414
+ if (!storageProperties.has(relationProperty))
415
+ continue;
416
+ const snapshot = relationProperty.getService().getSnapshot();
417
+ const context = 'context' in snapshot ? snapshot.context : null;
418
+ if (!context) {
419
+ continue;
420
+ }
421
+ const propertyValue = context.propertyValue;
422
+ if (!propertyValue || relationProperty.uid) {
423
+ continue;
424
+ }
425
+ const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(normalizeRelationPropertyValue(propertyValue) ?? '');
426
+ if (!seedLocalId && !seedUid) {
427
+ throw new Error(`Invalid relation value for ${relationProperty.propertyName}: expected local seed id or 0x uid`);
428
+ }
429
+ const relatedItem = await Item.find({
430
+ seedLocalId,
431
+ seedUid,
432
+ });
433
+ if (!relatedItem) {
434
+ // Related seed referenced by attested uid with no local copy: already published, nothing to upload.
435
+ if (isPublishedSeedRef(propertyValue))
436
+ continue;
437
+ throw new Error(`No relatedItem found for ${relationProperty.propertyName}`);
438
+ }
439
+ if (await itemOwnUploadCandidates(relatedItem, relationProperty, false)) {
440
+ return true;
441
+ }
442
+ }
443
+ return false;
444
+ }
445
+ /** Same walk as getPublishUploads: the item and the draft items its publish carries along. */
446
+ async function itemHasPublishUploadCandidates(item, relatedItemProperty) {
447
+ if (await itemOwnUploadCandidates(item, relatedItemProperty, true))
448
+ return true;
449
+ const { drafts } = await getPublishDraftGraph(item, { strict: true });
450
+ for (const { item: draft, via, viaList } of drafts) {
451
+ if (await itemOwnUploadCandidates(draft, viaList ? undefined : via, true))
452
+ return true;
453
+ }
454
+ return false;
455
+ }
456
+ const processUploadPropertyData = async (uploadProperty, uploads, relatedItemProperty, options) => {
457
+ const itemProperty = uploadProperty.itemProperty;
458
+ const childUploads = [];
459
+ for (const childProperty of uploadProperty.childProperties) {
460
+ const { filePath, missingLocalEdit } = await resolveItemStorageChildFile(childProperty);
461
+ if (!filePath) {
462
+ if (missingLocalEdit) {
463
+ // Uploading without it would publish a composite that silently lacks this edit.
464
+ throw new Error(`Cannot publish ${itemProperty.seedLocalId}: the local file for ${childProperty.propertyName} ` +
465
+ `was not found (looked in ${missingLocalEdit.join(', ')})`);
466
+ }
467
+ continue;
468
+ }
469
+ childUploads.push({
470
+ propertyName: childProperty.propertyName,
471
+ localStoragePath: filePath,
472
+ });
473
+ }
474
+ let fileContents;
475
+ let fileContentType;
476
+ if (!childUploads || childUploads.length === 0) {
477
+ if (relatedItemProperty && relatedItemProperty.localStoragePath) {
478
+ const filePath = relatedItemProperty.localStoragePath;
479
+ if (!filePath || filePath.endsWith('undefined')) {
480
+ return uploads;
481
+ }
482
+ const exists = await BaseFileManager.pathExists(filePath);
483
+ if (!exists) {
484
+ return uploads;
485
+ }
486
+ try {
487
+ const read = await readUploadFile(filePath);
488
+ fileContents = read.bytes;
489
+ fileContentType = read.contentType;
490
+ }
491
+ catch (e) {
492
+ const fs = await BaseFileManager.getFs();
493
+ fileContents = await toUint8Array(fs.readFileSync(filePath));
494
+ fileContentType = resolveUploadMimeType({ fileName: filePath, bytes: fileContents });
495
+ }
496
+ }
497
+ if (!fileContents) {
498
+ return uploads;
499
+ }
500
+ }
501
+ if (childUploads.length > 0) {
502
+ // Composite of the item's ItemStorage files; see helpers/compositeUpload.ts for the format.
503
+ // Children are read as bytes: a binary child is base64-framed instead of decoded as text.
504
+ const children = [];
505
+ const fs = await BaseFileManager.getFs();
506
+ for (const childUpload of childUploads) {
507
+ let childUploadContents;
508
+ try {
509
+ childUploadContents = await fs.promises.readFile(childUpload.localStoragePath);
510
+ }
511
+ catch (e) {
512
+ childUploadContents = fs.readFileSync(childUpload.localStoragePath);
513
+ }
514
+ children.push({
515
+ name: childUpload.propertyName,
516
+ bytes: typeof childUploadContents === 'string'
517
+ ? new TextEncoder().encode(childUploadContents)
518
+ : new Uint8Array(childUploadContents),
519
+ });
520
+ }
521
+ fileContents = encodeCompositeUpload(children);
522
+ }
523
+ if (!fileContents) {
524
+ throw new Error(`No file contents found for ${itemProperty.propertyName}`);
525
+ }
526
+ const uint8Array = new Uint8Array(fileContents);
527
+ let contentType;
528
+ if (childUploads.length === 0 && relatedItemProperty?.localStoragePath) {
529
+ contentType = fileContentType;
530
+ }
531
+ else if (childUploads.length > 0) {
532
+ contentType = 'application/octet-stream';
533
+ }
534
+ let itemPropertyLocalId = relatedItemProperty
535
+ ? relatedItemProperty.localId
536
+ : itemProperty.localId;
537
+ let itemPropertyName = relatedItemProperty
538
+ ? relatedItemProperty.propertyName
539
+ : itemProperty.propertyName;
540
+ uploads.push(buildPublishUploadData(uint8Array, contentType, {
541
+ itemPropertyName,
542
+ itemPropertyLocalId,
543
+ seedLocalId: itemProperty.seedLocalId,
544
+ versionLocalId: itemProperty.versionLocalId,
545
+ }, options));
546
+ return uploads;
547
+ };
548
+ /** No seed uid yet: a related item in this state is published together with the item. */
549
+ const isDraftItem = (item) => !item.seedUid || item.seedUid === '0x' + '0'.repeat(64);
550
+ /** One item's own uploads: its files, storage seeds, Html-embedded images, and the items its storage relations point at. */
551
+ const getItemOwnPublishUploadData = async (item, uploads, relatedItemProperty, options) => {
552
+ const { itemUploadProperties, itemRelationProperties, itemImageProperties } = await getSegmentedItemProperties(item);
553
+ // Phase 2 of an embedded-image publish: only the deferred Html storage seeds, of this item and of
554
+ // the related items published with it (whose Html can embed images too).
555
+ const onlyDeferredHtml = !!options?.onlyHtmlStorageSeedLocalIds?.length;
556
+ if (onlyDeferredHtml) {
557
+ const storageSeedUploads = await getStorageSeedUploadData(itemImageProperties, options);
558
+ uploads.push(...storageSeedUploads);
559
+ }
560
+ else {
561
+ for (const uploadProperty of itemUploadProperties) {
562
+ uploads = await processUploadPropertyData(uploadProperty, uploads, relatedItemProperty, options);
563
+ }
564
+ const storageSeedUploads = await getStorageSeedUploadData(itemImageProperties, options);
565
+ uploads.push(...storageSeedUploads);
566
+ // Images embedded in this item's Html: the published item's, and a related draft's published with it.
567
+ if (!relatedItemProperty || isDraftItem(item)) {
568
+ uploads = await appendCoPublishedImageUploadData(item, uploads, options);
569
+ }
570
+ }
571
+ if (options?.skipRelationRecursion) {
572
+ return uploads;
573
+ }
574
+ // Relations to Image/File/Html/Json items: their file, read through the relation property.
575
+ const storageProperties = new Set(itemImageProperties);
576
+ for (const relationProperty of itemRelationProperties) {
577
+ if (!storageProperties.has(relationProperty))
578
+ continue;
579
+ const snapshot = relationProperty.getService().getSnapshot();
580
+ const context = 'context' in snapshot ? snapshot.context : null;
581
+ if (!context) {
582
+ continue;
583
+ }
584
+ const propertyValue = context.propertyValue;
585
+ if (!propertyValue || relationProperty.uid) {
586
+ continue;
587
+ }
588
+ const { seedLocalId, seedUid } = resolveSeedIdsFromRefString(normalizeRelationPropertyValue(propertyValue) ?? '');
589
+ if (!seedLocalId && !seedUid) {
590
+ throw new Error(`Invalid relation value for ${relationProperty.propertyName}: expected local seed id or 0x uid`);
591
+ }
592
+ const relatedItem = await Item.find({
593
+ seedLocalId,
594
+ seedUid,
595
+ });
596
+ if (!relatedItem) {
597
+ // Related seed referenced by attested uid with no local copy: already published, nothing to upload.
598
+ if (isPublishedSeedRef(propertyValue))
599
+ continue;
600
+ throw new Error(`No relatedItem found for ${relationProperty.propertyName}`);
601
+ }
602
+ uploads = await getItemOwnPublishUploadData(relatedItem, uploads, relationProperty, {
603
+ ...options,
604
+ skipRelationRecursion: true,
605
+ });
606
+ }
607
+ return uploads;
608
+ };
609
+ /**
610
+ * Upload data for a publish of `item`: its own, and that of every draft item the publish carries
611
+ * along (reachable through relation and list properties, see publishDraftGraph.ts). Raw bytes plus
612
+ * Content-SHA-256 / Content-Type / configured tags; no Arweave transaction is created, so this
613
+ * does not touch the network. The bundler path in `@seedprotocol/publish` signs these as
614
+ * DataItems; {@link getPublishUploads} turns them into L1 transactions.
615
+ */
616
+ const getPublishUploadData = async (item, uploads = [], relatedItemProperty, options) => {
617
+ uploads = await getItemOwnPublishUploadData(item, uploads, relatedItemProperty, options);
618
+ if (options?.skipRelationRecursion) {
619
+ return uploads;
620
+ }
621
+ const { drafts } = await getPublishDraftGraph(item, { strict: true });
622
+ for (const { item: draft, via, viaList } of drafts) {
623
+ uploads = await getItemOwnPublishUploadData(draft, uploads, viaList ? undefined : via, options);
624
+ }
625
+ return uploads;
626
+ };
627
+ /**
628
+ * Arweave L1 transactions for a publish of `item`: {@link getPublishUploadData}, each made into an
629
+ * unsigned transaction carrying the same tags.
630
+ */
631
+ const getPublishUploads = async (item, uploads = [], relatedItemProperty, options) => {
632
+ const uploadData = await getPublishUploadData(item, [], relatedItemProperty, options);
633
+ // Each createTransaction fetches the price / anchor from the gateway: run a few at once.
634
+ const created = await mapWithConcurrency(uploadData, CREATE_TRANSACTION_CONCURRENCY, async (upload) => ({
635
+ itemPropertyName: upload.itemPropertyName,
636
+ itemPropertyLocalId: upload.itemPropertyLocalId,
637
+ seedLocalId: upload.seedLocalId,
638
+ versionLocalId: upload.versionLocalId,
639
+ transactionToSign: await BaseArweaveClient.createTransaction(upload.data, {
640
+ tags: upload.tags.length ? upload.tags : undefined,
641
+ }),
642
+ }));
643
+ uploads.push(...created);
644
+ return uploads;
645
+ };
646
+
647
+ export { CREATE_TRANSACTION_CONCURRENCY, getPublishUploadData, getPublishUploads, itemHasPublishUploadCandidates, resolveItemStorageChildFile };
648
+ //# sourceMappingURL=getPublishUploads-SFHCbf_y.js.map