@seedprotocol/sdk 0.4.32 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/dist/BasePathResolver-BDgc7c4T.js +485 -0
  2. package/dist/BasePathResolver-BDgc7c4T.js.map +1 -0
  3. package/dist/{ModelProperty-e_hXSFvf.js → ModelProperty-BBXBvgvy.js} +38 -43
  4. package/dist/ModelProperty-BBXBvgvy.js.map +1 -0
  5. package/dist/{Schema-DonRkUOJ.js → Schema-xAt7jWlW.js} +40 -40
  6. package/dist/{Schema-DonRkUOJ.js.map → Schema-xAt7jWlW.js.map} +1 -1
  7. package/dist/{SchemaValidationService-DcmfhQae.js → SchemaValidationService-CLzAdBm-.js} +10 -5
  8. package/dist/{SchemaValidationService-DcmfhQae.js.map → SchemaValidationService-CLzAdBm-.js.map} +1 -1
  9. package/dist/{backfillMetadataPropertyIds-CKTfvFgQ.js → backfillMetadataPropertyIds-DBVaIs7O.js} +3 -11
  10. package/dist/{backfillMetadataPropertyIds-CKTfvFgQ.js.map → backfillMetadataPropertyIds-DBVaIs7O.js.map} +1 -1
  11. package/dist/cjs/{ModelProperty-BQYU5hPQ.js → ModelProperty-Dgd4tGrB.js} +25 -26
  12. package/dist/cjs/{ModelProperty-BQYU5hPQ.js.map → ModelProperty-Dgd4tGrB.js.map} +1 -1
  13. package/dist/cjs/{Schema-BcRHcQ0W.js → Schema-dkd-eo3B.js} +28 -29
  14. package/dist/cjs/{Schema-BcRHcQ0W.js.map → Schema-dkd-eo3B.js.map} +1 -1
  15. package/dist/cjs/{SchemaValidationService-CQNDgyZl.js → SchemaValidationService-BMnjcVWV.js} +9 -10
  16. package/dist/cjs/{SchemaValidationService-CQNDgyZl.js.map → SchemaValidationService-BMnjcVWV.js.map} +1 -1
  17. package/dist/cjs/{backfillMetadataPropertyIds-Dn4oVmEv.js → backfillMetadataPropertyIds-ClLuj3s6.js} +11 -12
  18. package/dist/cjs/{backfillMetadataPropertyIds-Dn4oVmEv.js.map → backfillMetadataPropertyIds-ClLuj3s6.js.map} +1 -1
  19. package/dist/cjs/eas-nWAzbl_F.js +112 -0
  20. package/dist/cjs/eas-nWAzbl_F.js.map +1 -0
  21. package/dist/cjs/{getItem-DpnPrzl3.js → getItem-B08FgglK.js} +11 -12
  22. package/dist/cjs/{getItem-DpnPrzl3.js.map → getItem-B08FgglK.js.map} +1 -1
  23. package/dist/cjs/{getPublishPayload-CGKMEL3H.js → getPublishPayload-B_G_6qkE.js} +93 -83
  24. package/dist/cjs/getPublishPayload-B_G_6qkE.js.map +1 -0
  25. package/dist/cjs/{getPublishUploads-DeI0f2UN.js → getPublishUploads-Dt-DS-lo.js} +17 -18
  26. package/dist/cjs/{getPublishUploads-DeI0f2UN.js.map → getPublishUploads-Dt-DS-lo.js.map} +1 -1
  27. package/dist/cjs/{getSegmentedItemProperties-BgS_FhAx.js → getSegmentedItemProperties-BDGbeDW7.js} +64 -15
  28. package/dist/cjs/getSegmentedItemProperties-BDGbeDW7.js.map +1 -0
  29. package/dist/cjs/{index-ByozbTn_.js → index-CRBI6dSD.js} +1663 -3244
  30. package/dist/cjs/index-CRBI6dSD.js.map +1 -0
  31. package/dist/cjs/{index-BnAqr2le.js → index-Dx19j60c.js} +12 -13
  32. package/dist/cjs/index-Dx19j60c.js.map +1 -0
  33. package/dist/cjs/index.browser-BSf8HpnU.js +22 -0
  34. package/dist/cjs/index.browser-BSf8HpnU.js.map +1 -0
  35. package/dist/cjs/{ownership-CsWuaNfH.js → ownership-3Tc1-Yrc.js} +11 -25
  36. package/dist/cjs/{ownership-CsWuaNfH.js.map → ownership-3Tc1-Yrc.js.map} +1 -1
  37. package/dist/cjs/{property-CeR45LMx.js → property-628qAHpN.js} +13 -14
  38. package/dist/cjs/{property-CeR45LMx.js.map → property-628qAHpN.js.map} +1 -1
  39. package/dist/cjs/{syncDbWithEas-CA2Lum5V.js → syncDbWithEas-DOBtMPw-.js} +65 -81
  40. package/dist/cjs/syncDbWithEas-DOBtMPw-.js.map +1 -0
  41. package/dist/configurePlatform-Ce6NIKRP.js +28 -0
  42. package/dist/configurePlatform-Ce6NIKRP.js.map +1 -0
  43. package/dist/constants-DMHTYMgJ.js +120 -0
  44. package/dist/constants-DMHTYMgJ.js.map +1 -0
  45. package/dist/constants-slkc9uq0.js +655 -0
  46. package/dist/constants-slkc9uq0.js.map +1 -0
  47. package/dist/db-CSmK0c3e.js +1972 -0
  48. package/dist/db-CSmK0c3e.js.map +1 -0
  49. package/dist/eas-rx1grht5.js +69 -0
  50. package/dist/eas-rx1grht5.js.map +1 -0
  51. package/dist/{getItem-GOXWo_Iy.js → getItem-hPBJU5JF.js} +11 -6
  52. package/dist/{getItem-GOXWo_Iy.js.map → getItem-hPBJU5JF.js.map} +1 -1
  53. package/dist/{getPublishPayload-D16enahU.js → getPublishPayload-5ugovGK5.js} +88 -74
  54. package/dist/getPublishPayload-5ugovGK5.js.map +1 -0
  55. package/dist/{getPublishUploads-wGqH19UY.js → getPublishUploads-CdWeci-s.js} +15 -10
  56. package/dist/{getPublishUploads-wGqH19UY.js.map → getPublishUploads-CdWeci-s.js.map} +1 -1
  57. package/dist/{getSegmentedItemProperties-Be3kYWY3.js → getSegmentedItemProperties-DV2LHElJ.js} +18 -15
  58. package/dist/getSegmentedItemProperties-DV2LHElJ.js.map +1 -0
  59. package/dist/index-CcH2e0Zr.js +23 -0
  60. package/dist/index-CcH2e0Zr.js.map +1 -0
  61. package/dist/{index-BcXKZQpX.js → index-ClwdGWfr.js} +1625 -5474
  62. package/dist/index-ClwdGWfr.js.map +1 -0
  63. package/dist/{index-BFyMxc7e.js → index-QMrBK-L3.js} +2 -2
  64. package/dist/index-QMrBK-L3.js.map +1 -0
  65. package/dist/index.node-CrXwRoiB.js +503 -0
  66. package/dist/index.node-CrXwRoiB.js.map +1 -0
  67. package/dist/main.cjs +12 -14
  68. package/dist/main.cjs.map +1 -1
  69. package/dist/main.js +32 -22
  70. package/dist/main.js.map +1 -1
  71. package/dist/node.js +41 -346
  72. package/dist/node.js.map +1 -1
  73. package/dist/{ownership-C17YhE7J.js → ownership-58i0iyD9.js} +14 -9
  74. package/dist/{ownership-C17YhE7J.js.map → ownership-58i0iyD9.js.map} +1 -1
  75. package/dist/platform.browser.js +3512 -0
  76. package/dist/platform.browser.js.map +1 -0
  77. package/dist/platform.node.js +19 -0
  78. package/dist/platform.node.js.map +1 -0
  79. package/dist/{property-CRAau-Q-.js → property-CKhOxRNt.js} +15 -11
  80. package/dist/property-CKhOxRNt.js.map +1 -0
  81. package/dist/src/Item/Item.d.ts.map +1 -1
  82. package/dist/src/Item/service/actors/fetchDataFromEas.d.ts.map +1 -1
  83. package/dist/src/Item/service/actors/saveDataToDb.d.ts.map +1 -1
  84. package/dist/src/Model/service/actors/createModelProperties.d.ts.map +1 -1
  85. package/dist/src/Model/service/modelMachine.d.ts +1 -1
  86. package/dist/src/browser/db/Db.d.ts +17 -18
  87. package/dist/src/browser/db/Db.d.ts.map +1 -1
  88. package/dist/src/browser/helpers/ArweaveClient.d.ts +10 -27
  89. package/dist/src/browser/helpers/ArweaveClient.d.ts.map +1 -1
  90. package/dist/src/browser/helpers/EasClient.d.ts +6 -4
  91. package/dist/src/browser/helpers/EasClient.d.ts.map +1 -1
  92. package/dist/src/browser/helpers/FileManager.d.ts +27 -26
  93. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  94. package/dist/src/browser/helpers/PathResolver.d.ts +6 -5
  95. package/dist/src/browser/helpers/PathResolver.d.ts.map +1 -1
  96. package/dist/src/browser/helpers/QueryClient.d.ts +6 -5
  97. package/dist/src/browser/helpers/QueryClient.d.ts.map +1 -1
  98. package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
  99. package/dist/src/client/ClientManager.d.ts.map +1 -1
  100. package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
  101. package/dist/src/client/actors/processSchemaFiles.d.ts.map +1 -1
  102. package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
  103. package/dist/src/db/Db/BaseDb.d.ts +6 -26
  104. package/dist/src/db/Db/BaseDb.d.ts.map +1 -1
  105. package/dist/src/db/read/getItemData.d.ts +8 -0
  106. package/dist/src/db/read/getItemData.d.ts.map +1 -1
  107. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  108. package/dist/src/db/write/createMetadata.d.ts.map +1 -1
  109. package/dist/src/db/write/updateMetadata.d.ts.map +1 -1
  110. package/dist/src/eas.d.ts +4 -37
  111. package/dist/src/eas.d.ts.map +1 -1
  112. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  113. package/dist/src/helpers/ArweaveClient/BaseArweaveClient.d.ts +1 -101
  114. package/dist/src/helpers/ArweaveClient/BaseArweaveClient.d.ts.map +1 -1
  115. package/dist/src/helpers/ArweaveClient/arweaveL1UploadApi.d.ts +1 -51
  116. package/dist/src/helpers/ArweaveClient/arweaveL1UploadApi.d.ts.map +1 -1
  117. package/dist/src/helpers/ArweaveClient/index.d.ts +2 -2
  118. package/dist/src/helpers/ArweaveClient/index.d.ts.map +1 -1
  119. package/dist/src/helpers/ArweaveClient/selectReadGateway.d.ts +1 -15
  120. package/dist/src/helpers/ArweaveClient/selectReadGateway.d.ts.map +1 -1
  121. package/dist/src/helpers/ArweaveClient/uploadApiVerification.d.ts +1 -22
  122. package/dist/src/helpers/ArweaveClient/uploadApiVerification.d.ts.map +1 -1
  123. package/dist/src/helpers/EasClient/BaseEasClient.d.ts +1 -9
  124. package/dist/src/helpers/EasClient/BaseEasClient.d.ts.map +1 -1
  125. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +4 -2
  126. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  127. package/dist/src/helpers/FileManager/IFileManager.d.ts +44 -0
  128. package/dist/src/helpers/FileManager/IFileManager.d.ts.map +1 -0
  129. package/dist/src/helpers/PathResolver/BasePathResolver.d.ts +16 -12
  130. package/dist/src/helpers/PathResolver/BasePathResolver.d.ts.map +1 -1
  131. package/dist/src/helpers/PathResolver/IPathResolver.d.ts +16 -0
  132. package/dist/src/helpers/PathResolver/IPathResolver.d.ts.map +1 -0
  133. package/dist/src/helpers/QueryClient/BaseQueryClient.d.ts +1 -6
  134. package/dist/src/helpers/QueryClient/BaseQueryClient.d.ts.map +1 -1
  135. package/dist/src/helpers/constants.d.ts +4 -22
  136. package/dist/src/helpers/constants.d.ts.map +1 -1
  137. package/dist/src/helpers/db.d.ts.map +1 -1
  138. package/dist/src/helpers/easPropertyCanonical.d.ts +1 -14
  139. package/dist/src/helpers/easPropertyCanonical.d.ts.map +1 -1
  140. package/dist/src/helpers/easRevokedFilter.d.ts +1 -9
  141. package/dist/src/helpers/easRevokedFilter.d.ts.map +1 -1
  142. package/dist/src/helpers/easUid.d.ts +1 -12
  143. package/dist/src/helpers/easUid.d.ts.map +1 -1
  144. package/dist/src/helpers/ethereumUtils.d.ts +5 -0
  145. package/dist/src/helpers/ethereumUtils.d.ts.map +1 -0
  146. package/dist/src/helpers/file/fetchAll/index.d.ts +1 -1
  147. package/dist/src/helpers/file/fetchAll/index.d.ts.map +1 -1
  148. package/dist/src/helpers/gateway/gatewayState.d.ts +2 -0
  149. package/dist/src/helpers/gateway/gatewayState.d.ts.map +1 -0
  150. package/dist/src/helpers/gateway/resolveSeedGatewayEndpoints.d.ts +2 -0
  151. package/dist/src/helpers/gateway/resolveSeedGatewayEndpoints.d.ts.map +1 -0
  152. package/dist/src/helpers/gateway/seedGatewayConfig.d.ts +2 -0
  153. package/dist/src/helpers/gateway/seedGatewayConfig.d.ts.map +1 -0
  154. package/dist/src/helpers/generateId.d.ts +2 -0
  155. package/dist/src/helpers/generateId.d.ts.map +1 -0
  156. package/dist/src/helpers/getSchemaForItemProperty.d.ts +1 -1
  157. package/dist/src/helpers/getSchemaForItemProperty.d.ts.map +1 -1
  158. package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
  159. package/dist/src/helpers/index.d.ts +16 -15
  160. package/dist/src/helpers/index.d.ts.map +1 -1
  161. package/dist/src/helpers/isSqliteUniqueConstraintError.d.ts +7 -0
  162. package/dist/src/helpers/isSqliteUniqueConstraintError.d.ts.map +1 -0
  163. package/dist/src/helpers/mediaRef.d.ts +3 -0
  164. package/dist/src/helpers/mediaRef.d.ts.map +1 -1
  165. package/dist/src/helpers/property/index.d.ts.map +1 -1
  166. package/dist/src/index.d.ts +13 -7
  167. package/dist/src/index.d.ts.map +1 -1
  168. package/dist/src/interfaces/IDb.d.ts +11 -0
  169. package/dist/src/interfaces/IDb.d.ts.map +1 -1
  170. package/dist/src/node/db/Db.d.ts +22 -37
  171. package/dist/src/node/db/Db.d.ts.map +1 -1
  172. package/dist/src/node/helpers/ArweaveClient.d.ts +4 -30
  173. package/dist/src/node/helpers/ArweaveClient.d.ts.map +1 -1
  174. package/dist/src/node/helpers/EasClient.d.ts +4 -6
  175. package/dist/src/node/helpers/EasClient.d.ts.map +1 -1
  176. package/dist/src/node/helpers/FileManager.d.ts +26 -25
  177. package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
  178. package/dist/src/node/helpers/PathResolver.d.ts +6 -5
  179. package/dist/src/node/helpers/PathResolver.d.ts.map +1 -1
  180. package/dist/src/node/helpers/QueryClient.d.ts +4 -6
  181. package/dist/src/node/helpers/QueryClient.d.ts.map +1 -1
  182. package/dist/src/node/helpers/scripts.d.ts +5 -7
  183. package/dist/src/node/helpers/scripts.d.ts.map +1 -1
  184. package/dist/src/node/index.d.ts +2 -9
  185. package/dist/src/node/index.d.ts.map +1 -1
  186. package/dist/src/node/webpack/index.d.ts +3 -0
  187. package/dist/src/node/webpack/index.d.ts.map +1 -1
  188. package/dist/src/platform/configurePlatform.d.ts +6 -0
  189. package/dist/src/platform/configurePlatform.d.ts.map +1 -0
  190. package/dist/src/platform/index.browser.d.ts +3 -0
  191. package/dist/src/platform/index.browser.d.ts.map +1 -0
  192. package/dist/src/platform/index.d.ts +9 -0
  193. package/dist/src/platform/index.d.ts.map +1 -0
  194. package/dist/src/platform/index.node.d.ts +3 -0
  195. package/dist/src/platform/index.node.d.ts.map +1 -0
  196. package/dist/src/platform/types.d.ts +14 -0
  197. package/dist/src/platform/types.d.ts.map +1 -0
  198. package/dist/src/query/createLocalQueryDataSource.d.ts +6 -0
  199. package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -0
  200. package/dist/src/query/index.d.ts +4 -0
  201. package/dist/src/query/index.d.ts.map +1 -0
  202. package/dist/src/query/registerSeedQueryLocalSource.d.ts +25 -0
  203. package/dist/src/query/registerSeedQueryLocalSource.d.ts.map +1 -0
  204. package/dist/src/stores/eas.d.ts +1 -18
  205. package/dist/src/stores/eas.d.ts.map +1 -1
  206. package/dist/src/testing/platformTestHandle.d.ts +8 -0
  207. package/dist/src/testing/platformTestHandle.d.ts.map +1 -0
  208. package/dist/src/types/gateway.d.ts +2 -0
  209. package/dist/src/types/gateway.d.ts.map +1 -0
  210. package/dist/src/types/index.d.ts +5 -0
  211. package/dist/src/types/index.d.ts.map +1 -1
  212. package/dist/src/types/item.d.ts +1 -1
  213. package/dist/src/types/item.d.ts.map +1 -1
  214. package/dist/src/types/machines.d.ts +12 -0
  215. package/dist/src/types/machines.d.ts.map +1 -1
  216. package/dist/src/types/seedProtocol.d.ts +1 -1
  217. package/dist/src/types/seedProtocol.d.ts.map +1 -1
  218. package/dist/src/vite/index.d.ts +2 -47
  219. package/dist/src/vite/index.d.ts.map +1 -1
  220. package/dist/{syncDbWithEas-CB5aXPtf.js → syncDbWithEas-GsaXzTIY.js} +59 -56
  221. package/dist/syncDbWithEas-GsaXzTIY.js.map +1 -0
  222. package/dist/{updateSeedRevokedAt-BIu5Q4Po.js → updateSeedRevokedAt-Ba0OhDQj.js} +2 -2
  223. package/dist/{updateSeedRevokedAt-BIu5Q4Po.js.map → updateSeedRevokedAt-Ba0OhDQj.js.map} +1 -1
  224. package/dist/vite.cjs +5 -481
  225. package/dist/vite.cjs.map +1 -1
  226. package/dist/vite.js +1 -483
  227. package/dist/vite.js.map +1 -1
  228. package/package.json +42 -37
  229. package/dist/ArweaveClient-CZpZgmR2.js +0 -204
  230. package/dist/ArweaveClient-CZpZgmR2.js.map +0 -1
  231. package/dist/ArweaveClient-Cs7AL9dp.js +0 -204
  232. package/dist/ArweaveClient-Cs7AL9dp.js.map +0 -1
  233. package/dist/Db-CF6R7HIy.js +0 -2098
  234. package/dist/Db-CF6R7HIy.js.map +0 -1
  235. package/dist/Db-CZkONsdT.js +0 -248
  236. package/dist/Db-CZkONsdT.js.map +0 -1
  237. package/dist/EasClient-PXOzSzPG.js +0 -29
  238. package/dist/EasClient-PXOzSzPG.js.map +0 -1
  239. package/dist/EasClient-qfTiM2we.js +0 -29
  240. package/dist/EasClient-qfTiM2we.js.map +0 -1
  241. package/dist/FileManager-5GkHtxF7.js +0 -1256
  242. package/dist/FileManager-5GkHtxF7.js.map +0 -1
  243. package/dist/FileManager-jORQ8Bb6.js +0 -177
  244. package/dist/FileManager-jORQ8Bb6.js.map +0 -1
  245. package/dist/ModelProperty-e_hXSFvf.js.map +0 -1
  246. package/dist/PathResolver-B4_X69Rd.js +0 -204
  247. package/dist/PathResolver-B4_X69Rd.js.map +0 -1
  248. package/dist/PathResolver-Dz0RVGIz.js +0 -78
  249. package/dist/PathResolver-Dz0RVGIz.js.map +0 -1
  250. package/dist/QueryClient-CXHZ239d.js +0 -51
  251. package/dist/QueryClient-CXHZ239d.js.map +0 -1
  252. package/dist/QueryClient-D_UK4YLm.js +0 -35
  253. package/dist/QueryClient-D_UK4YLm.js.map +0 -1
  254. package/dist/arweave-default-shim.js +0 -6
  255. package/dist/cjs/getPublishPayload-CGKMEL3H.js.map +0 -1
  256. package/dist/cjs/getSegmentedItemProperties-BgS_FhAx.js.map +0 -1
  257. package/dist/cjs/index-BnAqr2le.js.map +0 -1
  258. package/dist/cjs/index-ByozbTn_.js.map +0 -1
  259. package/dist/cjs/syncDbWithEas-CA2Lum5V.js.map +0 -1
  260. package/dist/debug-default-shim.js +0 -27
  261. package/dist/getPublishPayload-D16enahU.js.map +0 -1
  262. package/dist/getSegmentedItemProperties-Be3kYWY3.js.map +0 -1
  263. package/dist/index-BFyMxc7e.js.map +0 -1
  264. package/dist/index-BcXKZQpX.js.map +0 -1
  265. package/dist/index-C9p-skT3.js +0 -18
  266. package/dist/index-C9p-skT3.js.map +0 -1
  267. package/dist/property-CRAau-Q-.js.map +0 -1
  268. package/dist/queries-Ct7CcQ3g.js +0 -16
  269. package/dist/queries-Ct7CcQ3g.js.map +0 -1
  270. package/dist/src/Item/queries.d.ts +0 -27
  271. package/dist/src/Item/queries.d.ts.map +0 -1
  272. package/dist/src/graphql/fragments/Attestation.d.ts +0 -2
  273. package/dist/src/graphql/fragments/Attestation.d.ts.map +0 -1
  274. package/dist/src/graphql/fragments/Schema.d.ts +0 -2
  275. package/dist/src/graphql/fragments/Schema.d.ts.map +0 -1
  276. package/dist/src/graphql/fragments/index.d.ts +0 -3
  277. package/dist/src/graphql/fragments/index.d.ts.map +0 -1
  278. package/dist/src/graphql/gql/fragment-masking.d.ts +0 -20
  279. package/dist/src/graphql/gql/fragment-masking.d.ts.map +0 -1
  280. package/dist/src/graphql/gql/gql.d.ts +0 -107
  281. package/dist/src/graphql/gql/gql.d.ts.map +0 -1
  282. package/dist/src/graphql/gql/graphql.d.ts +0 -2969
  283. package/dist/src/graphql/gql/graphql.d.ts.map +0 -1
  284. package/dist/src/graphql/gql/index.d.ts +0 -3
  285. package/dist/src/graphql/gql/index.d.ts.map +0 -1
  286. package/dist/src/helpers/ArweaveClient/queries.d.ts +0 -13
  287. package/dist/src/helpers/ArweaveClient/queries.d.ts.map +0 -1
  288. package/dist/src/helpers/file/queries.d.ts +0 -9
  289. package/dist/src/helpers/file/queries.d.ts.map +0 -1
  290. package/dist/src/helpers/image/queries.d.ts +0 -7
  291. package/dist/src/helpers/image/queries.d.ts.map +0 -1
  292. package/dist/src/node/codegen/drizzle.d.ts +0 -5
  293. package/dist/src/node/codegen/drizzle.d.ts.map +0 -1
  294. package/dist/src/node/codegen/index.d.ts +0 -2
  295. package/dist/src/node/codegen/index.d.ts.map +0 -1
  296. package/dist/src/node/codegen/ts-to-proto.d.ts +0 -9
  297. package/dist/src/node/codegen/ts-to-proto.d.ts.map +0 -1
  298. package/dist/src/node/db/node.app.db.config.d.ts +0 -4
  299. package/dist/src/node/db/node.app.db.config.d.ts.map +0 -1
  300. package/dist/src/node/helpers/index.d.ts +0 -3
  301. package/dist/src/node/helpers/index.d.ts.map +0 -1
  302. package/dist/src/vite/arweave-default-shim.d.ts +0 -4
  303. package/dist/src/vite/arweave-default-shim.d.ts.map +0 -1
  304. package/dist/src/vite/debug-default-shim.d.ts +0 -3
  305. package/dist/src/vite/debug-default-shim.d.ts.map +0 -1
  306. package/dist/src/vite/easFix.d.ts +0 -2
  307. package/dist/src/vite/easFix.d.ts.map +0 -1
  308. package/dist/syncDbWithEas-CB5aXPtf.js.map +0 -1
  309. /package/dist/db/drizzle/{drizzle/0000_married_malice.sql → 0000_married_malice.sql} +0 -0
  310. /package/dist/db/drizzle/{drizzle/0001_sweet_bruce_banner.sql → 0001_sweet_bruce_banner.sql} +0 -0
  311. /package/dist/db/drizzle/{drizzle/0002_bitter_proudstar.sql → 0002_bitter_proudstar.sql} +0 -0
  312. /package/dist/db/drizzle/{drizzle/0003_cultured_senator_kelly.sql → 0003_cultured_senator_kelly.sql} +0 -0
  313. /package/dist/db/drizzle/{drizzle/0004_add_publisher_to_seeds.sql → 0004_add_publisher_to_seeds.sql} +0 -0
  314. /package/dist/db/drizzle/{drizzle/0005_bright_lily_hollister.sql → 0005_bright_lily_hollister.sql} +0 -0
  315. /package/dist/db/drizzle/{drizzle/0006_add_publisher_to_versions_and_metadata.sql → 0006_add_publisher_to_versions_and_metadata.sql} +0 -0
  316. /package/dist/db/drizzle/{drizzle/0007_add_required_to_properties.sql → 0007_add_required_to_properties.sql} +0 -0
  317. /package/dist/db/drizzle/{drizzle/0008_add_revoked_at_to_seeds.sql → 0008_add_revoked_at_to_seeds.sql} +0 -0
  318. /package/dist/db/drizzle/{drizzle/0009_happy_namor.sql → 0009_happy_namor.sql} +0 -0
  319. /package/dist/db/drizzle/{drizzle/0010_add_arweave_l1_finalize_jobs.sql → 0010_add_arweave_l1_finalize_jobs.sql} +0 -0
  320. /package/dist/db/drizzle/{drizzle/0011_normalize_placeholder_uids.sql → 0011_normalize_placeholder_uids.sql} +0 -0
  321. /package/dist/db/drizzle/{drizzle/0012_html_embedded_image_co_publish.sql → 0012_html_embedded_image_co_publish.sql} +0 -0
  322. /package/dist/db/drizzle/{drizzle/0013_eas_sync_processes.sql → 0013_eas_sync_processes.sql} +0 -0
  323. /package/dist/db/drizzle/{drizzle/meta → meta}/0000_snapshot.json +0 -0
  324. /package/dist/db/drizzle/{drizzle/meta → meta}/0001_snapshot.json +0 -0
  325. /package/dist/db/drizzle/{drizzle/meta → meta}/0002_snapshot.json +0 -0
  326. /package/dist/db/drizzle/{drizzle/meta → meta}/0003_snapshot.json +0 -0
  327. /package/dist/db/drizzle/{drizzle/meta → meta}/0004_snapshot.json +0 -0
  328. /package/dist/db/drizzle/{drizzle/meta → meta}/0005_snapshot.json +0 -0
  329. /package/dist/db/drizzle/{drizzle/meta → meta}/0006_snapshot.json +0 -0
  330. /package/dist/db/drizzle/{drizzle/meta → meta}/0007_snapshot.json +0 -0
  331. /package/dist/db/drizzle/{drizzle/meta → meta}/0008_snapshot.json +0 -0
  332. /package/dist/db/drizzle/{drizzle/meta → meta}/0009_snapshot.json +0 -0
  333. /package/dist/db/drizzle/{drizzle/meta → meta}/0010_snapshot.json +0 -0
  334. /package/dist/db/drizzle/{drizzle/meta → meta}/0013_snapshot.json +0 -0
  335. /package/dist/db/drizzle/{drizzle/meta → meta}/_journal.json +0 -0
@@ -0,0 +1,3512 @@
1
+ import { B as BaseDb, b as appState, t as BasePathResolver, a as BaseFileManager } from './BasePathResolver-BDgc7c4T.js';
2
+ import debug from 'debug';
3
+ import { sql } from 'drizzle-orm';
4
+ import { readMigrationFiles } from 'drizzle-orm/migrator';
5
+ import { drizzle } from 'drizzle-orm/sqlite-proxy';
6
+ import { migrate } from 'drizzle-orm/sqlite-proxy/migrator';
7
+ import { E as EAS_ENDPOINT } from './constants-slkc9uq0.js';
8
+ import { s as schema } from './index-QMrBK-L3.js';
9
+ import { SQLocalDrizzle } from 'sqlocal/drizzle';
10
+ import { Observable, distinctUntilChanged } from 'rxjs';
11
+ import { BaseArweaveClient, GET_TRANSACTION_TAGS } from '@seedprotocol/arweave';
12
+ import { GraphQLClient } from 'graphql-request';
13
+ import Arweave from 'arweave';
14
+ import { BaseEasClient, BaseQueryClient } from '@seedprotocol/eas';
15
+ import { QueryClient } from '@tanstack/react-query';
16
+ import 'drizzle-orm/sqlite-core';
17
+ import 'xstate';
18
+ import 'pluralize';
19
+ import '@sinclair/typebox';
20
+ import 'nanoid';
21
+ import 'nanoid-dictionary';
22
+ import '@seedprotocol/query';
23
+
24
+ const saveAppState = async (key, value) => {
25
+ const appDb = BaseDb.getAppDb();
26
+ await appDb
27
+ .insert(appState)
28
+ .values({
29
+ key,
30
+ value,
31
+ })
32
+ .onConflictDoUpdate({
33
+ target: appState.key,
34
+ set: {
35
+ value,
36
+ },
37
+ });
38
+ };
39
+
40
+ class BrowserPathResolver {
41
+ /** @deprecated Prefer BasePathResolver static methods or configure(). */
42
+ static getInstance() {
43
+ return BasePathResolver.getInstance();
44
+ }
45
+ /**
46
+ * Gets the root directory containing node_modules
47
+ * Note: In browser, this returns a virtual path based on OPFS
48
+ */
49
+ getRootWithNodeModules() {
50
+ // In browser, we use OPFS which doesn't have traditional paths
51
+ // Return a virtual root path
52
+ return '/';
53
+ }
54
+ /**
55
+ * Gets the SDK root directory
56
+ * Note: In browser, this returns a virtual path
57
+ */
58
+ getSdkRootDir() {
59
+ // In browser, SDK is bundled, so we return a virtual path
60
+ return '/sdk';
61
+ }
62
+ getNodeModulesDir() {
63
+ // In browser, node_modules don't exist in the traditional sense
64
+ return '/node_modules';
65
+ }
66
+ /**
67
+ * Gets the .seed directory path
68
+ * Note: In browser, this returns the OPFS path where .seed data is stored
69
+ */
70
+ getDotSeedDir(schemaFileDir) {
71
+ // In browser, .seed directory is stored in OPFS
72
+ // The actual path is handled by the FileManager
73
+ return '/.seed';
74
+ }
75
+ /**
76
+ * Finds the Seed Protocol config file
77
+ * Note: In browser, config files are not accessible via filesystem
78
+ */
79
+ findConfigFile(searchDir) {
80
+ // In browser, config files are typically embedded in the bundle
81
+ // or loaded via fetch/import
82
+ return null;
83
+ }
84
+ /**
85
+ * Gets paths for app-specific directories
86
+ * Note: In browser, these are virtual paths for OPFS
87
+ */
88
+ getAppPaths(schemaFileDir) {
89
+ const dotSeedDir = this.getDotSeedDir(schemaFileDir);
90
+ return {
91
+ sdkRootDir: this.getSdkRootDir(),
92
+ dotSeedDir,
93
+ nodeModulesDir: this.getNodeModulesDir(),
94
+ appSchemaDir: `${dotSeedDir}/schema`,
95
+ appDbDir: `${dotSeedDir}/db`,
96
+ appMetaDir: `${dotSeedDir}/db/meta`,
97
+ };
98
+ }
99
+ }
100
+ BasePathResolver.configure(new BrowserPathResolver());
101
+
102
+ var filesDownload = `(
103
+ ${function () {
104
+ const identifyString = (str) => {
105
+ try {
106
+ JSON.parse(str);
107
+ return 'json';
108
+ }
109
+ catch (e) {
110
+ // Not JSON
111
+ }
112
+ if (!str) {
113
+ return;
114
+ }
115
+ if (str.trim().startsWith('<') && str.trim().endsWith('>')) {
116
+ return 'html';
117
+ }
118
+ // Simple markdown checks (very naive)
119
+ if (/^#{1,6}\s|^-{3,}|\*{3,}|^-{1,2}\s|\*\s/.test(str)) {
120
+ return 'markdown';
121
+ }
122
+ if (/^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {
123
+ return 'base64';
124
+ }
125
+ // Default to plain text if unsure
126
+ return 'text';
127
+ };
128
+ const getMimeType = (base64) => {
129
+ if (!base64) {
130
+ return null;
131
+ }
132
+ const result = base64.match(/^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,/);
133
+ if (result && result.length > 1) {
134
+ return result[1];
135
+ }
136
+ else {
137
+ return null; // MIME type could not be determined
138
+ }
139
+ };
140
+ const getDataTypeFromString = (data) => {
141
+ const nonImageBase64Regex = /^(?!data:image\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/;
142
+ if (nonImageBase64Regex.test(data)) {
143
+ return 'base64';
144
+ }
145
+ // Regular expression for base64 (simple version, checking for base64 format)
146
+ const imageBase64Regex = /^data:image\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/;
147
+ if (imageBase64Regex.test(data)) {
148
+ return 'imageBase64';
149
+ }
150
+ // Regular expression for URL (simple version, checking for common URL format)
151
+ const urlRegex = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
152
+ if (urlRegex.test(data)) {
153
+ return 'url';
154
+ }
155
+ return null;
156
+ };
157
+ const isBinary = (arrayBuffer) => {
158
+ const view = new Uint8Array(arrayBuffer);
159
+ let nonTextCount = 0;
160
+ const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)
161
+ for (let i = 0; i < view.length; i++) {
162
+ const byte = view[i];
163
+ // ASCII printable characters (32-126) and common whitespace (9, 10, 13)
164
+ if ((byte >= 32 && byte <= 126) || // Printable ASCII
165
+ byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR
166
+ ) {
167
+ continue;
168
+ }
169
+ nonTextCount++;
170
+ if (nonTextCount / view.length > threshold) {
171
+ return true; // More than threshold are non-text bytes
172
+ }
173
+ }
174
+ return false; // Fewer than threshold are non-text bytes
175
+ };
176
+ const saveBufferToOPFS = async (filePath, buffer) => {
177
+ // Access the OPFS root directory
178
+ const rootHandle = await navigator.storage.getDirectory();
179
+ // Split the filePath into directory segments and file name
180
+ const segments = filePath.split('/').filter(Boolean);
181
+ const fileName = segments.pop(); // Extract the file name
182
+ if (!fileName) {
183
+ throw new Error('Invalid file path: No file name provided.');
184
+ }
185
+ // Traverse or create directories as needed
186
+ let currentDirHandle = rootHandle;
187
+ for (const segment of segments) {
188
+ currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
189
+ }
190
+ // Create or open the file in OPFS
191
+ const fileHandleAsync = await currentDirHandle.getFileHandle(fileName, { create: true });
192
+ const fileHandle = await fileHandleAsync.createSyncAccessHandle();
193
+ // Write the buffer to the file
194
+ fileHandle.write(buffer);
195
+ fileHandle.flush();
196
+ fileHandle.close();
197
+ };
198
+ const getFilesPath = (filesRoot, ...parts) => {
199
+ const root = filesRoot.replace(/\/$/, '');
200
+ return [root, ...parts].filter(Boolean).join('/').replace(/\/+/g, '/');
201
+ };
202
+ const downloadFiles = async ({ transactionIds, arweaveHost, filesRoot = '/files', }) => {
203
+ let arrayBuffer;
204
+ for (const transactionId of transactionIds) {
205
+ try {
206
+ const response = await fetch((() => {
207
+ const base = arweaveHost.trim().startsWith('http')
208
+ ? arweaveHost.trim().replace(/\/$/, '')
209
+ : (() => {
210
+ const h = arweaveHost.trim();
211
+ const protocol = h.startsWith('127.0.0.1') || h.startsWith('localhost') || h.includes(':1984')
212
+ ? 'http'
213
+ : 'https';
214
+ return `${protocol}://${h}`;
215
+ })();
216
+ return `${base}/raw/${transactionId}`;
217
+ })());
218
+ arrayBuffer = await response.arrayBuffer();
219
+ }
220
+ catch (error) {
221
+ globalThis.postMessage({
222
+ message: 'excludeTransaction',
223
+ transactionId,
224
+ });
225
+ continue;
226
+ }
227
+ let dataString;
228
+ const isBinaryData = isBinary(arrayBuffer);
229
+ if (!isBinaryData) {
230
+ const decoder = new TextDecoder('utf-8');
231
+ const text = decoder.decode(arrayBuffer);
232
+ dataString = text;
233
+ }
234
+ if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
235
+ const dataStringParts = dataString
236
+ .split('===FILE_SEPARATOR===')
237
+ .slice(1);
238
+ if (dataStringParts.length % 2 !== 0) {
239
+ throw new Error('Input array must have an even number of elements.');
240
+ }
241
+ for (let i = 0; i < dataStringParts.length; i += 2) {
242
+ const contentType = dataStringParts[i];
243
+ const content = dataStringParts[i + 1];
244
+ const encoder = new TextEncoder();
245
+ if (contentType === 'html') {
246
+ const fileName = `${transactionId}.html`;
247
+ const buffer = encoder.encode(content);
248
+ saveBufferToOPFS(getFilesPath(filesRoot, 'html', fileName), buffer);
249
+ }
250
+ if (contentType === 'json') {
251
+ const fileName = `${transactionId}.json`;
252
+ const buffer = encoder.encode(content);
253
+ saveBufferToOPFS(getFilesPath(filesRoot, 'json', fileName), buffer);
254
+ }
255
+ }
256
+ continue;
257
+ }
258
+ if (!dataString && arrayBuffer) {
259
+ saveBufferToOPFS(getFilesPath(filesRoot, 'images', transactionId), new Uint8Array(arrayBuffer));
260
+ continue;
261
+ }
262
+ if (!dataString) {
263
+ continue;
264
+ }
265
+ let contentType = identifyString(dataString);
266
+ if (contentType !== 'json' &&
267
+ contentType !== 'base64' &&
268
+ contentType !== 'html') {
269
+ const possibleImageType = getDataTypeFromString(dataString);
270
+ if (!possibleImageType) {
271
+ continue;
272
+ }
273
+ contentType = possibleImageType;
274
+ }
275
+ if (contentType === 'url') {
276
+ const url = dataString;
277
+ let buffer;
278
+ try {
279
+ const response = await fetch(url);
280
+ buffer = await response.arrayBuffer();
281
+ }
282
+ catch (error) {
283
+ globalThis.postMessage({
284
+ message: 'excludeTransaction',
285
+ transactionId,
286
+ });
287
+ continue;
288
+ }
289
+ const bufferUint8Array = new Uint8Array(buffer);
290
+ // Extract the file extension from the URL
291
+ const extensionMatch = url.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i);
292
+ if (!extensionMatch) {
293
+ throw new Error('Unable to determine the file extension from the URL.');
294
+ }
295
+ extensionMatch[0]; // e.g., ".jpg"
296
+ // Set the file name (you can customize this)
297
+ // const fileNameFromUrl = `${transactionId}${fileExtension}`
298
+ await saveBufferToOPFS(getFilesPath(filesRoot, 'images', transactionId), bufferUint8Array);
299
+ continue;
300
+ }
301
+ const mimeType = getMimeType(dataString);
302
+ let fileExtension = mimeType;
303
+ if (fileExtension && fileExtension?.startsWith('image')) {
304
+ fileExtension = fileExtension.replace('image/', '');
305
+ }
306
+ let fileName = transactionId;
307
+ if (contentType === 'base64') {
308
+ if (fileExtension) {
309
+ fileName += `.${fileExtension}`;
310
+ }
311
+ // Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
312
+ const base64Data = dataString.split(',').pop() || '';
313
+ // Decode the Base64 string to binary
314
+ const binaryString = atob(base64Data);
315
+ const length = binaryString.length;
316
+ const binaryData = new Uint8Array(length);
317
+ for (let i = 0; i < length; i++) {
318
+ binaryData[i] = binaryString.charCodeAt(i);
319
+ }
320
+ await saveBufferToOPFS(getFilesPath(filesRoot, 'images', fileName), binaryData);
321
+ }
322
+ if (contentType === 'html') {
323
+ fileName += '.html';
324
+ const encoder = new TextEncoder();
325
+ const buffer = encoder.encode(dataString);
326
+ await saveBufferToOPFS(getFilesPath(filesRoot, 'html', fileName), buffer);
327
+ }
328
+ if (contentType === 'json') {
329
+ fileName += '.json';
330
+ const encoder = new TextEncoder();
331
+ const buffer = encoder.encode(dataString);
332
+ await saveBufferToOPFS(getFilesPath(filesRoot, 'json', fileName), buffer);
333
+ }
334
+ }
335
+ };
336
+ onmessage = async (e) => {
337
+ const { debug, filesRoot } = e.data;
338
+ if (!debug) {
339
+ console.log = () => { };
340
+ }
341
+ await downloadFiles({ ...e.data, filesRoot });
342
+ globalThis.postMessage({
343
+ message: 'filesDownload onmessage done',
344
+ done: true,
345
+ });
346
+ };
347
+ }.toString()}
348
+ )()`;
349
+
350
+ const logger$4 = debug('seedSdk:browser:workers:FileDownloader');
351
+ class FileDownloader {
352
+ constructor() {
353
+ this.workersArchive = [];
354
+ this.downloadAll = async ({ transactionIds, arweaveHost, excludedTransactions }) => {
355
+ if (this.workersArchive.length > 0) {
356
+ for (let i = 0; i < this.workersArchive.length; i++) {
357
+ this.workersArchive[i].terminate();
358
+ delete this.workersArchive[i];
359
+ }
360
+ this.workersArchive = [];
361
+ }
362
+ const worker = new Worker(this.workerBlobUrl);
363
+ this.workersArchive.push(worker);
364
+ const localExcludedTransactions = new Set(excludedTransactions);
365
+ return new Promise((resolve, reject) => {
366
+ worker.onmessage = (e) => {
367
+ logger$4('filesDownload main thread onmessage', e.data);
368
+ if (e.data.message === 'excludeTransaction') {
369
+ localExcludedTransactions.add(e.data.transactionId);
370
+ }
371
+ if (e.data.done) {
372
+ saveAppState('excludedTransactions', JSON.stringify(Array.from(localExcludedTransactions)))
373
+ .then(() => {
374
+ resolve(e.data);
375
+ })
376
+ .catch((error) => {
377
+ reject(error);
378
+ });
379
+ }
380
+ if (e.data.error) {
381
+ reject(e.data.error);
382
+ }
383
+ };
384
+ worker.postMessage({
385
+ transactionIds,
386
+ arweaveHost,
387
+ debug: logger$4.enabled,
388
+ filesRoot: BaseFileManager.getWorkingDir(),
389
+ });
390
+ });
391
+ };
392
+ this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
393
+ this.workerBlobUrl = globalThis.URL.createObjectURL(new Blob([filesDownload], { type: 'application/javascript' }));
394
+ }
395
+ }
396
+
397
+ var imageResize = `(
398
+ ${function () {
399
+ async function listFilesInDirectory(directoryHandle) {
400
+ const entries = [];
401
+ for await (const [name, handle] of directoryHandle.entries()) {
402
+ entries.push({
403
+ name,
404
+ kind: handle.kind,
405
+ });
406
+ }
407
+ return entries;
408
+ }
409
+ const getFileHandle = async (path, rootHandle = null) => {
410
+ // Split the path into segments
411
+ const segments = path.split('/').filter(Boolean);
412
+ // Start from the root directory if not provided
413
+ if (!rootHandle) {
414
+ rootHandle = await navigator.storage.getDirectory();
415
+ }
416
+ let currentHandle = rootHandle;
417
+ // Traverse the path segments
418
+ for (let i = 0; i < segments.length; i++) {
419
+ const segment = segments[i];
420
+ const isLastSegment = i === segments.length - 1;
421
+ try {
422
+ for await (const [name, handle] of currentHandle.entries()) {
423
+ if (name !== segment) {
424
+ continue;
425
+ }
426
+ if (isLastSegment) {
427
+ if (handle.kind === 'file') {
428
+ return handle; // Return the file handle if found
429
+ }
430
+ else {
431
+ throw new Error(`Path '${path}' refers to a directory, not a file.`);
432
+ }
433
+ }
434
+ else if (handle.kind === 'directory') {
435
+ currentHandle = handle; // Traverse into the directory
436
+ }
437
+ else {
438
+ throw new Error(`Invalid path segment '${segment}'`);
439
+ }
440
+ }
441
+ }
442
+ catch (err) {
443
+ if (err instanceof Error && err.name === 'NotFoundError') {
444
+ throw new Error(`Path '${path}' does not exist.`);
445
+ }
446
+ else {
447
+ throw err;
448
+ }
449
+ }
450
+ }
451
+ throw new Error(`Path '${path}' could not be resolved.`);
452
+ };
453
+ async function getFileFromOPFS(path) {
454
+ const fileHandleAsync = await getFileHandle(path);
455
+ const file = await fileHandleAsync.getFile();
456
+ return file;
457
+ }
458
+ /** Infer MIME from magic bytes. OPFS File may have empty type, causing createImageBitmap to fail. */
459
+ async function getBlobWithInferredMime(file) {
460
+ const buf = await file.arrayBuffer();
461
+ const bytes = new Uint8Array(buf);
462
+ let mime = file.type;
463
+ if (!mime || mime === '') {
464
+ if (bytes[0] === 0xff && bytes[1] === 0xd8)
465
+ mime = 'image/jpeg';
466
+ else if (bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47)
467
+ mime = 'image/png';
468
+ else if (bytes[0] === 0x52 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x52 && bytes[8] === 0x57 && bytes[9] === 0x45 && bytes[10] === 0x42 && bytes[11] === 0x50)
469
+ mime = 'image/webp';
470
+ else if (bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46)
471
+ mime = 'image/gif';
472
+ else if (bytes[0] === 0x42 && bytes[1] === 0x4d)
473
+ mime = 'image/bmp';
474
+ else if (bytes[4] === 0x66 && bytes[5] === 0x74 && bytes[6] === 0x79 && bytes[7] === 0x70 && bytes[8] === 0x61 && bytes[9] === 0x76 && bytes[10] === 0x69 && bytes[11] === 0x66)
475
+ mime = 'image/avif';
476
+ else if (bytes[4] === 0x66 && bytes[5] === 0x74 && bytes[6] === 0x79 && bytes[7] === 0x70 && bytes[8] === 0x68 && bytes[9] === 0x65 && bytes[10] === 0x69 && bytes[11] === 0x63)
477
+ mime = 'image/heic';
478
+ else
479
+ mime = 'image/jpeg';
480
+ }
481
+ return new Blob([buf], { type: mime });
482
+ }
483
+ const DEFAULT_CONFIG = {
484
+ argorithm: 'null',
485
+ processByHalf: true,
486
+ quality: 0.5,
487
+ maxWidth: 800,
488
+ maxHeight: 600,
489
+ debug: false,
490
+ mimeType: 'image/jpeg',
491
+ };
492
+ function isIos() {
493
+ if (typeof navigator === 'undefined')
494
+ return false;
495
+ if (!navigator.userAgent)
496
+ return false;
497
+ return /iPad|iPhone|iPod/.test(navigator.userAgent);
498
+ }
499
+ const getTargetHeight = (srcHeight, scale, config) => {
500
+ return Math.min(Math.floor(srcHeight * scale), config.maxHeight);
501
+ };
502
+ const findMaxWidth = (config, canvas) => {
503
+ //Let's find the max available width for scaled image
504
+ const ratio = canvas.width / canvas.height;
505
+ let mWidth = Math.min(canvas.width, config.maxWidth, ratio * config.maxHeight);
506
+ if (config.maxSize &&
507
+ config.maxSize > 0 &&
508
+ config.maxSize < (canvas.width * canvas.height) / 1000)
509
+ mWidth = Math.min(mWidth, Math.floor((config.maxSize * 1000) / canvas.height));
510
+ if (!!config.scaleRatio)
511
+ mWidth = Math.min(mWidth, Math.floor(config.scaleRatio * canvas.width));
512
+ const rHeight = getTargetHeight(canvas.height, mWidth / canvas.width, config);
513
+ // console.log(
514
+ // 'browser-image-resizer: original image size = ' +
515
+ // canvas.width +
516
+ // ' px (width) X ' +
517
+ // canvas.height +
518
+ // ' px (height)'
519
+ // );
520
+ // console.log(
521
+ // 'browser-image-resizer: scaled image size = ' +
522
+ // mWidth +
523
+ // ' px (width) X ' +
524
+ // rHeight +
525
+ // ' px (height)'
526
+ // );
527
+ if (mWidth <= 0) {
528
+ mWidth = 1;
529
+ console.warn("browser-image-resizer: image size is too small");
530
+ }
531
+ if (isIos() && mWidth * rHeight > 167777216) {
532
+ console.error("browser-image-resizer: image size is too large for iOS WebKit.", mWidth, rHeight);
533
+ throw new Error("browser-image-resizer: image size is too large for iOS WebKit.");
534
+ }
535
+ return mWidth;
536
+ };
537
+ /**
538
+ * Hermite resize, multicore version - fast image resize/resample using Hermite filter.
539
+ */
540
+ const resample = (srcCanvas, destCanvas, config) => {
541
+ return new Promise((resolve, reject) => {
542
+ const ratio_h = srcCanvas.height / destCanvas.height;
543
+ const cores = Math.min(navigator.hardwareConcurrency || 4, 4);
544
+ //prepare source and target data for workers
545
+ const ctx = srcCanvas.getContext('2d');
546
+ if (!ctx)
547
+ return reject('Canvas is empty (resample)');
548
+ const data_part = [];
549
+ const block_height = Math.ceil(srcCanvas.height / cores / 2) * 2;
550
+ let end_y = -1;
551
+ for (let c = 0; c < cores; c++) {
552
+ //source
553
+ const offset_y = end_y + 1;
554
+ if (offset_y >= srcCanvas.height) {
555
+ //size too small, nothing left for this core
556
+ continue;
557
+ }
558
+ end_y = Math.min(offset_y + block_height - 1, srcCanvas.height - 1);
559
+ const current_block_height = Math.min(block_height, srcCanvas.height - offset_y);
560
+ data_part.push({
561
+ source: ctx.getImageData(0, offset_y, srcCanvas.width, block_height),
562
+ startY: Math.ceil(offset_y / ratio_h),
563
+ height: current_block_height
564
+ });
565
+ }
566
+ //start
567
+ const destCtx = destCanvas.getContext('2d');
568
+ if (!destCtx)
569
+ return reject('Canvas is empty (resample dest)');
570
+ for (let c = 0; c < data_part.length; c++) {
571
+ //draw
572
+ const height_part = Math.ceil(data_part[c].height / ratio_h);
573
+ const target = destCtx.createImageData(destCanvas.width, height_part);
574
+ // target.data.set(event.data.target);
575
+ destCtx.putImageData(target, 0, data_part[c].startY);
576
+ }
577
+ });
578
+ };
579
+ /**
580
+ * Hermite resize - fast image resize/resample using Hermite filter. 1 cpu version!
581
+ */
582
+ const resampleSingle = (srcCanvasData, destCanvasData) => {
583
+ const ratio_w = srcCanvasData.width / destCanvasData.width;
584
+ const ratio_h = srcCanvasData.height / destCanvasData.height;
585
+ const ratio_w_half = Math.ceil(ratio_w / 2);
586
+ const ratio_h_half = Math.ceil(ratio_h / 2);
587
+ const data = srcCanvasData.data;
588
+ const data2 = destCanvasData.data;
589
+ for (let j = 0; j < destCanvasData.height; j++) {
590
+ for (let i = 0; i < destCanvasData.width; i++) {
591
+ const x2 = (i + j * destCanvasData.width) * 4;
592
+ let weight = 0;
593
+ let weights = 0;
594
+ let weights_alpha = 0;
595
+ let gx_r = 0;
596
+ let gx_g = 0;
597
+ let gx_b = 0;
598
+ let gx_a = 0;
599
+ const center_y = j * ratio_h;
600
+ const xx_start = Math.floor(i * ratio_w);
601
+ const xx_stop = Math.min(Math.ceil((i + 1) * ratio_w), srcCanvasData.width);
602
+ const yy_start = Math.floor(j * ratio_h);
603
+ const yy_stop = Math.min(Math.ceil((j + 1) * ratio_h), srcCanvasData.height);
604
+ for (let yy = yy_start; yy < yy_stop; yy++) {
605
+ let dy = Math.abs(center_y - yy) / ratio_h_half;
606
+ let center_x = i * ratio_w;
607
+ let w0 = dy * dy; //pre-calc part of w
608
+ for (let xx = xx_start; xx < xx_stop; xx++) {
609
+ let dx = Math.abs(center_x - xx) / ratio_w_half;
610
+ let w = Math.sqrt(w0 + dx * dx);
611
+ if (w >= 1) {
612
+ //pixel too far
613
+ continue;
614
+ }
615
+ //hermite filter
616
+ weight = 2 * w * w * w - 3 * w * w + 1;
617
+ let pos_x = 4 * (xx + yy * srcCanvasData.width);
618
+ //alpha
619
+ gx_a += weight * data[pos_x + 3];
620
+ weights_alpha += weight;
621
+ //colors
622
+ if (data[pos_x + 3] < 255)
623
+ weight = weight * data[pos_x + 3] / 250;
624
+ gx_r += weight * data[pos_x];
625
+ gx_g += weight * data[pos_x + 1];
626
+ gx_b += weight * data[pos_x + 2];
627
+ weights += weight;
628
+ }
629
+ }
630
+ data2[x2] = gx_r / weights;
631
+ data2[x2 + 1] = gx_g / weights;
632
+ data2[x2 + 2] = gx_b / weights;
633
+ data2[x2 + 3] = gx_a / weights_alpha;
634
+ }
635
+ }
636
+ };
637
+ /**
638
+ * Hermite resize. Detect cpu count and use best option for user.
639
+ */
640
+ const resampleAuto = (srcCanvas, destCanvas, config) => {
641
+ if (!!globalThis.Worker && navigator.hardwareConcurrency > 1 && config?.argorithm !== 'hermite_single') {
642
+ //workers supported and we have at least 2 cpu cores - using multithreading
643
+ return resample(srcCanvas, destCanvas);
644
+ }
645
+ else {
646
+ //1 cpu version
647
+ const { srcImgData, destImgData } = getImageData(srcCanvas, destCanvas);
648
+ resampleSingle(srcImgData, destImgData);
649
+ destCanvas.getContext('2d').putImageData(destImgData, 0, 0);
650
+ return;
651
+ }
652
+ };
653
+ async function scaleCanvasWithAlgorithm(canvas, config) {
654
+ const scale = config.outputWidth / canvas.width;
655
+ const scaled = new OffscreenCanvas(Math.floor(config.outputWidth), getTargetHeight(canvas.height, scale, config));
656
+ switch (config.algorithm) {
657
+ case 'hermite': {
658
+ await resampleAuto(canvas, scaled, config);
659
+ break;
660
+ }
661
+ case 'hermite_single': {
662
+ const { srcImgData, destImgData } = getImageData(canvas, scaled);
663
+ resampleSingle(srcImgData, destImgData);
664
+ scaled?.getContext('2d')?.putImageData(destImgData, 0, 0);
665
+ break;
666
+ }
667
+ case 'bilinear': {
668
+ // const { srcImgData, destImgData } = getImageData(canvas, scaled);
669
+ // bilinear(srcImgData, destImgData, scale);
670
+ // scaled?.getContext('2d')?.putImageData(destImgData, 0, 0);
671
+ break;
672
+ }
673
+ default: {
674
+ scaled.getContext('2d')?.drawImage(canvas, 0, 0, scaled.width, scaled.height);
675
+ break;
676
+ }
677
+ }
678
+ return scaled;
679
+ }
680
+ const getHalfScaleCanvas = (src) => {
681
+ const half = new OffscreenCanvas(src.width / 2, src.height / 2);
682
+ half
683
+ ?.getContext('2d')
684
+ ?.drawImage(src, 0, 0, half.width, half.height);
685
+ return half;
686
+ };
687
+ const getImageData = (canvas, scaled) => {
688
+ const srcImgData = canvas
689
+ ?.getContext('2d')
690
+ ?.getImageData(0, 0, canvas.width, canvas.height);
691
+ const destImgData = scaled
692
+ ?.getContext('2d')
693
+ ?.createImageData(scaled.width, scaled.height);
694
+ if (!srcImgData || !destImgData)
695
+ throw Error('Canvas is empty (scaleCanvasWithAlgorithm). You should run this script after the document is ready.');
696
+ return { srcImgData, destImgData };
697
+ };
698
+ async function saveBlobToOPFS(filePath, blob) {
699
+ // Access the OPFS root directory
700
+ const rootHandle = await navigator.storage.getDirectory();
701
+ // Split the filePath into directory segments and file name
702
+ const segments = filePath.split('/').filter(Boolean);
703
+ const fileName = segments.pop(); // Extract the file name
704
+ if (!fileName) {
705
+ throw new Error('Invalid file path: No file name provided.');
706
+ }
707
+ // Traverse or create directories as needed
708
+ let currentDirHandle = rootHandle;
709
+ for (const segment of segments) {
710
+ currentDirHandle = await currentDirHandle.getDirectoryHandle(segment, { create: true });
711
+ }
712
+ // Create or open the file in OPFS
713
+ const fileHandle = await currentDirHandle.getFileHandle(fileName, { create: true });
714
+ // Write the Blob to the file
715
+ const writableStream = await fileHandle.createWritable();
716
+ await writableStream.write(blob);
717
+ await writableStream.close();
718
+ }
719
+ const imageResize = async (filePath, width, height) => {
720
+ const config = {
721
+ ...DEFAULT_CONFIG,
722
+ algorithm: 'hermite_single',
723
+ mimeType: 'image/webp',
724
+ maxWidth: width,
725
+ maxHeight: height,
726
+ };
727
+ const rootHandle = await navigator.storage.getDirectory();
728
+ // List files in the root directory
729
+ await listFilesInDirectory(rootHandle);
730
+ const file = await getFileFromOPFS(filePath);
731
+ const blobWithMime = await getBlobWithInferredMime(file);
732
+ const imageBitmap = await createImageBitmap(blobWithMime);
733
+ let converting;
734
+ if (isIos() && imageBitmap.width * imageBitmap.height > 16777216) {
735
+ const scale = Math.sqrt(16777216 / (imageBitmap.width * imageBitmap.height));
736
+ converting = new OffscreenCanvas(Math.floor(imageBitmap.width * scale), Math.floor(imageBitmap.height * scale));
737
+ converting.getContext('2d')?.drawImage(imageBitmap, 0, 0, converting.width, converting.height);
738
+ }
739
+ else {
740
+ converting = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
741
+ converting.getContext('2d')?.drawImage(imageBitmap, 0, 0);
742
+ }
743
+ const maxWidth = findMaxWidth(config, converting);
744
+ if (!maxWidth) {
745
+ throw Error(`browser-image-resizer: maxWidth is ${maxWidth}!!`);
746
+ }
747
+ while (config.processByHalf && converting.width >= 2 * maxWidth) {
748
+ converting = getHalfScaleCanvas(converting);
749
+ }
750
+ if (converting.width > maxWidth) {
751
+ converting = await scaleCanvasWithAlgorithm(converting, Object.assign(config, { outputWidth: maxWidth }));
752
+ }
753
+ if (config.mimeType === null) {
754
+ return converting;
755
+ }
756
+ const resizedBlob = await converting.convertToBlob({ type: config.mimeType, quality: config.quality });
757
+ const pathSegments = filePath.split('/');
758
+ const fileName = pathSegments.pop();
759
+ if (!fileName) {
760
+ throw Error('Invalid file path: No file name provided.');
761
+ }
762
+ const newSegments = [
763
+ ...pathSegments,
764
+ width,
765
+ ];
766
+ const fileNameParts = fileName.split('.');
767
+ const newFileName = `${fileNameParts[0]}.webp`;
768
+ const newDirPath = newSegments.join('/');
769
+ const newFilePath = `${newDirPath}/${newFileName}`;
770
+ await saveBlobToOPFS(newFilePath, resizedBlob);
771
+ globalThis.postMessage({
772
+ done: true,
773
+ filePath: newFilePath,
774
+ });
775
+ };
776
+ onmessage = async (e) => {
777
+ const { filePath, width, height, debug } = e.data;
778
+ if (!debug) {
779
+ console.log = () => { };
780
+ }
781
+ try {
782
+ await imageResize(filePath, width, height);
783
+ }
784
+ catch (err) {
785
+ globalThis.postMessage({ error: err instanceof Error ? err.message : String(err) });
786
+ }
787
+ };
788
+ }.toString()}
789
+ )()`;
790
+
791
+ const logger$3 = debug('seedSdk:browser:workers:ImageResizer');
792
+ class ImageResizer {
793
+ constructor() {
794
+ this.workersArchive = new Map();
795
+ this.cores = Math.min(navigator.hardwareConcurrency || 4, 4);
796
+ this.workerBlobUrl = globalThis.URL.createObjectURL(new Blob([imageResize], { type: 'application/javascript' }));
797
+ }
798
+ async resize({ filePath, width, height }) {
799
+ if (this.workersArchive.has(filePath)) {
800
+ const savedWorker = this.workersArchive.get(filePath);
801
+ savedWorker?.terminate();
802
+ logger$3('[ImageResizer.resize] Terminated worker for filePath due to incoming request', filePath);
803
+ this.workersArchive.delete(filePath);
804
+ }
805
+ const worker = new Worker(this.workerBlobUrl);
806
+ this.workersArchive.set(filePath, worker);
807
+ return new Promise((resolve, reject) => {
808
+ worker.onmessage = (e) => {
809
+ logger$3('[ImageResizer.resize] main thread onmessage', e.data);
810
+ if (e.data.done) {
811
+ const savedWorker = this.workersArchive.get(filePath);
812
+ savedWorker?.terminate();
813
+ logger$3('[ImageResizer.resize] Terminated worker for filePath due to done', filePath);
814
+ this.workersArchive.delete(filePath);
815
+ resolve(e.data);
816
+ }
817
+ if (e.data.error) {
818
+ reject(e.data.error);
819
+ }
820
+ };
821
+ worker.onerror = (err) => {
822
+ reject(err);
823
+ };
824
+ worker.postMessage({
825
+ filePath,
826
+ width,
827
+ height,
828
+ debug: logger$3.enabled,
829
+ });
830
+ });
831
+ }
832
+ async resizeAll({ width, height }) {
833
+ const fs = await BaseFileManager.getFs();
834
+ const imageDir = BaseFileManager.getFilesPath('images');
835
+ let imageFilesStats = await fs.promises.readdir(imageDir, {
836
+ withFileTypes: true
837
+ });
838
+ imageFilesStats = imageFilesStats.filter((file) => file.isFile());
839
+ const imageFiles = imageFilesStats.map((file) => file.path);
840
+ const widthDir = `${imageDir}/${width}`;
841
+ await BaseFileManager.createDirIfNotExists(widthDir);
842
+ for (const imageFile of imageFiles) {
843
+ const resizedImageExists = await BaseFileManager.pathExists(`${widthDir}/${imageFile}`);
844
+ if (!resizedImageExists) {
845
+ await this.resize({ filePath: `${imageDir}/${imageFile}`, width, height });
846
+ }
847
+ }
848
+ }
849
+ }
850
+
851
+ const logger$2 = debug('seedSdk:browser:helpers:FileManager');
852
+ /**
853
+ * Browser-safe path helpers for SDK virtual file paths.
854
+ * We intentionally avoid Node/CJS path polyfills here to keep browser bundles ESM-safe.
855
+ * Provides the subset of Node path APIs used via BaseFileManager.getPathModule().
856
+ */
857
+ const pathCompat = {
858
+ dirname(filePath) {
859
+ if (!filePath)
860
+ return '.';
861
+ const normalized = filePath.replace(/\\/g, '/');
862
+ if (normalized === '/')
863
+ return '/';
864
+ const trimmed = normalized.endsWith('/') && normalized.length > 1
865
+ ? normalized.slice(0, -1)
866
+ : normalized;
867
+ const lastSlash = trimmed.lastIndexOf('/');
868
+ if (lastSlash === -1)
869
+ return '.';
870
+ if (lastSlash === 0)
871
+ return '/';
872
+ return trimmed.slice(0, lastSlash);
873
+ },
874
+ basename(filePath) {
875
+ if (!filePath)
876
+ return '';
877
+ const normalized = filePath.replace(/\\/g, '/');
878
+ if (normalized === '/')
879
+ return '/';
880
+ const trimmed = normalized.endsWith('/') && normalized.length > 1
881
+ ? normalized.slice(0, -1)
882
+ : normalized;
883
+ const lastSlash = trimmed.lastIndexOf('/');
884
+ return lastSlash === -1 ? trimmed : trimmed.slice(lastSlash + 1);
885
+ },
886
+ isAbsolute(filePath) {
887
+ if (!filePath)
888
+ return false;
889
+ const normalized = filePath.replace(/\\/g, '/');
890
+ return normalized.startsWith('/');
891
+ },
892
+ join(...segments) {
893
+ if (segments.length === 0)
894
+ return '.';
895
+ const joined = segments
896
+ .filter((s) => s != null && s !== '')
897
+ .map((s) => String(s).replace(/\\/g, '/'))
898
+ .join('/');
899
+ return pathCompat.normalize(joined);
900
+ },
901
+ resolve(...segments) {
902
+ // POSIX-like resolve for virtual paths: walk right-to-left until absolute.
903
+ let resolved = '';
904
+ let absolute = false;
905
+ for (let i = segments.length - 1; i >= 0 && !absolute; i--) {
906
+ const segment = segments[i];
907
+ if (segment == null || segment === '')
908
+ continue;
909
+ const normalized = String(segment).replace(/\\/g, '/');
910
+ resolved = resolved ? `${normalized}/${resolved}` : normalized;
911
+ absolute = pathCompat.isAbsolute(normalized);
912
+ }
913
+ // Browser has no process.cwd(); treat unresolved relative paths as root-relative.
914
+ if (!absolute) {
915
+ resolved = `/${resolved}`;
916
+ }
917
+ return pathCompat.normalize(resolved);
918
+ },
919
+ normalize(filePath) {
920
+ if (!filePath)
921
+ return '.';
922
+ const normalized = filePath.replace(/\\/g, '/');
923
+ const absolute = normalized.startsWith('/');
924
+ const parts = normalized.split('/');
925
+ const stack = [];
926
+ for (const part of parts) {
927
+ if (!part || part === '.')
928
+ continue;
929
+ if (part === '..') {
930
+ if (stack.length > 0 && stack[stack.length - 1] !== '..') {
931
+ stack.pop();
932
+ }
933
+ else if (!absolute) {
934
+ stack.push('..');
935
+ }
936
+ continue;
937
+ }
938
+ stack.push(part);
939
+ }
940
+ const result = stack.join('/');
941
+ if (absolute)
942
+ return `/${result}`;
943
+ return result || '.';
944
+ },
945
+ };
946
+ /** OPFS / ZenFS can throw NotReadableError while a file is still settling after write. */
947
+ function isTransientOpfsReadError(error) {
948
+ if (error instanceof DOMException && error.name === 'NotReadableError') {
949
+ return true;
950
+ }
951
+ const message = error instanceof Error ? error.message : String(error);
952
+ // Chromium wording when getFile/read races a writer or stale handle
953
+ if (message.includes('permission problems') && message.includes('reference')) {
954
+ return true;
955
+ }
956
+ return false;
957
+ }
958
+ function sleep(ms) {
959
+ return new Promise((resolve) => setTimeout(resolve, ms));
960
+ }
961
+ class BrowserFileManager {
962
+ constructor() {
963
+ this.zenfsCache = null;
964
+ }
965
+ async getFs() {
966
+ if (!this.zenfsCache) {
967
+ this.zenfsCache = await import('@zenfs/core');
968
+ }
969
+ return this.zenfsCache;
970
+ }
971
+ getFsSync() {
972
+ if (!this.zenfsCache) {
973
+ throw new Error('File system not initialized. Call getFs() or initializeFileSystem() first.');
974
+ }
975
+ return this.zenfsCache;
976
+ }
977
+ async getContentUrlFromPath(path) {
978
+ const fileExists = await this.pathExists(path);
979
+ if (fileExists) {
980
+ const file = await this.readFile(path);
981
+ return URL.createObjectURL(file);
982
+ }
983
+ }
984
+ async initializeFileSystem(workingDir) {
985
+ const zenfs = await this.getFs();
986
+ const zenfsDomMod = await import('@zenfs/dom');
987
+ const { WebAccess } = zenfsDomMod;
988
+ const { configureSingle } = zenfs;
989
+ const handle = await navigator.storage.getDirectory();
990
+ // await configure({
991
+ // mounts: {
992
+ // '/': {
993
+ // backend: WebAccess,
994
+ // handle,
995
+ // },
996
+ // },
997
+ // disableUpdateOnRead: true,
998
+ // onlySyncOnClose: true,
999
+ // })
1000
+ await configureSingle({
1001
+ backend: WebAccess,
1002
+ handle,
1003
+ });
1004
+ // Cache is already set in getFs(), so no need to set it again
1005
+ }
1006
+ async downloadAllFiles({ transactionIds, arweaveHost, excludedTransactions, }) {
1007
+ const fileDownloader = new FileDownloader();
1008
+ await fileDownloader.downloadAll({ transactionIds, arweaveHost, excludedTransactions });
1009
+ }
1010
+ async resizeImage({ filePath, width, height }) {
1011
+ const imageResizer = new ImageResizer();
1012
+ await imageResizer.resize({ filePath, width, height });
1013
+ }
1014
+ async resizeAllImages({ width, height }) {
1015
+ const imageResizer = new ImageResizer();
1016
+ await imageResizer.resizeAll({ width, height });
1017
+ }
1018
+ async listImageFiles() {
1019
+ return this.listFiles('images');
1020
+ }
1021
+ async listFiles(dir) {
1022
+ const targetDir = BaseFileManager.getFilesPath(dir);
1023
+ const exists = await this.pathExists(targetDir);
1024
+ if (!exists) {
1025
+ return [];
1026
+ }
1027
+ const zenfs = await this.getFs();
1028
+ const entries = await zenfs.promises.readdir(targetDir, { withFileTypes: true });
1029
+ return entries.filter((entry) => entry.isFile()).map((entry) => entry.name);
1030
+ }
1031
+ async pathExists(filePath) {
1032
+ try {
1033
+ const zenfs = await this.getFs();
1034
+ await zenfs.promises.access(filePath, zenfs.constants.F_OK);
1035
+ return true;
1036
+ }
1037
+ catch (error) {
1038
+ // ENOENT means the file doesn't exist, which is expected
1039
+ if (error?.code === 'ENOENT' || error?.errno === -2) {
1040
+ return false;
1041
+ }
1042
+ // For other errors, re-throw them
1043
+ throw error;
1044
+ }
1045
+ }
1046
+ async createDirIfNotExists(filePath) {
1047
+ if (!(await this.pathExists(filePath))) {
1048
+ try {
1049
+ const zenfs = await this.getFs();
1050
+ await zenfs.promises.mkdir(filePath, { recursive: true });
1051
+ }
1052
+ catch (error) {
1053
+ // This is a no-op. We tried to create a directory that already exists.
1054
+ logger$2('Attempted to create a directory that already exists');
1055
+ }
1056
+ }
1057
+ }
1058
+ /**
1059
+ * Waits for a file to exist at the specified path.
1060
+ * @param {string} filePath - The path of the file to check.
1061
+ * @param {number} interval - The interval in milliseconds between checks (default: 500ms).
1062
+ * @param {number} timeout - The timeout in milliseconds to wait for the file to exist (default: 10s).
1063
+ * @returns {Promise<boolean>} - Resolves to true if the file exists within the timeout period, otherwise false.
1064
+ */
1065
+ async waitForFile(filePath, interval = 1000, timeout = 60000) {
1066
+ // const fs = await this.getFs()
1067
+ // const fsNode = await import('node:fs')
1068
+ const pathExists = await this.pathExists(filePath);
1069
+ if (pathExists) {
1070
+ return true;
1071
+ }
1072
+ return new Promise((resolve, reject) => {
1073
+ const startTime = Date.now();
1074
+ let isBusy = false;
1075
+ const cancelableInterval = new CancelableInterval(async (stop) => {
1076
+ logger$2('waitForFile', filePath);
1077
+ if (isBusy) {
1078
+ return;
1079
+ }
1080
+ isBusy = true;
1081
+ // // TODO: Needs to read from OPFS
1082
+ // const exists = await BaseFileManager.pathExists(filePath)
1083
+ // if (exists) {
1084
+ // stop()
1085
+ // resolve(true)
1086
+ // }
1087
+ const pathExists = await this.pathExists(filePath);
1088
+ if (pathExists) {
1089
+ stop();
1090
+ resolve(true);
1091
+ }
1092
+ if (Date.now() - startTime >= timeout) {
1093
+ stop();
1094
+ reject(new Error('Timeout exceeded while waiting for file'));
1095
+ }
1096
+ isBusy = false;
1097
+ }, interval);
1098
+ cancelableInterval.start();
1099
+ // const _interval = setInterval(async () => {
1100
+ // logger('waitForFile', filePath)
1101
+ // if (isBusy) {
1102
+ // return
1103
+ // }
1104
+ // isBusy = true
1105
+ // // TODO: Needs to read from OPFS
1106
+ // if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
1107
+ // clearInterval(_interval)
1108
+ // resolve(true)
1109
+ // }
1110
+ // const pathExists = await this.pathExists(filePath)
1111
+ // if (pathExists) {
1112
+ // clearInterval(_interval)
1113
+ // resolve(true)
1114
+ // }
1115
+ // if (Date.now() - startTime >= timeout) {
1116
+ // clearInterval(_interval)
1117
+ // reject(new Error('Timeout exceeded while waiting for file'))
1118
+ // }
1119
+ // isBusy = false
1120
+ // }, interval)
1121
+ // retry(
1122
+ // {
1123
+ // times: Math.ceil(timeout / interval),
1124
+ // interval: interval,
1125
+ // },
1126
+ // (callback: Function) => {
1127
+ // if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
1128
+ // return callback(null, true) // File exists, finish with success
1129
+ // }
1130
+ // if (Date.now() - startTime >= timeout) {
1131
+ // return callback(new Error('Timeout exceeded while waiting for file'))
1132
+ // }
1133
+ // callback(new Error('File does not exist yet')) // Retry with this error
1134
+ // },
1135
+ // (err: Error, result: boolean) => {
1136
+ // if (err) {
1137
+ // return resolve(false) // Resolve as false if timeout or error occurs
1138
+ // }
1139
+ // resolve(result) // Resolve as true if file exists
1140
+ // },
1141
+ // )
1142
+ });
1143
+ }
1144
+ /**
1145
+ * Waits for a file to exist and have content (non-zero size).
1146
+ * This is important for browser/OPFS where writes may not be immediately readable.
1147
+ * @param {string} filePath - The path of the file to check.
1148
+ * @param {number} interval - The interval in milliseconds between checks (default: 100ms).
1149
+ * @param {number} timeout - The timeout in milliseconds to wait (default: 5s).
1150
+ * @returns {Promise<boolean>} - Resolves to true if the file exists with content within the timeout period.
1151
+ */
1152
+ async waitForFileWithContent(filePath, interval = 100, timeout = 5000) {
1153
+ // First wait for file to exist
1154
+ await this.waitForFile(filePath, interval, timeout);
1155
+ // Now wait for file to have content
1156
+ return new Promise((resolve, reject) => {
1157
+ const startTime = Date.now();
1158
+ let isBusy = false;
1159
+ const cancelableInterval = new CancelableInterval(async (stop) => {
1160
+ logger$2('waitForFileWithContent', filePath);
1161
+ if (isBusy) {
1162
+ return;
1163
+ }
1164
+ isBusy = true;
1165
+ try {
1166
+ // Try to read the file to check if it has content
1167
+ const file = await this.readFile(filePath);
1168
+ if (file.size > 0) {
1169
+ stop();
1170
+ resolve(true);
1171
+ return;
1172
+ }
1173
+ // File exists but is 0 bytes, continue waiting
1174
+ }
1175
+ catch (error) {
1176
+ // If error is about file being 0 bytes, not readable, or I/O error, continue waiting
1177
+ const errorMessage = error?.message || String(error);
1178
+ if (errorMessage.includes('0 bytes') ||
1179
+ errorMessage.includes('ENOENT') ||
1180
+ errorMessage.includes('EIO') ||
1181
+ errorMessage.includes('Input/output error') ||
1182
+ isTransientOpfsReadError(error)) ;
1183
+ else {
1184
+ // Other errors should be thrown
1185
+ stop();
1186
+ reject(error);
1187
+ return;
1188
+ }
1189
+ }
1190
+ if (Date.now() - startTime >= timeout) {
1191
+ stop();
1192
+ reject(new Error(`Timeout exceeded while waiting for file ${filePath} to have content`));
1193
+ return;
1194
+ }
1195
+ isBusy = false;
1196
+ }, interval);
1197
+ cancelableInterval.start();
1198
+ });
1199
+ }
1200
+ async saveFile(filePath, content) {
1201
+ const zenfs = await this.getFs();
1202
+ // Convert content to a format that zenfs.writeFile accepts
1203
+ let writeContent;
1204
+ if (typeof content === 'string') {
1205
+ writeContent = content;
1206
+ }
1207
+ else if (content instanceof Blob) {
1208
+ const arrayBuffer = await content.arrayBuffer();
1209
+ writeContent = new Uint8Array(arrayBuffer);
1210
+ }
1211
+ else if (content instanceof ArrayBuffer) {
1212
+ writeContent = new Uint8Array(content);
1213
+ }
1214
+ else {
1215
+ throw new Error('Unsupported content type');
1216
+ }
1217
+ await zenfs.writeFile(filePath, writeContent);
1218
+ await this.waitForFileWithContent(filePath, 100, 5000);
1219
+ // try {
1220
+ // // Get a handle to the OPFS root directory
1221
+ // const root = await navigator.storage.getDirectory();
1222
+ // // Split the file path into directory and file name
1223
+ // const pathParts = filePath.split('/');
1224
+ // const fileName = pathParts.pop();
1225
+ // if (!fileName) throw new Error('Invalid file path');
1226
+ // // Traverse directories and create them if they don't exist
1227
+ // let currentDir = root;
1228
+ // for (const part of pathParts) {
1229
+ // if (part !== '') {
1230
+ // currentDir = await currentDir.getDirectoryHandle(part, { create: true });
1231
+ // }
1232
+ // }
1233
+ // // Get the file handle and create the file if it doesn't exist
1234
+ // const fileHandle = await currentDir.getFileHandle(fileName, { create: true });
1235
+ // // Create a writable stream and write the content
1236
+ // const writable = await fileHandle.createWritable();
1237
+ // if (typeof content === 'string' || content instanceof Uint8Array) {
1238
+ // await writable.write(content);
1239
+ // } else if (content instanceof Blob) {
1240
+ // await writable.write(content);
1241
+ // } else if (content instanceof ArrayBuffer) {
1242
+ // await writable.write(new Blob([content]));
1243
+ // } else {
1244
+ // throw new Error('Unsupported content type');
1245
+ // }
1246
+ // await writable.close();
1247
+ // logger(`File written successfully: ${filePath}`);
1248
+ // } catch (error) {
1249
+ // console.error(`Error writing to OPFS: ${error.message}`);
1250
+ // }
1251
+ }
1252
+ saveFileSync(filePath, content) {
1253
+ // Note: This is a synchronous wrapper, but zenfs operations may still be async under the hood
1254
+ // For true sync operations in browser, we'd need to use OPFS sync access handles
1255
+ // For now, we'll use zenfs.writeFileSync which should be available
1256
+ const zenfs = this.getFsSync();
1257
+ // Convert content to a format that zenfs.writeFileSync accepts
1258
+ let writeContent;
1259
+ if (typeof content === 'string') {
1260
+ writeContent = content;
1261
+ }
1262
+ else if (content instanceof Blob) {
1263
+ // Blob cannot be converted synchronously - throw error
1264
+ throw new Error('Blob content not supported in saveFileSync. Use saveFile() instead or convert to ArrayBuffer first.');
1265
+ }
1266
+ else if (content instanceof ArrayBuffer) {
1267
+ writeContent = new Uint8Array(content);
1268
+ }
1269
+ else {
1270
+ throw new Error('Unsupported content type');
1271
+ }
1272
+ zenfs.writeFileSync(filePath, writeContent);
1273
+ }
1274
+ async readFile(filePath) {
1275
+ const zenfs = await this.getFs();
1276
+ const maxAttempts = 3;
1277
+ const baseDelayMs = 50;
1278
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
1279
+ try {
1280
+ const data = await zenfs.promises.readFile(filePath);
1281
+ return new File([new Uint8Array(data)], filePath);
1282
+ }
1283
+ catch (error) {
1284
+ if (!isTransientOpfsReadError(error) || attempt === maxAttempts - 1) {
1285
+ throw error;
1286
+ }
1287
+ await sleep(baseDelayMs * (attempt + 1));
1288
+ }
1289
+ }
1290
+ throw new Error('readFile: exhausted retries');
1291
+ // try {
1292
+ // // Get a handle to the OPFS root directory
1293
+ // const root = await navigator.storage.getDirectory();
1294
+ // // Split the file path into directory and file name
1295
+ // const pathParts = filePath.split('/');
1296
+ // const fileName = pathParts.pop();
1297
+ // if (!fileName) throw new Error('Invalid file path');
1298
+ // // Traverse directories to reach the target file
1299
+ // let currentDir = root;
1300
+ // for (const part of pathParts) {
1301
+ // if (part !== '') {
1302
+ // currentDir = await currentDir.getDirectoryHandle(part, { create: false });
1303
+ // }
1304
+ // }
1305
+ // // Get the file handle
1306
+ // const fileHandle = await currentDir.getFileHandle(fileName, { create: false });
1307
+ // // Get the file and read it as an ArrayBuffer
1308
+ // return await fileHandle.getFile();
1309
+ // } catch (error) {
1310
+ // console.error(`Error reading from OPFS: ${error.message}`);
1311
+ // throw error;
1312
+ // }
1313
+ }
1314
+ readFileSync(filePath) {
1315
+ // Note: This is a synchronous wrapper, but zenfs operations may still be async under the hood
1316
+ // For true sync operations in browser, we'd need to use OPFS sync access handles
1317
+ // For now, we'll use zenfs.readFileSync which should be available
1318
+ const zenfs = this.getFsSync();
1319
+ const file = zenfs.readFileSync(filePath);
1320
+ return new File([new Uint8Array(file)], filePath);
1321
+ }
1322
+ async readFileAsBuffer(filePath) {
1323
+ try {
1324
+ // Get the file and read it as an ArrayBuffer
1325
+ const file = await this.readFile(filePath);
1326
+ const arrayBuffer = await file.arrayBuffer();
1327
+ // Convert ArrayBuffer to Blob
1328
+ return new Blob([arrayBuffer]);
1329
+ }
1330
+ catch (error) {
1331
+ const errorMessage = error instanceof Error ? error.message : String(error);
1332
+ console.error(`Error reading from OPFS: ${errorMessage}`);
1333
+ throw error;
1334
+ }
1335
+ }
1336
+ async readFileAsString(filePath) {
1337
+ const blob = await this.readFileAsBuffer(filePath);
1338
+ return blob.text();
1339
+ }
1340
+ getParentDirPath(filePath) {
1341
+ return pathCompat.dirname(filePath);
1342
+ }
1343
+ getFilenameFromPath(filePath) {
1344
+ return pathCompat.basename(filePath);
1345
+ }
1346
+ getPathModule() {
1347
+ return pathCompat;
1348
+ }
1349
+ }
1350
+ class CancelableInterval {
1351
+ constructor(task, interval) {
1352
+ this.task = task;
1353
+ this.interval = interval;
1354
+ this.intervalId = null;
1355
+ this.currentTaskAbortController = null;
1356
+ }
1357
+ start() {
1358
+ this.intervalId = window.setInterval(async () => {
1359
+ if (this.currentTaskAbortController) {
1360
+ // Cancel the previous running task
1361
+ this.currentTaskAbortController.abort();
1362
+ }
1363
+ // Create a new abort controller for the current task
1364
+ this.currentTaskAbortController = new AbortController();
1365
+ const signal = this.currentTaskAbortController.signal;
1366
+ try {
1367
+ await this.taskWithCancellation(signal);
1368
+ }
1369
+ catch (error) {
1370
+ if (error instanceof DOMException && error.name === 'AbortError') {
1371
+ logger$2('Previous task was canceled.');
1372
+ }
1373
+ else {
1374
+ console.error('Task error:', error);
1375
+ }
1376
+ this.stop();
1377
+ }
1378
+ }, this.interval);
1379
+ }
1380
+ async taskWithCancellation(signal) {
1381
+ await this.task(() => this.stop());
1382
+ if (signal.aborted) {
1383
+ throw new DOMException('Task was aborted', 'AbortError');
1384
+ }
1385
+ }
1386
+ stop() {
1387
+ if (this.intervalId !== null) {
1388
+ clearInterval(this.intervalId);
1389
+ this.intervalId = null;
1390
+ }
1391
+ if (this.currentTaskAbortController) {
1392
+ this.currentTaskAbortController.abort();
1393
+ }
1394
+ }
1395
+ }
1396
+ BaseFileManager.configure(new BrowserFileManager());
1397
+
1398
+ // This file embeds the drizzle migration files as strings for browser runtime
1399
+ // These files are copied from packages/sdk/src/db/drizzle at build time
1400
+ // Individual migration SQL files
1401
+ const migrationSql_0000_married_malice = `CREATE TABLE \`appState\` (
1402
+ \`key\` text,
1403
+ \`value\` text,
1404
+ \`created_at\` integer,
1405
+ \`updated_at\` integer
1406
+ );
1407
+ --> statement-breakpoint
1408
+ CREATE UNIQUE INDEX \`appState_key_unique\` ON \`appState\` (\`key\`);--> statement-breakpoint
1409
+ CREATE TABLE \`config\` (
1410
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1411
+ \`key\` text NOT NULL,
1412
+ \`text\` text,
1413
+ \`json\` text,
1414
+ \`blob\` blob
1415
+ );
1416
+ --> statement-breakpoint
1417
+ CREATE TABLE \`metadata\` (
1418
+ \`local_id\` text,
1419
+ \`uid\` text,
1420
+ \`property_name\` text,
1421
+ \`property_value\` text,
1422
+ \`schema_uid\` text,
1423
+ \`model_type\` text,
1424
+ \`seed_local_id\` text,
1425
+ \`seed_uid\` text,
1426
+ \`version_local_id\` text,
1427
+ \`version_uid\` text,
1428
+ \`eas_data_type\` text,
1429
+ \`ref_value_type\` text,
1430
+ \`ref_schema_uid\` text,
1431
+ \`ref_seed_type\` text,
1432
+ \`ref_resolved_value\` text,
1433
+ \`ref_resolved_display_value\` text,
1434
+ \`local_storage_dir\` text,
1435
+ \`attestation_raw\` text,
1436
+ \`attestation_created_at\` integer,
1437
+ \`content_hash\` text,
1438
+ \`created_at\` integer,
1439
+ \`updated_at\` integer
1440
+ );
1441
+ --> statement-breakpoint
1442
+ CREATE UNIQUE INDEX \`metadata_local_id_unique\` ON \`metadata\` (\`local_id\`);--> statement-breakpoint
1443
+ CREATE TABLE \`models\` (
1444
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1445
+ \`name\` text NOT NULL,
1446
+ \`schema_file_id\` text
1447
+ );
1448
+ --> statement-breakpoint
1449
+ CREATE TABLE \`properties\` (
1450
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1451
+ \`name\` text NOT NULL,
1452
+ \`data_type\` text NOT NULL,
1453
+ \`model_id\` integer NOT NULL,
1454
+ \`ref_model_id\` integer,
1455
+ \`ref_value_type\` text,
1456
+ \`schema_file_id\` text,
1457
+ FOREIGN KEY (\`model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action,
1458
+ FOREIGN KEY (\`ref_model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action
1459
+ );
1460
+ --> statement-breakpoint
1461
+ CREATE UNIQUE INDEX \`unique_name_model_id\` ON \`properties\` (\`name\`,\`model_id\`);--> statement-breakpoint
1462
+ CREATE TABLE \`model_schemas\` (
1463
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1464
+ \`model_id\` integer,
1465
+ \`schema_id\` integer,
1466
+ FOREIGN KEY (\`model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action,
1467
+ FOREIGN KEY (\`schema_id\`) REFERENCES \`schemas\`(\`id\`) ON UPDATE no action ON DELETE no action
1468
+ );
1469
+ --> statement-breakpoint
1470
+ CREATE TABLE \`model_uids\` (
1471
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1472
+ \`uid\` text NOT NULL,
1473
+ \`model_id\` integer NOT NULL,
1474
+ FOREIGN KEY (\`model_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action
1475
+ );
1476
+ --> statement-breakpoint
1477
+ CREATE UNIQUE INDEX \`model_uids_model_id_unique\` ON \`model_uids\` (\`model_id\`);--> statement-breakpoint
1478
+ CREATE TABLE \`property_uids\` (
1479
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1480
+ \`uid\` text NOT NULL,
1481
+ \`property_id\` integer NOT NULL,
1482
+ FOREIGN KEY (\`property_id\`) REFERENCES \`models\`(\`id\`) ON UPDATE no action ON DELETE no action
1483
+ );
1484
+ --> statement-breakpoint
1485
+ CREATE UNIQUE INDEX \`property_uids_property_id_unique\` ON \`property_uids\` (\`property_id\`);--> statement-breakpoint
1486
+ CREATE TABLE \`schemas\` (
1487
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1488
+ \`name\` text NOT NULL,
1489
+ \`version\` integer NOT NULL,
1490
+ \`schema_file_id\` text,
1491
+ \`created_at\` integer,
1492
+ \`updated_at\` integer
1493
+ );
1494
+ --> statement-breakpoint
1495
+ CREATE TABLE \`seeds\` (
1496
+ \`local_id\` text,
1497
+ \`uid\` text,
1498
+ \`schema_uid\` text,
1499
+ \`type\` text,
1500
+ \`attestation_raw\` text,
1501
+ \`attestation_created_at\` integer,
1502
+ \`created_at\` integer,
1503
+ \`updated_at\` integer,
1504
+ \`_marked_for_deletion\` integer
1505
+ );
1506
+ --> statement-breakpoint
1507
+ CREATE UNIQUE INDEX \`seeds_local_id_unique\` ON \`seeds\` (\`local_id\`);--> statement-breakpoint
1508
+ CREATE TABLE \`versions\` (
1509
+ \`local_id\` text,
1510
+ \`uid\` text,
1511
+ \`seed_local_id\` text,
1512
+ \`seed_uid\` text,
1513
+ \`seed_type\` text,
1514
+ \`note\` text,
1515
+ \`created_at\` integer,
1516
+ \`updated_at\` integer,
1517
+ \`attestation_created_at\` integer,
1518
+ \`attestation_raw\` text
1519
+ );
1520
+ --> statement-breakpoint
1521
+ CREATE UNIQUE INDEX \`versions_local_id_unique\` ON \`versions\` (\`local_id\`);`;
1522
+ const migrationSql_0001_sweet_bruce_banner = `ALTER TABLE \`schemas\` ADD \`schema_data\` text;--> statement-breakpoint
1523
+ ALTER TABLE \`schemas\` ADD \`is_draft\` integer;`;
1524
+ const migrationSql_0002_bitter_proudstar = `CREATE UNIQUE INDEX \`unique_schema_file_id\` ON \`models\` (\`schema_file_id\`);--> statement-breakpoint
1525
+ CREATE UNIQUE INDEX \`unique_property_schema_file_id\` ON \`properties\` (\`schema_file_id\`);--> statement-breakpoint
1526
+ CREATE UNIQUE INDEX \`unique_schema_schema_file_id\` ON \`schemas\` (\`schema_file_id\`);`;
1527
+ const migrationSql_0003_cultured_senator_kelly = `ALTER TABLE \`models\` ADD \`is_edited\` integer;--> statement-breakpoint
1528
+ ALTER TABLE \`properties\` ADD \`is_edited\` integer;--> statement-breakpoint
1529
+ ALTER TABLE \`schemas\` ADD \`is_edited\` integer;`;
1530
+ const migrationSql_0004_add_publisher_to_seeds = `ALTER TABLE \`seeds\` ADD \`publisher\` text;`;
1531
+ const migrationSql_0005_bright_lily_hollister = `CREATE TABLE \`publish_processes\` (
1532
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1533
+ \`seed_local_id\` text NOT NULL,
1534
+ \`model_name\` text NOT NULL,
1535
+ \`schema_id\` text,
1536
+ \`status\` text NOT NULL,
1537
+ \`started_at\` integer NOT NULL,
1538
+ \`completed_at\` integer,
1539
+ \`error_message\` text,
1540
+ \`error_step\` text,
1541
+ \`error_details\` text,
1542
+ \`persisted_snapshot\` text NOT NULL,
1543
+ \`seed_id\` text,
1544
+ \`existing_seed_uid\` text,
1545
+ \`created_at\` integer,
1546
+ \`updated_at\` integer
1547
+ );
1548
+ --> statement-breakpoint
1549
+ CREATE TABLE \`upload_processes\` (
1550
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1551
+ \`reimbursement_confirmed\` integer NOT NULL,
1552
+ \`reimbursement_transaction_id\` text,
1553
+ \`transaction_keys\` text,
1554
+ \`persisted_snapshot\` text NOT NULL,
1555
+ \`created_at\` integer,
1556
+ \`updated_at\` integer
1557
+ );
1558
+ `;
1559
+ const migrationSql_0006_add_publisher_to_versions_and_metadata = `ALTER TABLE \`versions\` ADD \`publisher\` text;
1560
+ --> statement-breakpoint
1561
+ ALTER TABLE \`metadata\` ADD \`publisher\` text;
1562
+ `;
1563
+ const migrationSql_0007_add_required_to_properties = `ALTER TABLE \`properties\` ADD \`required\` integer DEFAULT 0;
1564
+ `;
1565
+ const migrationSql_0008_add_revoked_at_to_seeds = `ALTER TABLE \`seeds\` ADD \`revoked_at\` integer;
1566
+ `;
1567
+ const migrationSql_0009_happy_namor = `PRAGMA foreign_keys=OFF;--> statement-breakpoint
1568
+ CREATE TABLE \`__new_property_uids\` (
1569
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1570
+ \`uid\` text NOT NULL,
1571
+ \`property_id\` integer NOT NULL,
1572
+ FOREIGN KEY (\`property_id\`) REFERENCES \`properties\`(\`id\`) ON UPDATE no action ON DELETE no action
1573
+ );
1574
+ --> statement-breakpoint
1575
+ INSERT INTO \`__new_property_uids\`("id", "uid", "property_id") SELECT "id", "uid", "property_id" FROM \`property_uids\`;--> statement-breakpoint
1576
+ DROP TABLE \`property_uids\`;--> statement-breakpoint
1577
+ ALTER TABLE \`__new_property_uids\` RENAME TO \`property_uids\`;--> statement-breakpoint
1578
+ PRAGMA foreign_keys=ON;--> statement-breakpoint
1579
+ CREATE UNIQUE INDEX \`property_uids_property_id_unique\` ON \`property_uids\` (\`property_id\`);--> statement-breakpoint
1580
+ ALTER TABLE \`metadata\` ADD \`property_id\` integer REFERENCES properties(id);`;
1581
+ const migrationSql_0010_add_arweave_l1_finalize_jobs = `CREATE TABLE \`arweave_l1_finalize_jobs\` (
1582
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1583
+ \`seed_local_id\` text NOT NULL,
1584
+ \`data_item_id\` text NOT NULL,
1585
+ \`l1_transaction_id\` text,
1586
+ \`bundle_id\` text,
1587
+ \`version_local_id\` text,
1588
+ \`item_property_name\` text,
1589
+ \`phase\` text NOT NULL,
1590
+ \`status_json\` text,
1591
+ \`error_message\` text,
1592
+ \`created_at\` integer NOT NULL,
1593
+ \`updated_at\` integer NOT NULL
1594
+ );
1595
+ --> statement-breakpoint
1596
+ CREATE UNIQUE INDEX \`arweave_l1_finalize_jobs_data_item_id_unique\` ON \`arweave_l1_finalize_jobs\` (\`data_item_id\`);
1597
+ `;
1598
+ const migrationSql_0011_normalize_placeholder_uids = `UPDATE \`versions\` SET \`uid\` = NULL WHERE \`uid\` = 'NULL';
1599
+ --> statement-breakpoint
1600
+ UPDATE \`versions\` SET \`seed_uid\` = NULL WHERE \`seed_uid\` = 'NULL';
1601
+ --> statement-breakpoint
1602
+ UPDATE \`metadata\` SET \`uid\` = NULL WHERE \`uid\` = 'NULL';
1603
+ --> statement-breakpoint
1604
+ UPDATE \`metadata\` SET \`version_uid\` = NULL WHERE \`version_uid\` = 'NULL';
1605
+ --> statement-breakpoint
1606
+ UPDATE \`seeds\` SET \`uid\` = NULL WHERE \`uid\` = 'NULL';
1607
+ `;
1608
+ const migrationSql_0012_html_embedded_image_co_publish = `CREATE TABLE \`html_embedded_image_co_publish\` (
1609
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1610
+ \`parent_seed_local_id\` text NOT NULL,
1611
+ \`html_seed_local_id\` text NOT NULL,
1612
+ \`image_seed_local_id\` text NOT NULL,
1613
+ \`stable_key\` text NOT NULL,
1614
+ \`created_at\` integer NOT NULL
1615
+ );
1616
+ --> statement-breakpoint
1617
+ CREATE UNIQUE INDEX \`html_embed_co_pub_parent_html_stable\` ON \`html_embedded_image_co_publish\` (\`parent_seed_local_id\`,\`html_seed_local_id\`,\`stable_key\`);
1618
+ `;
1619
+ const migrationSql_0013_eas_sync_processes = `CREATE TABLE \`eas_sync_processes\` (
1620
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1621
+ \`status\` text NOT NULL,
1622
+ \`started_at\` integer NOT NULL,
1623
+ \`completed_at\` integer,
1624
+ \`request_payload\` text NOT NULL,
1625
+ \`error_message\` text,
1626
+ \`error_details\` text,
1627
+ \`persisted_snapshot\` text NOT NULL,
1628
+ \`created_at\` integer,
1629
+ \`updated_at\` integer
1630
+ );
1631
+ `;
1632
+ // Journal JSON file
1633
+ const journalJson = `{
1634
+ "version": "7",
1635
+ "dialect": "sqlite",
1636
+ "entries": [
1637
+ {
1638
+ "idx": 0,
1639
+ "version": "6",
1640
+ "when": 1765976502903,
1641
+ "tag": "0000_married_malice",
1642
+ "breakpoints": true
1643
+ },
1644
+ {
1645
+ "idx": 1,
1646
+ "version": "6",
1647
+ "when": 1766010851770,
1648
+ "tag": "0001_sweet_bruce_banner",
1649
+ "breakpoints": true
1650
+ },
1651
+ {
1652
+ "idx": 2,
1653
+ "version": "6",
1654
+ "when": 1767621120087,
1655
+ "tag": "0002_bitter_proudstar",
1656
+ "breakpoints": true
1657
+ },
1658
+ {
1659
+ "idx": 3,
1660
+ "version": "6",
1661
+ "when": 1768415440282,
1662
+ "tag": "0003_cultured_senator_kelly",
1663
+ "breakpoints": true
1664
+ },
1665
+ {
1666
+ "idx": 4,
1667
+ "version": "6",
1668
+ "when": 1768500000000,
1669
+ "tag": "0004_add_publisher_to_seeds",
1670
+ "breakpoints": true
1671
+ },
1672
+ {
1673
+ "idx": 5,
1674
+ "version": "6",
1675
+ "when": 1772489937031,
1676
+ "tag": "0005_bright_lily_hollister",
1677
+ "breakpoints": true
1678
+ },
1679
+ {
1680
+ "idx": 6,
1681
+ "version": "6",
1682
+ "when": 1772600000000,
1683
+ "tag": "0006_add_publisher_to_versions_and_metadata",
1684
+ "breakpoints": true
1685
+ },
1686
+ {
1687
+ "idx": 7,
1688
+ "version": "6",
1689
+ "when": 1772700000000,
1690
+ "tag": "0007_add_required_to_properties",
1691
+ "breakpoints": true
1692
+ },
1693
+ {
1694
+ "idx": 8,
1695
+ "version": "6",
1696
+ "when": 1772800000000,
1697
+ "tag": "0008_add_revoked_at_to_seeds",
1698
+ "breakpoints": true
1699
+ },
1700
+ {
1701
+ "idx": 9,
1702
+ "version": "6",
1703
+ "when": 1773924021107,
1704
+ "tag": "0009_happy_namor",
1705
+ "breakpoints": true
1706
+ },
1707
+ {
1708
+ "idx": 10,
1709
+ "version": "6",
1710
+ "when": 1774000000000,
1711
+ "tag": "0010_add_arweave_l1_finalize_jobs",
1712
+ "breakpoints": true
1713
+ },
1714
+ {
1715
+ "idx": 11,
1716
+ "version": "6",
1717
+ "when": 1774100000000,
1718
+ "tag": "0011_normalize_placeholder_uids",
1719
+ "breakpoints": true
1720
+ },
1721
+ {
1722
+ "idx": 12,
1723
+ "version": "6",
1724
+ "when": 1774200000000,
1725
+ "tag": "0012_html_embedded_image_co_publish",
1726
+ "breakpoints": true
1727
+ },
1728
+ {
1729
+ "idx": 13,
1730
+ "version": "6",
1731
+ "when": 1774300000000,
1732
+ "tag": "0013_eas_sync_processes",
1733
+ "breakpoints": true
1734
+ }
1735
+ ]
1736
+ }`;
1737
+ // Snapshot JSON file - this is large, so we'll import it dynamically if needed
1738
+ // For now, we'll read it from the actual file if ?raw works, otherwise we'll need to embed it
1739
+ const snapshotJson = `{
1740
+ "version": "6",
1741
+ "dialect": "sqlite",
1742
+ "id": "a9e8f7d6-c5b4-4321-a0b9-c8d7e6f5a4b3",
1743
+ "prevId": "ff2318d5-236f-4157-82ae-10ccb44c0e0c",
1744
+ "tables": {
1745
+ "appState": {
1746
+ "name": "appState",
1747
+ "columns": {
1748
+ "key": {
1749
+ "name": "key",
1750
+ "type": "text",
1751
+ "primaryKey": false,
1752
+ "notNull": false,
1753
+ "autoincrement": false
1754
+ },
1755
+ "value": {
1756
+ "name": "value",
1757
+ "type": "text",
1758
+ "primaryKey": false,
1759
+ "notNull": false,
1760
+ "autoincrement": false
1761
+ },
1762
+ "created_at": {
1763
+ "name": "created_at",
1764
+ "type": "integer",
1765
+ "primaryKey": false,
1766
+ "notNull": false,
1767
+ "autoincrement": false
1768
+ },
1769
+ "updated_at": {
1770
+ "name": "updated_at",
1771
+ "type": "integer",
1772
+ "primaryKey": false,
1773
+ "notNull": false,
1774
+ "autoincrement": false
1775
+ }
1776
+ },
1777
+ "indexes": {
1778
+ "appState_key_unique": {
1779
+ "name": "appState_key_unique",
1780
+ "columns": [
1781
+ "key"
1782
+ ],
1783
+ "isUnique": true
1784
+ }
1785
+ },
1786
+ "foreignKeys": {},
1787
+ "compositePrimaryKeys": {},
1788
+ "uniqueConstraints": {},
1789
+ "checkConstraints": {}
1790
+ },
1791
+ "config": {
1792
+ "name": "config",
1793
+ "columns": {
1794
+ "id": {
1795
+ "name": "id",
1796
+ "type": "integer",
1797
+ "primaryKey": true,
1798
+ "notNull": true,
1799
+ "autoincrement": true
1800
+ },
1801
+ "key": {
1802
+ "name": "key",
1803
+ "type": "text",
1804
+ "primaryKey": false,
1805
+ "notNull": true,
1806
+ "autoincrement": false
1807
+ },
1808
+ "text": {
1809
+ "name": "text",
1810
+ "type": "text",
1811
+ "primaryKey": false,
1812
+ "notNull": false,
1813
+ "autoincrement": false
1814
+ },
1815
+ "json": {
1816
+ "name": "json",
1817
+ "type": "text",
1818
+ "primaryKey": false,
1819
+ "notNull": false,
1820
+ "autoincrement": false
1821
+ },
1822
+ "blob": {
1823
+ "name": "blob",
1824
+ "type": "blob",
1825
+ "primaryKey": false,
1826
+ "notNull": false,
1827
+ "autoincrement": false
1828
+ }
1829
+ },
1830
+ "indexes": {},
1831
+ "foreignKeys": {},
1832
+ "compositePrimaryKeys": {},
1833
+ "uniqueConstraints": {},
1834
+ "checkConstraints": {}
1835
+ },
1836
+ "metadata": {
1837
+ "name": "metadata",
1838
+ "columns": {
1839
+ "local_id": {
1840
+ "name": "local_id",
1841
+ "type": "text",
1842
+ "primaryKey": false,
1843
+ "notNull": false,
1844
+ "autoincrement": false
1845
+ },
1846
+ "uid": {
1847
+ "name": "uid",
1848
+ "type": "text",
1849
+ "primaryKey": false,
1850
+ "notNull": false,
1851
+ "autoincrement": false
1852
+ },
1853
+ "property_id": {
1854
+ "name": "property_id",
1855
+ "type": "integer",
1856
+ "primaryKey": false,
1857
+ "notNull": false,
1858
+ "autoincrement": false
1859
+ },
1860
+ "property_name": {
1861
+ "name": "property_name",
1862
+ "type": "text",
1863
+ "primaryKey": false,
1864
+ "notNull": false,
1865
+ "autoincrement": false
1866
+ },
1867
+ "property_value": {
1868
+ "name": "property_value",
1869
+ "type": "text",
1870
+ "primaryKey": false,
1871
+ "notNull": false,
1872
+ "autoincrement": false
1873
+ },
1874
+ "schema_uid": {
1875
+ "name": "schema_uid",
1876
+ "type": "text",
1877
+ "primaryKey": false,
1878
+ "notNull": false,
1879
+ "autoincrement": false
1880
+ },
1881
+ "model_type": {
1882
+ "name": "model_type",
1883
+ "type": "text",
1884
+ "primaryKey": false,
1885
+ "notNull": false,
1886
+ "autoincrement": false
1887
+ },
1888
+ "seed_local_id": {
1889
+ "name": "seed_local_id",
1890
+ "type": "text",
1891
+ "primaryKey": false,
1892
+ "notNull": false,
1893
+ "autoincrement": false
1894
+ },
1895
+ "seed_uid": {
1896
+ "name": "seed_uid",
1897
+ "type": "text",
1898
+ "primaryKey": false,
1899
+ "notNull": false,
1900
+ "autoincrement": false
1901
+ },
1902
+ "version_local_id": {
1903
+ "name": "version_local_id",
1904
+ "type": "text",
1905
+ "primaryKey": false,
1906
+ "notNull": false,
1907
+ "autoincrement": false
1908
+ },
1909
+ "version_uid": {
1910
+ "name": "version_uid",
1911
+ "type": "text",
1912
+ "primaryKey": false,
1913
+ "notNull": false,
1914
+ "autoincrement": false
1915
+ },
1916
+ "eas_data_type": {
1917
+ "name": "eas_data_type",
1918
+ "type": "text",
1919
+ "primaryKey": false,
1920
+ "notNull": false,
1921
+ "autoincrement": false
1922
+ },
1923
+ "ref_value_type": {
1924
+ "name": "ref_value_type",
1925
+ "type": "text",
1926
+ "primaryKey": false,
1927
+ "notNull": false,
1928
+ "autoincrement": false
1929
+ },
1930
+ "ref_schema_uid": {
1931
+ "name": "ref_schema_uid",
1932
+ "type": "text",
1933
+ "primaryKey": false,
1934
+ "notNull": false,
1935
+ "autoincrement": false
1936
+ },
1937
+ "ref_seed_type": {
1938
+ "name": "ref_seed_type",
1939
+ "type": "text",
1940
+ "primaryKey": false,
1941
+ "notNull": false,
1942
+ "autoincrement": false
1943
+ },
1944
+ "ref_resolved_value": {
1945
+ "name": "ref_resolved_value",
1946
+ "type": "text",
1947
+ "primaryKey": false,
1948
+ "notNull": false,
1949
+ "autoincrement": false
1950
+ },
1951
+ "ref_resolved_display_value": {
1952
+ "name": "ref_resolved_display_value",
1953
+ "type": "text",
1954
+ "primaryKey": false,
1955
+ "notNull": false,
1956
+ "autoincrement": false
1957
+ },
1958
+ "local_storage_dir": {
1959
+ "name": "local_storage_dir",
1960
+ "type": "text",
1961
+ "primaryKey": false,
1962
+ "notNull": false,
1963
+ "autoincrement": false
1964
+ },
1965
+ "attestation_raw": {
1966
+ "name": "attestation_raw",
1967
+ "type": "text",
1968
+ "primaryKey": false,
1969
+ "notNull": false,
1970
+ "autoincrement": false
1971
+ },
1972
+ "attestation_created_at": {
1973
+ "name": "attestation_created_at",
1974
+ "type": "integer",
1975
+ "primaryKey": false,
1976
+ "notNull": false,
1977
+ "autoincrement": false
1978
+ },
1979
+ "content_hash": {
1980
+ "name": "content_hash",
1981
+ "type": "text",
1982
+ "primaryKey": false,
1983
+ "notNull": false,
1984
+ "autoincrement": false
1985
+ },
1986
+ "created_at": {
1987
+ "name": "created_at",
1988
+ "type": "integer",
1989
+ "primaryKey": false,
1990
+ "notNull": false,
1991
+ "autoincrement": false
1992
+ },
1993
+ "updated_at": {
1994
+ "name": "updated_at",
1995
+ "type": "integer",
1996
+ "primaryKey": false,
1997
+ "notNull": false,
1998
+ "autoincrement": false
1999
+ },
2000
+ "publisher": {
2001
+ "name": "publisher",
2002
+ "type": "text",
2003
+ "primaryKey": false,
2004
+ "notNull": false,
2005
+ "autoincrement": false
2006
+ }
2007
+ },
2008
+ "indexes": {
2009
+ "metadata_local_id_unique": {
2010
+ "name": "metadata_local_id_unique",
2011
+ "columns": [
2012
+ "local_id"
2013
+ ],
2014
+ "isUnique": true
2015
+ }
2016
+ },
2017
+ "foreignKeys": {
2018
+ "metadata_property_id_properties_id_fk": {
2019
+ "name": "metadata_property_id_properties_id_fk",
2020
+ "tableFrom": "metadata",
2021
+ "tableTo": "properties",
2022
+ "columnsFrom": [
2023
+ "property_id"
2024
+ ],
2025
+ "columnsTo": [
2026
+ "id"
2027
+ ],
2028
+ "onDelete": "no action",
2029
+ "onUpdate": "no action"
2030
+ }
2031
+ },
2032
+ "compositePrimaryKeys": {},
2033
+ "uniqueConstraints": {},
2034
+ "checkConstraints": {}
2035
+ },
2036
+ "models": {
2037
+ "name": "models",
2038
+ "columns": {
2039
+ "id": {
2040
+ "name": "id",
2041
+ "type": "integer",
2042
+ "primaryKey": true,
2043
+ "notNull": true,
2044
+ "autoincrement": true
2045
+ },
2046
+ "name": {
2047
+ "name": "name",
2048
+ "type": "text",
2049
+ "primaryKey": false,
2050
+ "notNull": true,
2051
+ "autoincrement": false
2052
+ },
2053
+ "schema_file_id": {
2054
+ "name": "schema_file_id",
2055
+ "type": "text",
2056
+ "primaryKey": false,
2057
+ "notNull": false,
2058
+ "autoincrement": false
2059
+ },
2060
+ "is_edited": {
2061
+ "name": "is_edited",
2062
+ "type": "integer",
2063
+ "primaryKey": false,
2064
+ "notNull": false,
2065
+ "autoincrement": false
2066
+ }
2067
+ },
2068
+ "indexes": {
2069
+ "unique_schema_file_id": {
2070
+ "name": "unique_schema_file_id",
2071
+ "columns": [
2072
+ "schema_file_id"
2073
+ ],
2074
+ "isUnique": true
2075
+ }
2076
+ },
2077
+ "foreignKeys": {},
2078
+ "compositePrimaryKeys": {},
2079
+ "uniqueConstraints": {},
2080
+ "checkConstraints": {}
2081
+ },
2082
+ "properties": {
2083
+ "name": "properties",
2084
+ "columns": {
2085
+ "id": {
2086
+ "name": "id",
2087
+ "type": "integer",
2088
+ "primaryKey": true,
2089
+ "notNull": true,
2090
+ "autoincrement": true
2091
+ },
2092
+ "name": {
2093
+ "name": "name",
2094
+ "type": "text",
2095
+ "primaryKey": false,
2096
+ "notNull": true,
2097
+ "autoincrement": false
2098
+ },
2099
+ "data_type": {
2100
+ "name": "data_type",
2101
+ "type": "text",
2102
+ "primaryKey": false,
2103
+ "notNull": true,
2104
+ "autoincrement": false
2105
+ },
2106
+ "model_id": {
2107
+ "name": "model_id",
2108
+ "type": "integer",
2109
+ "primaryKey": false,
2110
+ "notNull": true,
2111
+ "autoincrement": false
2112
+ },
2113
+ "ref_model_id": {
2114
+ "name": "ref_model_id",
2115
+ "type": "integer",
2116
+ "primaryKey": false,
2117
+ "notNull": false,
2118
+ "autoincrement": false
2119
+ },
2120
+ "ref_value_type": {
2121
+ "name": "ref_value_type",
2122
+ "type": "text",
2123
+ "primaryKey": false,
2124
+ "notNull": false,
2125
+ "autoincrement": false
2126
+ },
2127
+ "schema_file_id": {
2128
+ "name": "schema_file_id",
2129
+ "type": "text",
2130
+ "primaryKey": false,
2131
+ "notNull": false,
2132
+ "autoincrement": false
2133
+ },
2134
+ "is_edited": {
2135
+ "name": "is_edited",
2136
+ "type": "integer",
2137
+ "primaryKey": false,
2138
+ "notNull": false,
2139
+ "autoincrement": false
2140
+ },
2141
+ "required": {
2142
+ "name": "required",
2143
+ "type": "integer",
2144
+ "primaryKey": false,
2145
+ "notNull": false,
2146
+ "autoincrement": false
2147
+ }
2148
+ },
2149
+ "indexes": {
2150
+ "unique_name_model_id": {
2151
+ "name": "unique_name_model_id",
2152
+ "columns": [
2153
+ "name",
2154
+ "model_id"
2155
+ ],
2156
+ "isUnique": true
2157
+ },
2158
+ "unique_property_schema_file_id": {
2159
+ "name": "unique_property_schema_file_id",
2160
+ "columns": [
2161
+ "schema_file_id"
2162
+ ],
2163
+ "isUnique": true
2164
+ }
2165
+ },
2166
+ "foreignKeys": {
2167
+ "properties_model_id_models_id_fk": {
2168
+ "name": "properties_model_id_models_id_fk",
2169
+ "tableFrom": "properties",
2170
+ "tableTo": "models",
2171
+ "columnsFrom": [
2172
+ "model_id"
2173
+ ],
2174
+ "columnsTo": [
2175
+ "id"
2176
+ ],
2177
+ "onDelete": "no action",
2178
+ "onUpdate": "no action"
2179
+ },
2180
+ "properties_ref_model_id_models_id_fk": {
2181
+ "name": "properties_ref_model_id_models_id_fk",
2182
+ "tableFrom": "properties",
2183
+ "tableTo": "models",
2184
+ "columnsFrom": [
2185
+ "ref_model_id"
2186
+ ],
2187
+ "columnsTo": [
2188
+ "id"
2189
+ ],
2190
+ "onDelete": "no action",
2191
+ "onUpdate": "no action"
2192
+ }
2193
+ },
2194
+ "compositePrimaryKeys": {},
2195
+ "uniqueConstraints": {},
2196
+ "checkConstraints": {}
2197
+ },
2198
+ "model_schemas": {
2199
+ "name": "model_schemas",
2200
+ "columns": {
2201
+ "id": {
2202
+ "name": "id",
2203
+ "type": "integer",
2204
+ "primaryKey": true,
2205
+ "notNull": true,
2206
+ "autoincrement": true
2207
+ },
2208
+ "model_id": {
2209
+ "name": "model_id",
2210
+ "type": "integer",
2211
+ "primaryKey": false,
2212
+ "notNull": false,
2213
+ "autoincrement": false
2214
+ },
2215
+ "schema_id": {
2216
+ "name": "schema_id",
2217
+ "type": "integer",
2218
+ "primaryKey": false,
2219
+ "notNull": false,
2220
+ "autoincrement": false
2221
+ }
2222
+ },
2223
+ "indexes": {},
2224
+ "foreignKeys": {
2225
+ "model_schemas_model_id_models_id_fk": {
2226
+ "name": "model_schemas_model_id_models_id_fk",
2227
+ "tableFrom": "model_schemas",
2228
+ "tableTo": "models",
2229
+ "columnsFrom": [
2230
+ "model_id"
2231
+ ],
2232
+ "columnsTo": [
2233
+ "id"
2234
+ ],
2235
+ "onDelete": "no action",
2236
+ "onUpdate": "no action"
2237
+ },
2238
+ "model_schemas_schema_id_schemas_id_fk": {
2239
+ "name": "model_schemas_schema_id_schemas_id_fk",
2240
+ "tableFrom": "model_schemas",
2241
+ "tableTo": "schemas",
2242
+ "columnsFrom": [
2243
+ "schema_id"
2244
+ ],
2245
+ "columnsTo": [
2246
+ "id"
2247
+ ],
2248
+ "onDelete": "no action",
2249
+ "onUpdate": "no action"
2250
+ }
2251
+ },
2252
+ "compositePrimaryKeys": {},
2253
+ "uniqueConstraints": {},
2254
+ "checkConstraints": {}
2255
+ },
2256
+ "model_uids": {
2257
+ "name": "model_uids",
2258
+ "columns": {
2259
+ "id": {
2260
+ "name": "id",
2261
+ "type": "integer",
2262
+ "primaryKey": true,
2263
+ "notNull": true,
2264
+ "autoincrement": true
2265
+ },
2266
+ "uid": {
2267
+ "name": "uid",
2268
+ "type": "text",
2269
+ "primaryKey": false,
2270
+ "notNull": true,
2271
+ "autoincrement": false
2272
+ },
2273
+ "model_id": {
2274
+ "name": "model_id",
2275
+ "type": "integer",
2276
+ "primaryKey": false,
2277
+ "notNull": true,
2278
+ "autoincrement": false
2279
+ }
2280
+ },
2281
+ "indexes": {
2282
+ "model_uids_model_id_unique": {
2283
+ "name": "model_uids_model_id_unique",
2284
+ "columns": [
2285
+ "model_id"
2286
+ ],
2287
+ "isUnique": true
2288
+ }
2289
+ },
2290
+ "foreignKeys": {
2291
+ "model_uids_model_id_models_id_fk": {
2292
+ "name": "model_uids_model_id_models_id_fk",
2293
+ "tableFrom": "model_uids",
2294
+ "tableTo": "models",
2295
+ "columnsFrom": [
2296
+ "model_id"
2297
+ ],
2298
+ "columnsTo": [
2299
+ "id"
2300
+ ],
2301
+ "onDelete": "no action",
2302
+ "onUpdate": "no action"
2303
+ }
2304
+ },
2305
+ "compositePrimaryKeys": {},
2306
+ "uniqueConstraints": {},
2307
+ "checkConstraints": {}
2308
+ },
2309
+ "property_uids": {
2310
+ "name": "property_uids",
2311
+ "columns": {
2312
+ "id": {
2313
+ "name": "id",
2314
+ "type": "integer",
2315
+ "primaryKey": true,
2316
+ "notNull": true,
2317
+ "autoincrement": true
2318
+ },
2319
+ "uid": {
2320
+ "name": "uid",
2321
+ "type": "text",
2322
+ "primaryKey": false,
2323
+ "notNull": true,
2324
+ "autoincrement": false
2325
+ },
2326
+ "property_id": {
2327
+ "name": "property_id",
2328
+ "type": "integer",
2329
+ "primaryKey": false,
2330
+ "notNull": true,
2331
+ "autoincrement": false
2332
+ }
2333
+ },
2334
+ "indexes": {
2335
+ "property_uids_property_id_unique": {
2336
+ "name": "property_uids_property_id_unique",
2337
+ "columns": [
2338
+ "property_id"
2339
+ ],
2340
+ "isUnique": true
2341
+ }
2342
+ },
2343
+ "foreignKeys": {
2344
+ "property_uids_property_id_properties_id_fk": {
2345
+ "name": "property_uids_property_id_properties_id_fk",
2346
+ "tableFrom": "property_uids",
2347
+ "tableTo": "properties",
2348
+ "columnsFrom": [
2349
+ "property_id"
2350
+ ],
2351
+ "columnsTo": [
2352
+ "id"
2353
+ ],
2354
+ "onDelete": "no action",
2355
+ "onUpdate": "no action"
2356
+ }
2357
+ },
2358
+ "compositePrimaryKeys": {},
2359
+ "uniqueConstraints": {},
2360
+ "checkConstraints": {}
2361
+ },
2362
+ "publish_processes": {
2363
+ "name": "publish_processes",
2364
+ "columns": {
2365
+ "id": {
2366
+ "name": "id",
2367
+ "type": "integer",
2368
+ "primaryKey": true,
2369
+ "notNull": true,
2370
+ "autoincrement": true
2371
+ },
2372
+ "seed_local_id": {
2373
+ "name": "seed_local_id",
2374
+ "type": "text",
2375
+ "primaryKey": false,
2376
+ "notNull": true,
2377
+ "autoincrement": false
2378
+ },
2379
+ "model_name": {
2380
+ "name": "model_name",
2381
+ "type": "text",
2382
+ "primaryKey": false,
2383
+ "notNull": true,
2384
+ "autoincrement": false
2385
+ },
2386
+ "schema_id": {
2387
+ "name": "schema_id",
2388
+ "type": "text",
2389
+ "primaryKey": false,
2390
+ "notNull": false,
2391
+ "autoincrement": false
2392
+ },
2393
+ "status": {
2394
+ "name": "status",
2395
+ "type": "text",
2396
+ "primaryKey": false,
2397
+ "notNull": true,
2398
+ "autoincrement": false
2399
+ },
2400
+ "started_at": {
2401
+ "name": "started_at",
2402
+ "type": "integer",
2403
+ "primaryKey": false,
2404
+ "notNull": true,
2405
+ "autoincrement": false
2406
+ },
2407
+ "completed_at": {
2408
+ "name": "completed_at",
2409
+ "type": "integer",
2410
+ "primaryKey": false,
2411
+ "notNull": false,
2412
+ "autoincrement": false
2413
+ },
2414
+ "error_message": {
2415
+ "name": "error_message",
2416
+ "type": "text",
2417
+ "primaryKey": false,
2418
+ "notNull": false,
2419
+ "autoincrement": false
2420
+ },
2421
+ "error_step": {
2422
+ "name": "error_step",
2423
+ "type": "text",
2424
+ "primaryKey": false,
2425
+ "notNull": false,
2426
+ "autoincrement": false
2427
+ },
2428
+ "error_details": {
2429
+ "name": "error_details",
2430
+ "type": "text",
2431
+ "primaryKey": false,
2432
+ "notNull": false,
2433
+ "autoincrement": false
2434
+ },
2435
+ "persisted_snapshot": {
2436
+ "name": "persisted_snapshot",
2437
+ "type": "text",
2438
+ "primaryKey": false,
2439
+ "notNull": true,
2440
+ "autoincrement": false
2441
+ },
2442
+ "seed_id": {
2443
+ "name": "seed_id",
2444
+ "type": "text",
2445
+ "primaryKey": false,
2446
+ "notNull": false,
2447
+ "autoincrement": false
2448
+ },
2449
+ "existing_seed_uid": {
2450
+ "name": "existing_seed_uid",
2451
+ "type": "text",
2452
+ "primaryKey": false,
2453
+ "notNull": false,
2454
+ "autoincrement": false
2455
+ },
2456
+ "created_at": {
2457
+ "name": "created_at",
2458
+ "type": "integer",
2459
+ "primaryKey": false,
2460
+ "notNull": false,
2461
+ "autoincrement": false
2462
+ },
2463
+ "updated_at": {
2464
+ "name": "updated_at",
2465
+ "type": "integer",
2466
+ "primaryKey": false,
2467
+ "notNull": false,
2468
+ "autoincrement": false
2469
+ }
2470
+ },
2471
+ "indexes": {},
2472
+ "foreignKeys": {},
2473
+ "compositePrimaryKeys": {},
2474
+ "uniqueConstraints": {},
2475
+ "checkConstraints": {}
2476
+ },
2477
+ "schemas": {
2478
+ "name": "schemas",
2479
+ "columns": {
2480
+ "id": {
2481
+ "name": "id",
2482
+ "type": "integer",
2483
+ "primaryKey": true,
2484
+ "notNull": true,
2485
+ "autoincrement": true
2486
+ },
2487
+ "name": {
2488
+ "name": "name",
2489
+ "type": "text",
2490
+ "primaryKey": false,
2491
+ "notNull": true,
2492
+ "autoincrement": false
2493
+ },
2494
+ "version": {
2495
+ "name": "version",
2496
+ "type": "integer",
2497
+ "primaryKey": false,
2498
+ "notNull": true,
2499
+ "autoincrement": false
2500
+ },
2501
+ "schema_file_id": {
2502
+ "name": "schema_file_id",
2503
+ "type": "text",
2504
+ "primaryKey": false,
2505
+ "notNull": false,
2506
+ "autoincrement": false
2507
+ },
2508
+ "schema_data": {
2509
+ "name": "schema_data",
2510
+ "type": "text",
2511
+ "primaryKey": false,
2512
+ "notNull": false,
2513
+ "autoincrement": false
2514
+ },
2515
+ "is_draft": {
2516
+ "name": "is_draft",
2517
+ "type": "integer",
2518
+ "primaryKey": false,
2519
+ "notNull": false,
2520
+ "autoincrement": false
2521
+ },
2522
+ "is_edited": {
2523
+ "name": "is_edited",
2524
+ "type": "integer",
2525
+ "primaryKey": false,
2526
+ "notNull": false,
2527
+ "autoincrement": false
2528
+ },
2529
+ "created_at": {
2530
+ "name": "created_at",
2531
+ "type": "integer",
2532
+ "primaryKey": false,
2533
+ "notNull": false,
2534
+ "autoincrement": false
2535
+ },
2536
+ "updated_at": {
2537
+ "name": "updated_at",
2538
+ "type": "integer",
2539
+ "primaryKey": false,
2540
+ "notNull": false,
2541
+ "autoincrement": false
2542
+ }
2543
+ },
2544
+ "indexes": {
2545
+ "unique_schema_schema_file_id": {
2546
+ "name": "unique_schema_schema_file_id",
2547
+ "columns": [
2548
+ "schema_file_id"
2549
+ ],
2550
+ "isUnique": true
2551
+ }
2552
+ },
2553
+ "foreignKeys": {},
2554
+ "compositePrimaryKeys": {},
2555
+ "uniqueConstraints": {},
2556
+ "checkConstraints": {}
2557
+ },
2558
+ "seeds": {
2559
+ "name": "seeds",
2560
+ "columns": {
2561
+ "local_id": {
2562
+ "name": "local_id",
2563
+ "type": "text",
2564
+ "primaryKey": false,
2565
+ "notNull": false,
2566
+ "autoincrement": false
2567
+ },
2568
+ "uid": {
2569
+ "name": "uid",
2570
+ "type": "text",
2571
+ "primaryKey": false,
2572
+ "notNull": false,
2573
+ "autoincrement": false
2574
+ },
2575
+ "schema_uid": {
2576
+ "name": "schema_uid",
2577
+ "type": "text",
2578
+ "primaryKey": false,
2579
+ "notNull": false,
2580
+ "autoincrement": false
2581
+ },
2582
+ "type": {
2583
+ "name": "type",
2584
+ "type": "text",
2585
+ "primaryKey": false,
2586
+ "notNull": false,
2587
+ "autoincrement": false
2588
+ },
2589
+ "publisher": {
2590
+ "name": "publisher",
2591
+ "type": "text",
2592
+ "primaryKey": false,
2593
+ "notNull": false,
2594
+ "autoincrement": false
2595
+ },
2596
+ "attestation_raw": {
2597
+ "name": "attestation_raw",
2598
+ "type": "text",
2599
+ "primaryKey": false,
2600
+ "notNull": false,
2601
+ "autoincrement": false
2602
+ },
2603
+ "attestation_created_at": {
2604
+ "name": "attestation_created_at",
2605
+ "type": "integer",
2606
+ "primaryKey": false,
2607
+ "notNull": false,
2608
+ "autoincrement": false
2609
+ },
2610
+ "created_at": {
2611
+ "name": "created_at",
2612
+ "type": "integer",
2613
+ "primaryKey": false,
2614
+ "notNull": false,
2615
+ "autoincrement": false
2616
+ },
2617
+ "updated_at": {
2618
+ "name": "updated_at",
2619
+ "type": "integer",
2620
+ "primaryKey": false,
2621
+ "notNull": false,
2622
+ "autoincrement": false
2623
+ },
2624
+ "_marked_for_deletion": {
2625
+ "name": "_marked_for_deletion",
2626
+ "type": "integer",
2627
+ "primaryKey": false,
2628
+ "notNull": false,
2629
+ "autoincrement": false
2630
+ },
2631
+ "revoked_at": {
2632
+ "name": "revoked_at",
2633
+ "type": "integer",
2634
+ "primaryKey": false,
2635
+ "notNull": false,
2636
+ "autoincrement": false
2637
+ }
2638
+ },
2639
+ "indexes": {
2640
+ "seeds_local_id_unique": {
2641
+ "name": "seeds_local_id_unique",
2642
+ "columns": [
2643
+ "local_id"
2644
+ ],
2645
+ "isUnique": true
2646
+ }
2647
+ },
2648
+ "foreignKeys": {},
2649
+ "compositePrimaryKeys": {},
2650
+ "uniqueConstraints": {},
2651
+ "checkConstraints": {}
2652
+ },
2653
+ "upload_processes": {
2654
+ "name": "upload_processes",
2655
+ "columns": {
2656
+ "id": {
2657
+ "name": "id",
2658
+ "type": "integer",
2659
+ "primaryKey": true,
2660
+ "notNull": true,
2661
+ "autoincrement": true
2662
+ },
2663
+ "reimbursement_confirmed": {
2664
+ "name": "reimbursement_confirmed",
2665
+ "type": "integer",
2666
+ "primaryKey": false,
2667
+ "notNull": true,
2668
+ "autoincrement": false
2669
+ },
2670
+ "reimbursement_transaction_id": {
2671
+ "name": "reimbursement_transaction_id",
2672
+ "type": "text",
2673
+ "primaryKey": false,
2674
+ "notNull": false,
2675
+ "autoincrement": false
2676
+ },
2677
+ "transaction_keys": {
2678
+ "name": "transaction_keys",
2679
+ "type": "text",
2680
+ "primaryKey": false,
2681
+ "notNull": false,
2682
+ "autoincrement": false
2683
+ },
2684
+ "persisted_snapshot": {
2685
+ "name": "persisted_snapshot",
2686
+ "type": "text",
2687
+ "primaryKey": false,
2688
+ "notNull": true,
2689
+ "autoincrement": false
2690
+ },
2691
+ "created_at": {
2692
+ "name": "created_at",
2693
+ "type": "integer",
2694
+ "primaryKey": false,
2695
+ "notNull": false,
2696
+ "autoincrement": false
2697
+ },
2698
+ "updated_at": {
2699
+ "name": "updated_at",
2700
+ "type": "integer",
2701
+ "primaryKey": false,
2702
+ "notNull": false,
2703
+ "autoincrement": false
2704
+ }
2705
+ },
2706
+ "indexes": {},
2707
+ "foreignKeys": {},
2708
+ "compositePrimaryKeys": {},
2709
+ "uniqueConstraints": {},
2710
+ "checkConstraints": {}
2711
+ },
2712
+ "versions": {
2713
+ "name": "versions",
2714
+ "columns": {
2715
+ "local_id": {
2716
+ "name": "local_id",
2717
+ "type": "text",
2718
+ "primaryKey": false,
2719
+ "notNull": false,
2720
+ "autoincrement": false
2721
+ },
2722
+ "uid": {
2723
+ "name": "uid",
2724
+ "type": "text",
2725
+ "primaryKey": false,
2726
+ "notNull": false,
2727
+ "autoincrement": false
2728
+ },
2729
+ "seed_local_id": {
2730
+ "name": "seed_local_id",
2731
+ "type": "text",
2732
+ "primaryKey": false,
2733
+ "notNull": false,
2734
+ "autoincrement": false
2735
+ },
2736
+ "seed_uid": {
2737
+ "name": "seed_uid",
2738
+ "type": "text",
2739
+ "primaryKey": false,
2740
+ "notNull": false,
2741
+ "autoincrement": false
2742
+ },
2743
+ "seed_type": {
2744
+ "name": "seed_type",
2745
+ "type": "text",
2746
+ "primaryKey": false,
2747
+ "notNull": false,
2748
+ "autoincrement": false
2749
+ },
2750
+ "note": {
2751
+ "name": "note",
2752
+ "type": "text",
2753
+ "primaryKey": false,
2754
+ "notNull": false,
2755
+ "autoincrement": false
2756
+ },
2757
+ "created_at": {
2758
+ "name": "created_at",
2759
+ "type": "integer",
2760
+ "primaryKey": false,
2761
+ "notNull": false,
2762
+ "autoincrement": false
2763
+ },
2764
+ "updated_at": {
2765
+ "name": "updated_at",
2766
+ "type": "integer",
2767
+ "primaryKey": false,
2768
+ "notNull": false,
2769
+ "autoincrement": false
2770
+ },
2771
+ "attestation_created_at": {
2772
+ "name": "attestation_created_at",
2773
+ "type": "integer",
2774
+ "primaryKey": false,
2775
+ "notNull": false,
2776
+ "autoincrement": false
2777
+ },
2778
+ "attestation_raw": {
2779
+ "name": "attestation_raw",
2780
+ "type": "text",
2781
+ "primaryKey": false,
2782
+ "notNull": false,
2783
+ "autoincrement": false
2784
+ },
2785
+ "publisher": {
2786
+ "name": "publisher",
2787
+ "type": "text",
2788
+ "primaryKey": false,
2789
+ "notNull": false,
2790
+ "autoincrement": false
2791
+ }
2792
+ },
2793
+ "indexes": {
2794
+ "versions_local_id_unique": {
2795
+ "name": "versions_local_id_unique",
2796
+ "columns": [
2797
+ "local_id"
2798
+ ],
2799
+ "isUnique": true
2800
+ }
2801
+ },
2802
+ "foreignKeys": {},
2803
+ "compositePrimaryKeys": {},
2804
+ "uniqueConstraints": {},
2805
+ "checkConstraints": {}
2806
+ },
2807
+ "arweave_l1_finalize_jobs": {
2808
+ "name": "arweave_l1_finalize_jobs",
2809
+ "columns": {
2810
+ "id": {
2811
+ "name": "id",
2812
+ "type": "integer",
2813
+ "primaryKey": true,
2814
+ "notNull": true,
2815
+ "autoincrement": true
2816
+ },
2817
+ "seed_local_id": {
2818
+ "name": "seed_local_id",
2819
+ "type": "text",
2820
+ "primaryKey": false,
2821
+ "notNull": true,
2822
+ "autoincrement": false
2823
+ },
2824
+ "data_item_id": {
2825
+ "name": "data_item_id",
2826
+ "type": "text",
2827
+ "primaryKey": false,
2828
+ "notNull": true,
2829
+ "autoincrement": false
2830
+ },
2831
+ "l1_transaction_id": {
2832
+ "name": "l1_transaction_id",
2833
+ "type": "text",
2834
+ "primaryKey": false,
2835
+ "notNull": false,
2836
+ "autoincrement": false
2837
+ },
2838
+ "bundle_id": {
2839
+ "name": "bundle_id",
2840
+ "type": "text",
2841
+ "primaryKey": false,
2842
+ "notNull": false,
2843
+ "autoincrement": false
2844
+ },
2845
+ "version_local_id": {
2846
+ "name": "version_local_id",
2847
+ "type": "text",
2848
+ "primaryKey": false,
2849
+ "notNull": false,
2850
+ "autoincrement": false
2851
+ },
2852
+ "item_property_name": {
2853
+ "name": "item_property_name",
2854
+ "type": "text",
2855
+ "primaryKey": false,
2856
+ "notNull": false,
2857
+ "autoincrement": false
2858
+ },
2859
+ "phase": {
2860
+ "name": "phase",
2861
+ "type": "text",
2862
+ "primaryKey": false,
2863
+ "notNull": true,
2864
+ "autoincrement": false
2865
+ },
2866
+ "status_json": {
2867
+ "name": "status_json",
2868
+ "type": "text",
2869
+ "primaryKey": false,
2870
+ "notNull": false,
2871
+ "autoincrement": false
2872
+ },
2873
+ "error_message": {
2874
+ "name": "error_message",
2875
+ "type": "text",
2876
+ "primaryKey": false,
2877
+ "notNull": false,
2878
+ "autoincrement": false
2879
+ },
2880
+ "created_at": {
2881
+ "name": "created_at",
2882
+ "type": "integer",
2883
+ "primaryKey": false,
2884
+ "notNull": true,
2885
+ "autoincrement": false
2886
+ },
2887
+ "updated_at": {
2888
+ "name": "updated_at",
2889
+ "type": "integer",
2890
+ "primaryKey": false,
2891
+ "notNull": true,
2892
+ "autoincrement": false
2893
+ }
2894
+ },
2895
+ "indexes": {
2896
+ "arweave_l1_finalize_jobs_data_item_id_unique": {
2897
+ "name": "arweave_l1_finalize_jobs_data_item_id_unique",
2898
+ "columns": [
2899
+ "data_item_id"
2900
+ ],
2901
+ "isUnique": true
2902
+ }
2903
+ },
2904
+ "foreignKeys": {},
2905
+ "compositePrimaryKeys": {},
2906
+ "uniqueConstraints": {},
2907
+ "checkConstraints": {}
2908
+ },
2909
+ "eas_sync_processes": {
2910
+ "name": "eas_sync_processes",
2911
+ "columns": {
2912
+ "id": {
2913
+ "name": "id",
2914
+ "type": "integer",
2915
+ "primaryKey": true,
2916
+ "notNull": true,
2917
+ "autoincrement": true
2918
+ },
2919
+ "status": {
2920
+ "name": "status",
2921
+ "type": "text",
2922
+ "primaryKey": false,
2923
+ "notNull": true,
2924
+ "autoincrement": false
2925
+ },
2926
+ "started_at": {
2927
+ "name": "started_at",
2928
+ "type": "integer",
2929
+ "primaryKey": false,
2930
+ "notNull": true,
2931
+ "autoincrement": false
2932
+ },
2933
+ "completed_at": {
2934
+ "name": "completed_at",
2935
+ "type": "integer",
2936
+ "primaryKey": false,
2937
+ "notNull": false,
2938
+ "autoincrement": false
2939
+ },
2940
+ "request_payload": {
2941
+ "name": "request_payload",
2942
+ "type": "text",
2943
+ "primaryKey": false,
2944
+ "notNull": true,
2945
+ "autoincrement": false
2946
+ },
2947
+ "error_message": {
2948
+ "name": "error_message",
2949
+ "type": "text",
2950
+ "primaryKey": false,
2951
+ "notNull": false,
2952
+ "autoincrement": false
2953
+ },
2954
+ "error_details": {
2955
+ "name": "error_details",
2956
+ "type": "text",
2957
+ "primaryKey": false,
2958
+ "notNull": false,
2959
+ "autoincrement": false
2960
+ },
2961
+ "persisted_snapshot": {
2962
+ "name": "persisted_snapshot",
2963
+ "type": "text",
2964
+ "primaryKey": false,
2965
+ "notNull": true,
2966
+ "autoincrement": false
2967
+ },
2968
+ "created_at": {
2969
+ "name": "created_at",
2970
+ "type": "integer",
2971
+ "primaryKey": false,
2972
+ "notNull": false,
2973
+ "autoincrement": false
2974
+ },
2975
+ "updated_at": {
2976
+ "name": "updated_at",
2977
+ "type": "integer",
2978
+ "primaryKey": false,
2979
+ "notNull": false,
2980
+ "autoincrement": false
2981
+ }
2982
+ },
2983
+ "indexes": {},
2984
+ "foreignKeys": {},
2985
+ "compositePrimaryKeys": {},
2986
+ "uniqueConstraints": {},
2987
+ "checkConstraints": {}
2988
+ }
2989
+ },
2990
+ "views": {},
2991
+ "enums": {},
2992
+ "_meta": {
2993
+ "schemas": {},
2994
+ "tables": {},
2995
+ "columns": {}
2996
+ },
2997
+ "internal": {
2998
+ "indexes": {}
2999
+ }
3000
+ }`;
3001
+
3002
+ var drizzleFiles = /*#__PURE__*/Object.freeze({
3003
+ __proto__: null,
3004
+ journalJson: journalJson,
3005
+ migrationSql_0000_married_malice: migrationSql_0000_married_malice,
3006
+ migrationSql_0001_sweet_bruce_banner: migrationSql_0001_sweet_bruce_banner,
3007
+ migrationSql_0002_bitter_proudstar: migrationSql_0002_bitter_proudstar,
3008
+ migrationSql_0003_cultured_senator_kelly: migrationSql_0003_cultured_senator_kelly,
3009
+ migrationSql_0004_add_publisher_to_seeds: migrationSql_0004_add_publisher_to_seeds,
3010
+ migrationSql_0005_bright_lily_hollister: migrationSql_0005_bright_lily_hollister,
3011
+ migrationSql_0006_add_publisher_to_versions_and_metadata: migrationSql_0006_add_publisher_to_versions_and_metadata,
3012
+ migrationSql_0007_add_required_to_properties: migrationSql_0007_add_required_to_properties,
3013
+ migrationSql_0008_add_revoked_at_to_seeds: migrationSql_0008_add_revoked_at_to_seeds,
3014
+ migrationSql_0009_happy_namor: migrationSql_0009_happy_namor,
3015
+ migrationSql_0010_add_arweave_l1_finalize_jobs: migrationSql_0010_add_arweave_l1_finalize_jobs,
3016
+ migrationSql_0011_normalize_placeholder_uids: migrationSql_0011_normalize_placeholder_uids,
3017
+ migrationSql_0012_html_embedded_image_co_publish: migrationSql_0012_html_embedded_image_co_publish,
3018
+ migrationSql_0013_eas_sync_processes: migrationSql_0013_eas_sync_processes,
3019
+ snapshotJson: snapshotJson
3020
+ });
3021
+
3022
+ const logger$1 = debug('seedSdk:browser:db:Db');
3023
+ class BrowserDb {
3024
+ getAppDb() {
3025
+ return this.appDb;
3026
+ }
3027
+ isAppDbReady() {
3028
+ return !!this.appDb;
3029
+ }
3030
+ async prepareDb(filesDir) {
3031
+ logger$1('[Db.prepareDb] preparing database');
3032
+ this.filesDir = filesDir;
3033
+ try {
3034
+ // Copy drizzle migration files from src/db/drizzle to filesDir/db
3035
+ await this.copyDrizzleFiles(filesDir);
3036
+ // Ensure meta directory exists
3037
+ const metaDirPath = `${filesDir}/db/meta`;
3038
+ await BaseFileManager.createDirIfNotExists(metaDirPath);
3039
+ // Ensure _journal.json file exists in meta directory
3040
+ const journalFilePath = `${metaDirPath}/_journal.json`;
3041
+ const journalExists = await BaseFileManager.pathExists(journalFilePath);
3042
+ if (!journalExists) {
3043
+ await BaseFileManager.saveFile(journalFilePath, JSON.stringify({
3044
+ version: 1,
3045
+ dialect: 'sqlite',
3046
+ entries: [],
3047
+ }, null, 2));
3048
+ }
3049
+ // Wait for journal file to be fully written before proceeding with migration
3050
+ // This is critical in browser/OPFS where writes may not be immediately readable
3051
+ logger$1('[Db.prepareDb] waiting for journal file to be fully written...');
3052
+ await BaseFileManager.waitForFileWithContent(journalFilePath, 100, 5000);
3053
+ logger$1('[Db.prepareDb] journal file is ready');
3054
+ // Initialize SQLocalDrizzle with reactive: true to enable reactive queries
3055
+ const sqlocalDrizzle = new SQLocalDrizzle({
3056
+ databasePath: `${this.filesDir}/db/seed.db`,
3057
+ reactive: true // Enable reactive queries
3058
+ });
3059
+ const { driver, batchDriver } = sqlocalDrizzle;
3060
+ // Store SQLocalDrizzle instance for reactive queries
3061
+ this.sqlocalInstance = sqlocalDrizzle;
3062
+ // Create db instance but do NOT set this.appDb yet. restoreFromDb (and other
3063
+ // callers of getAppDb()) must not see the db until migrations have completed,
3064
+ // otherwise they may query tables (e.g. publish_processes) that don't exist yet.
3065
+ const db = drizzle(driver, batchDriver, {
3066
+ schema,
3067
+ });
3068
+ logger$1('[Db.prepareDb] database prepared');
3069
+ await this.runMigrations(db);
3070
+ this.appDb = db;
3071
+ const { backfillMetadataPropertyIds } = await import('./backfillMetadataPropertyIds-DBVaIs7O.js');
3072
+ await backfillMetadataPropertyIds();
3073
+ return this.appDb;
3074
+ }
3075
+ catch (error) {
3076
+ logger$1('[Db.prepareDb] error', JSON.stringify(error));
3077
+ throw error;
3078
+ }
3079
+ }
3080
+ // static async prepareDb(filesDir: string) {
3081
+ // console.log('prepareDb', filesDir)
3082
+ // if (Db.sqliteWasmClient) {
3083
+ // return this.dbId
3084
+ // }
3085
+ // this.filesDir = filesDir
3086
+ // this.pathToDb = `${filesDir}/db/${DB_NAME_APP}.db`
3087
+ // if (typeof document === 'undefined') {
3088
+ // return
3089
+ // }
3090
+ // let promiser
3091
+ // try {
3092
+ // let sqlite3Worker1Promiser
3093
+ // const sqliteWasm = await import('@sqlite.org/sqlite-wasm')
3094
+ // if (sqliteWasm && sqliteWasm.sqlite3Worker1Promiser) {
3095
+ // sqlite3Worker1Promiser = sqliteWasm.sqlite3Worker1Promiser
3096
+ // }
3097
+ // if (!sqlite3Worker1Promiser && window.sqlite3Worker1Promiser) {
3098
+ // sqlite3Worker1Promiser = window.sqlite3Worker1Promiser
3099
+ // }
3100
+ // if (!sqlite3Worker1Promiser) {
3101
+ // throw new Error('Failed to load sqlite3Worker1Promiser')
3102
+ // }
3103
+ // promiser = await new Promise<(event: string, config: Record<string, unknown>) => Promise<any>>((resolve) => {
3104
+ // const _promiser = sqlite3Worker1Promiser({
3105
+ // onready: () => {
3106
+ // resolve(_promiser);
3107
+ // },
3108
+ // });
3109
+ // }).catch((error) => {
3110
+ // console.error('Error from sqlite proxy server: ', JSON.stringify(error))
3111
+ // });
3112
+ // } catch ( e ) {
3113
+ // console.error('Error from sqlite proxy server: ', JSON.stringify(e))
3114
+ // }
3115
+ // if (!promiser) {
3116
+ // throw new Error('Failed to create promiser')
3117
+ // }
3118
+ // this.sqliteWasmClient = promiser
3119
+ // const responseGet = await this.sqliteWasmClient('config-get', {});
3120
+ // logger('[Db.prepareDb] Running SQLite3 version', responseGet.result.version.libVersion);
3121
+ // const responseOpen = await this.sqliteWasmClient('open', {
3122
+ // filename: `file:${filesDir}/db/${DB_NAME_APP}.db?vfs=opfs`,
3123
+ // });
3124
+ // const { dbId } = responseOpen;
3125
+ // logger(
3126
+ // '[Db.prepareDb] OPFS is available, created persisted database at',
3127
+ // responseOpen.result.filename.replace(/^file:(.*?)\?vfs=opfs/, '$1'),
3128
+ // );
3129
+ // logger('[Db.prepareDb] dbId', dbId)
3130
+ // this.dbId = dbId
3131
+ // await this.migrate()
3132
+ // }
3133
+ async connectToDb(filesDir) {
3134
+ return this.dbId;
3135
+ }
3136
+ async copyDrizzleFiles(filesDir) {
3137
+ logger$1('[Db.copyDrizzleFiles] copying drizzle migration files');
3138
+ try {
3139
+ // Ensure db directory exists
3140
+ const dbDirPath = `${filesDir}/db`;
3141
+ await BaseFileManager.createDirIfNotExists(dbDirPath);
3142
+ // Ensure meta directory exists
3143
+ const metaDirPath = `${dbDirPath}/meta`;
3144
+ await BaseFileManager.createDirIfNotExists(metaDirPath);
3145
+ // Parse journal JSON to get all migration entries
3146
+ const journal = JSON.parse(journalJson);
3147
+ const entries = journal.entries || [];
3148
+ if (entries.length === 0) {
3149
+ logger$1('[Db.copyDrizzleFiles] no migration entries found in journal');
3150
+ return;
3151
+ }
3152
+ // Copy each migration SQL file (always overwrite to ensure they're up-to-date)
3153
+ // Each migration is exported as a separate variable (e.g., migrationSql_0000_married_malice)
3154
+ for (let i = 0; i < entries.length; i++) {
3155
+ const entry = entries[i];
3156
+ const tag = entry.tag; // e.g., "0000_married_malice"
3157
+ const migrationFileName = `${tag}.sql`;
3158
+ const migrationPath = `${dbDirPath}/${migrationFileName}`;
3159
+ // Get the SQL for this migration from the exported variable
3160
+ const migrationVarName = `migrationSql_${tag}`;
3161
+ const migrationContent = drizzleFiles[migrationVarName];
3162
+ if (!migrationContent) {
3163
+ logger$1(`[Db.copyDrizzleFiles] ERROR: No migration content found for ${migrationFileName} (variable: ${migrationVarName})`);
3164
+ throw new Error(`No migration content found for ${migrationFileName}. Expected variable: ${migrationVarName}`);
3165
+ }
3166
+ await BaseFileManager.saveFile(migrationPath, migrationContent.trim());
3167
+ logger$1(`[Db.copyDrizzleFiles] copied/updated migration SQL file: ${migrationFileName}`);
3168
+ }
3169
+ // Copy journal JSON file (always overwrite to ensure it's up-to-date with all migrations)
3170
+ const journalPath = `${metaDirPath}/_journal.json`;
3171
+ await BaseFileManager.saveFile(journalPath, journalJson);
3172
+ logger$1('[Db.copyDrizzleFiles] copied/updated journal JSON file');
3173
+ // Copy snapshot JSON file (use the latest snapshot based on the highest idx in journal)
3174
+ // Snapshot files are named like: 0000_snapshot.json, 0001_snapshot.json, etc.
3175
+ // The tag format is like "0000_married_malice", so we extract the numeric prefix
3176
+ const latestEntry = entries[entries.length - 1];
3177
+ const tagPrefixMatch = latestEntry.tag.match(/^(\d+_)/);
3178
+ const tagPrefix = tagPrefixMatch ? tagPrefixMatch[1] : '0000_';
3179
+ const snapshotFileName = `${tagPrefix}snapshot.json`;
3180
+ const snapshotPath = `${metaDirPath}/${snapshotFileName}`;
3181
+ // Always overwrite snapshot to ensure it's up-to-date
3182
+ await BaseFileManager.saveFile(snapshotPath, snapshotJson);
3183
+ logger$1(`[Db.copyDrizzleFiles] copied/updated snapshot JSON file: ${snapshotFileName}`);
3184
+ logger$1('[Db.copyDrizzleFiles] drizzle files copied successfully');
3185
+ }
3186
+ catch (error) {
3187
+ logger$1('[Db.copyDrizzleFiles] error copying drizzle files', error);
3188
+ // Don't throw - the files might already exist or migration might work without them
3189
+ // The migration will fail later if the files are truly needed
3190
+ }
3191
+ }
3192
+ /** Internal migration runner. Used by prepareDb before appDb is set. */
3193
+ async runMigrations(db, pathToDbDir) {
3194
+ const migrationsFolder = pathToDbDir ?? `${this.filesDir}/db`;
3195
+ try {
3196
+ logger$1('[Db.runMigrations] calling readMigrationFiles');
3197
+ const migrations = readMigrationFiles({
3198
+ migrationsFolder,
3199
+ });
3200
+ logger$1('[Db.runMigrations] migrations', migrations);
3201
+ await migrate(db, async (queriesToRun) => {
3202
+ logger$1('queriesToRun', queriesToRun);
3203
+ for (const query of queriesToRun) {
3204
+ logger$1('query', query);
3205
+ await db.run(sql.raw(query));
3206
+ }
3207
+ }, {
3208
+ migrationsFolder,
3209
+ });
3210
+ logger$1('[Db.runMigrations] migrations completed');
3211
+ }
3212
+ catch (error) {
3213
+ logger$1('[Db.runMigrations] error', JSON.stringify(error));
3214
+ throw error;
3215
+ }
3216
+ }
3217
+ async migrate(pathToDbDir, _dbName, _dbId) {
3218
+ const targetDb = this.appDb;
3219
+ if (!targetDb) {
3220
+ throw new Error('Database not prepared');
3221
+ }
3222
+ await this.runMigrations(targetDb, pathToDbDir);
3223
+ }
3224
+ // Legacy commented migrate/exec implementation archived at
3225
+ // docs/archive/commented/browser-Db-legacy-migrate.ts.txt
3226
+ /**
3227
+ * Execute a reactive query that emits new results whenever the underlying data changes.
3228
+ *
3229
+ * Supports two usage patterns:
3230
+ * 1. SQL tag function: liveQuery((sql) => sql`SELECT * FROM models`)
3231
+ * 2. Drizzle query builder: liveQuery(db.select().from(models))
3232
+ *
3233
+ * @param query - SQL query function or Drizzle query builder
3234
+ * @returns Observable that emits arrays of query results
3235
+ *
3236
+ * @example
3237
+ * ```typescript
3238
+ * // Using SQL tag function
3239
+ * const models$ = Db.liveQuery<ModelRow>(
3240
+ * (sql) => sql`SELECT * FROM models WHERE schema_file_id = ${schemaId}`
3241
+ * )
3242
+ *
3243
+ * // Using Drizzle query builder
3244
+ * const models$ = Db.liveQuery<ModelRow>(
3245
+ * appDb.select().from(models).where(eq(models.schemaFileId, schemaId))
3246
+ * )
3247
+ *
3248
+ * models$.subscribe(models => {
3249
+ * console.log('Models updated:', models)
3250
+ * })
3251
+ * ```
3252
+ */
3253
+ liveQuery(query) {
3254
+ if (!this.sqlocalInstance) {
3255
+ throw new Error('Database not initialized. Call prepareDb first.');
3256
+ }
3257
+ if (!this.sqlocalInstance.reactiveQuery) {
3258
+ throw new Error('Reactive queries not enabled. Initialize SQLocalDrizzle with reactive: true.');
3259
+ }
3260
+ const baseObservable = new Observable((subscriber) => {
3261
+ const reactiveQueryResult = this.sqlocalInstance.reactiveQuery(query);
3262
+ const subscription = reactiveQueryResult.subscribe((data) => {
3263
+ subscriber.next(data);
3264
+ }, (err) => {
3265
+ console.error('[BaseDb.liveQuery] SQLocal reactiveQuery error:', err);
3266
+ subscriber.error(err);
3267
+ });
3268
+ return () => {
3269
+ subscription.unsubscribe();
3270
+ };
3271
+ });
3272
+ // Compare stable JSON snapshots via keySelector. SQLocal may reuse one array reference
3273
+ // and mutate rows in place; comparing (prev, curr) on the same reference makes
3274
+ // JSON.stringify(prev) === JSON.stringify(curr) after mutation and suppresses emissions.
3275
+ return baseObservable.pipe(distinctUntilChanged((a, b) => a === b, (x) => JSON.stringify(x)));
3276
+ }
3277
+ }
3278
+ BaseDb.configure(new BrowserDb());
3279
+
3280
+ const logger = debug("seedSdk:browser:ArweaveClient");
3281
+ // Cached Arweave instance (keyed by gateway so setHost / protocol changes apply)
3282
+ let _arweaveInstance = null;
3283
+ let _arweaveGatewayKey = null;
3284
+ /**
3285
+ * Get or create the Arweave instance for browser
3286
+ */
3287
+ const getArweaveInstance = () => {
3288
+ const gatewayKey = `${BaseArweaveClient.getProtocol()}://${BaseArweaveClient.getHost()}`;
3289
+ if (_arweaveInstance && _arweaveGatewayKey === gatewayKey) {
3290
+ return _arweaveInstance;
3291
+ }
3292
+ _arweaveGatewayKey = gatewayKey;
3293
+ const host = BaseArweaveClient.getArweaveSdkHost();
3294
+ const protocol = BaseArweaveClient.getProtocol();
3295
+ // Handle both ES modules and CommonJS exports from arweave package
3296
+ if ("default" in Arweave && typeof Arweave.default?.init === "function") {
3297
+ _arweaveInstance = Arweave.default.init({
3298
+ host,
3299
+ protocol,
3300
+ });
3301
+ }
3302
+ else {
3303
+ _arweaveInstance = Arweave.init({
3304
+ host,
3305
+ protocol,
3306
+ });
3307
+ }
3308
+ return _arweaveInstance;
3309
+ };
3310
+ class BrowserArweaveClient {
3311
+ getArweaveClient() {
3312
+ return new GraphQLClient(BaseArweaveClient.getEndpoint());
3313
+ }
3314
+ async getTransactionStatus(transactionId) {
3315
+ const url = BaseArweaveClient.getStatusUrl(transactionId);
3316
+ try {
3317
+ const response = await fetch(url);
3318
+ if (response.status === 404) {
3319
+ return {
3320
+ status: 404,
3321
+ confirmed: null,
3322
+ };
3323
+ }
3324
+ if (!response.ok) {
3325
+ return {
3326
+ status: response.status,
3327
+ confirmed: null,
3328
+ };
3329
+ }
3330
+ if (response.body) {
3331
+ await response.body.cancel();
3332
+ }
3333
+ return {
3334
+ status: 200,
3335
+ confirmed: null,
3336
+ };
3337
+ }
3338
+ catch (error) {
3339
+ logger("Error fetching transaction status:", error);
3340
+ return {
3341
+ status: 500,
3342
+ confirmed: null,
3343
+ };
3344
+ }
3345
+ }
3346
+ async getTransactionData(transactionId, options) {
3347
+ // Path-prefixed proxies (app-server Hyper proxy) are not supported by arweave.init host;
3348
+ // fetch via getRawUrl so /api/seed-gateway/... works.
3349
+ if (BaseArweaveClient.getGatewayPath()) {
3350
+ const response = await fetch(BaseArweaveClient.getRawUrl(transactionId));
3351
+ if (!response.ok) {
3352
+ throw new Error(`Failed to fetch transaction data: HTTP ${response.status}`);
3353
+ }
3354
+ if (options?.string) {
3355
+ return response.text();
3356
+ }
3357
+ return new Uint8Array(await response.arrayBuffer());
3358
+ }
3359
+ const arweave = getArweaveInstance();
3360
+ try {
3361
+ const data = await arweave.transactions.getData(transactionId, {
3362
+ decode: options?.decode ?? true,
3363
+ string: options?.string ?? false,
3364
+ });
3365
+ if (options?.string && typeof data === "string") {
3366
+ return data;
3367
+ }
3368
+ // Ensure we return Uint8Array
3369
+ if (data instanceof Uint8Array) {
3370
+ return data;
3371
+ }
3372
+ // Handle string data when not requesting string
3373
+ if (typeof data === "string") {
3374
+ return new TextEncoder().encode(data);
3375
+ }
3376
+ return data;
3377
+ }
3378
+ catch (error) {
3379
+ logger("Error fetching transaction data:", error);
3380
+ throw error;
3381
+ }
3382
+ }
3383
+ async getTransactionTags(transactionId) {
3384
+ const client = this.getArweaveClient();
3385
+ try {
3386
+ const result = await client.request(GET_TRANSACTION_TAGS, { transactionId });
3387
+ if (!result.tags?.tags) {
3388
+ return [];
3389
+ }
3390
+ return result.tags.tags.map((tag) => ({
3391
+ name: tag.name,
3392
+ value: tag.value,
3393
+ }));
3394
+ }
3395
+ catch (error) {
3396
+ logger("Error fetching transaction tags:", error);
3397
+ return [];
3398
+ }
3399
+ }
3400
+ async createTransaction(data, options) {
3401
+ const arweave = getArweaveInstance();
3402
+ const tx = await arweave.createTransaction({
3403
+ data,
3404
+ });
3405
+ // Add tags if provided
3406
+ if (options?.tags) {
3407
+ for (const tag of options.tags) {
3408
+ tx.addTag(tag.name, tag.value);
3409
+ }
3410
+ }
3411
+ return tx;
3412
+ }
3413
+ async downloadFiles(params) {
3414
+ const { transactionIds, excludedTransactions } = params;
3415
+ const results = [];
3416
+ const baseUrl = BaseArweaveClient.getBaseUrl();
3417
+ for (const transactionId of transactionIds) {
3418
+ // Skip excluded transactions
3419
+ if (excludedTransactions?.has(transactionId)) {
3420
+ continue;
3421
+ }
3422
+ try {
3423
+ const url = `${baseUrl}/raw/${transactionId}`;
3424
+ const response = await fetch(url);
3425
+ if (!response.ok) {
3426
+ results.push({
3427
+ transactionId,
3428
+ success: false,
3429
+ error: `HTTP ${response.status}: ${response.statusText}`,
3430
+ });
3431
+ continue;
3432
+ }
3433
+ const arrayBuffer = await response.arrayBuffer();
3434
+ const data = new Uint8Array(arrayBuffer);
3435
+ // Detect content type
3436
+ const contentType = response.headers.get("content-type") || undefined;
3437
+ results.push({
3438
+ transactionId,
3439
+ success: true,
3440
+ contentType,
3441
+ data,
3442
+ });
3443
+ }
3444
+ catch (error) {
3445
+ logger(`Error downloading transaction ${transactionId}:`, error);
3446
+ results.push({
3447
+ transactionId,
3448
+ success: false,
3449
+ error: error instanceof Error ? error.message : String(error),
3450
+ });
3451
+ }
3452
+ }
3453
+ return results;
3454
+ }
3455
+ }
3456
+ BaseArweaveClient.configure(new BrowserArweaveClient());
3457
+
3458
+ class BrowserEasClient {
3459
+ getEasClient() {
3460
+ if (!this.easClient) {
3461
+ this.easClient = new GraphQLClient(EAS_ENDPOINT);
3462
+ }
3463
+ return this.easClient;
3464
+ }
3465
+ }
3466
+ BaseEasClient.configure(new BrowserEasClient());
3467
+
3468
+ class BrowserQueryClient {
3469
+ getQueryClient() {
3470
+ const reactQueryClient = new QueryClient({
3471
+ defaultOptions: {
3472
+ queries: {
3473
+ networkMode: 'offlineFirst',
3474
+ gcTime: 1000 * 60 * 60 * 24, // 24 hours
3475
+ },
3476
+ },
3477
+ });
3478
+ const queryClient = {
3479
+ fetchQuery: async (options) => {
3480
+ const { queryKey, queryFn, networkMode, staleTime } = options;
3481
+ return reactQueryClient.fetchQuery({
3482
+ queryKey,
3483
+ queryFn,
3484
+ networkMode: networkMode,
3485
+ staleTime,
3486
+ });
3487
+ },
3488
+ getQueryData: (queryKey) => {
3489
+ return reactQueryClient.getQueryData(queryKey);
3490
+ },
3491
+ removeQueries: async (filters) => {
3492
+ await reactQueryClient.removeQueries(filters);
3493
+ },
3494
+ };
3495
+ return queryClient;
3496
+ }
3497
+ }
3498
+ BaseQueryClient.configure(new BrowserQueryClient());
3499
+
3500
+ function createPlatformServices() {
3501
+ return {
3502
+ pathResolver: new BrowserPathResolver(),
3503
+ fileManager: new BrowserFileManager(),
3504
+ db: new BrowserDb(),
3505
+ arweaveClient: new BrowserArweaveClient(),
3506
+ easClient: new BrowserEasClient(),
3507
+ queryClient: new BrowserQueryClient(),
3508
+ };
3509
+ }
3510
+
3511
+ export { createPlatformServices };
3512
+ //# sourceMappingURL=platform.browser.js.map