@bsv/wallet-toolbox-client 2.1.23 → 2.1.25

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 (504) hide show
  1. package/out/src/CWIStyleWalletManager.d.ts +33 -7
  2. package/out/src/CWIStyleWalletManager.d.ts.map +1 -1
  3. package/out/src/CWIStyleWalletManager.js +281 -313
  4. package/out/src/CWIStyleWalletManager.js.map +1 -1
  5. package/out/src/SetupClient.d.ts +6 -6
  6. package/out/src/SetupClient.d.ts.map +1 -1
  7. package/out/src/SetupClient.js +5 -5
  8. package/out/src/SetupClient.js.map +1 -1
  9. package/out/src/SetupWallet.d.ts.map +1 -1
  10. package/out/src/SimpleWalletManager.d.ts +12 -2
  11. package/out/src/SimpleWalletManager.d.ts.map +1 -1
  12. package/out/src/SimpleWalletManager.js +46 -30
  13. package/out/src/SimpleWalletManager.js.map +1 -1
  14. package/out/src/Wallet.d.ts +1 -1
  15. package/out/src/Wallet.d.ts.map +1 -1
  16. package/out/src/Wallet.js +102 -100
  17. package/out/src/Wallet.js.map +1 -1
  18. package/out/src/WalletAuthenticationManager.d.ts +1 -1
  19. package/out/src/WalletAuthenticationManager.d.ts.map +1 -1
  20. package/out/src/WalletAuthenticationManager.js +3 -3
  21. package/out/src/WalletAuthenticationManager.js.map +1 -1
  22. package/out/src/WalletLogger.d.ts.map +1 -1
  23. package/out/src/WalletLogger.js +16 -8
  24. package/out/src/WalletLogger.js.map +1 -1
  25. package/out/src/WalletPermissionsManager.d.ts +89 -18
  26. package/out/src/WalletPermissionsManager.d.ts.map +1 -1
  27. package/out/src/WalletPermissionsManager.js +656 -870
  28. package/out/src/WalletPermissionsManager.js.map +1 -1
  29. package/out/src/WalletSettingsManager.d.ts +2 -2
  30. package/out/src/WalletSettingsManager.d.ts.map +1 -1
  31. package/out/src/WalletSettingsManager.js.map +1 -1
  32. package/out/src/fundWalletP2PKH.d.ts +2 -2
  33. package/out/src/fundWalletP2PKH.d.ts.map +1 -1
  34. package/out/src/fundWalletP2PKH.js +11 -10
  35. package/out/src/fundWalletP2PKH.js.map +1 -1
  36. package/out/src/mockchain/MockChainMigrations.d.ts +3 -3
  37. package/out/src/mockchain/MockChainMigrations.d.ts.map +1 -1
  38. package/out/src/mockchain/MockChainMigrations.js.map +1 -1
  39. package/out/src/mockchain/MockChainStorage.d.ts.map +1 -1
  40. package/out/src/mockchain/MockChainStorage.js +5 -5
  41. package/out/src/mockchain/MockChainStorage.js.map +1 -1
  42. package/out/src/mockchain/MockChainTracker.d.ts.map +1 -1
  43. package/out/src/mockchain/MockChainTracker.js +10 -10
  44. package/out/src/mockchain/MockChainTracker.js.map +1 -1
  45. package/out/src/mockchain/MockMiner.d.ts.map +1 -1
  46. package/out/src/mockchain/MockMiner.js +3 -3
  47. package/out/src/mockchain/MockMiner.js.map +1 -1
  48. package/out/src/mockchain/MockServices.d.ts +9 -0
  49. package/out/src/mockchain/MockServices.d.ts.map +1 -1
  50. package/out/src/mockchain/MockServices.js +195 -238
  51. package/out/src/mockchain/MockServices.js.map +1 -1
  52. package/out/src/mockchain/merkleTree.d.ts.map +1 -1
  53. package/out/src/mockchain/merkleTree.js +21 -12
  54. package/out/src/mockchain/merkleTree.js.map +1 -1
  55. package/out/src/monitor/Monitor.d.ts +17 -0
  56. package/out/src/monitor/Monitor.d.ts.map +1 -1
  57. package/out/src/monitor/Monitor.js +56 -75
  58. package/out/src/monitor/Monitor.js.map +1 -1
  59. package/out/src/monitor/tasks/TaskArcSSE.d.ts +2 -2
  60. package/out/src/monitor/tasks/TaskArcSSE.d.ts.map +1 -1
  61. package/out/src/monitor/tasks/TaskArcSSE.js +10 -23
  62. package/out/src/monitor/tasks/TaskArcSSE.js.map +1 -1
  63. package/out/src/monitor/tasks/TaskCheckForProofs.d.ts +2 -2
  64. package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
  65. package/out/src/monitor/tasks/TaskCheckForProofs.js +28 -16
  66. package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
  67. package/out/src/monitor/tasks/TaskCheckNoSends.d.ts +1 -1
  68. package/out/src/monitor/tasks/TaskCheckNoSends.d.ts.map +1 -1
  69. package/out/src/monitor/tasks/TaskCheckNoSends.js +1 -2
  70. package/out/src/monitor/tasks/TaskCheckNoSends.js.map +1 -1
  71. package/out/src/monitor/tasks/TaskClock.d.ts +1 -1
  72. package/out/src/monitor/tasks/TaskClock.d.ts.map +1 -1
  73. package/out/src/monitor/tasks/TaskClock.js +0 -1
  74. package/out/src/monitor/tasks/TaskClock.js.map +1 -1
  75. package/out/src/monitor/tasks/TaskFailAbandoned.d.ts +1 -1
  76. package/out/src/monitor/tasks/TaskFailAbandoned.d.ts.map +1 -1
  77. package/out/src/monitor/tasks/TaskFailAbandoned.js.map +1 -1
  78. package/out/src/monitor/tasks/TaskMineBlock.d.ts +1 -1
  79. package/out/src/monitor/tasks/TaskMineBlock.d.ts.map +1 -1
  80. package/out/src/monitor/tasks/TaskMineBlock.js.map +1 -1
  81. package/out/src/monitor/tasks/TaskMonitorCallHistory.d.ts +1 -1
  82. package/out/src/monitor/tasks/TaskMonitorCallHistory.d.ts.map +1 -1
  83. package/out/src/monitor/tasks/TaskMonitorCallHistory.js +1 -1
  84. package/out/src/monitor/tasks/TaskMonitorCallHistory.js.map +1 -1
  85. package/out/src/monitor/tasks/TaskNewHeader.d.ts +2 -2
  86. package/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -1
  87. package/out/src/monitor/tasks/TaskNewHeader.js +7 -5
  88. package/out/src/monitor/tasks/TaskNewHeader.js.map +1 -1
  89. package/out/src/monitor/tasks/TaskPurge.d.ts +1 -1
  90. package/out/src/monitor/tasks/TaskPurge.d.ts.map +1 -1
  91. package/out/src/monitor/tasks/TaskPurge.js.map +1 -1
  92. package/out/src/monitor/tasks/TaskReorg.d.ts +1 -1
  93. package/out/src/monitor/tasks/TaskReorg.d.ts.map +1 -1
  94. package/out/src/monitor/tasks/TaskReorg.js +2 -2
  95. package/out/src/monitor/tasks/TaskReorg.js.map +1 -1
  96. package/out/src/monitor/tasks/TaskReviewDoubleSpends.d.ts +1 -1
  97. package/out/src/monitor/tasks/TaskReviewDoubleSpends.d.ts.map +1 -1
  98. package/out/src/monitor/tasks/TaskReviewDoubleSpends.js +10 -10
  99. package/out/src/monitor/tasks/TaskReviewDoubleSpends.js.map +1 -1
  100. package/out/src/monitor/tasks/TaskReviewProvenTxs.d.ts +1 -1
  101. package/out/src/monitor/tasks/TaskReviewProvenTxs.d.ts.map +1 -1
  102. package/out/src/monitor/tasks/TaskReviewProvenTxs.js +2 -2
  103. package/out/src/monitor/tasks/TaskReviewProvenTxs.js.map +1 -1
  104. package/out/src/monitor/tasks/TaskReviewStatus.d.ts +1 -1
  105. package/out/src/monitor/tasks/TaskReviewStatus.d.ts.map +1 -1
  106. package/out/src/monitor/tasks/TaskReviewStatus.js.map +1 -1
  107. package/out/src/monitor/tasks/TaskReviewUtxos.d.ts +1 -1
  108. package/out/src/monitor/tasks/TaskReviewUtxos.d.ts.map +1 -1
  109. package/out/src/monitor/tasks/TaskReviewUtxos.js.map +1 -1
  110. package/out/src/monitor/tasks/TaskSendWaiting.d.ts +1 -1
  111. package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
  112. package/out/src/monitor/tasks/TaskSendWaiting.js +4 -5
  113. package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
  114. package/out/src/monitor/tasks/TaskUnFail.d.ts +1 -1
  115. package/out/src/monitor/tasks/TaskUnFail.d.ts.map +1 -1
  116. package/out/src/monitor/tasks/TaskUnFail.js +13 -15
  117. package/out/src/monitor/tasks/TaskUnFail.js.map +1 -1
  118. package/out/src/monitor/tasks/WalletMonitorTask.d.ts.map +1 -1
  119. package/out/src/monitor/tasks/WalletMonitorTask.js +3 -1
  120. package/out/src/monitor/tasks/WalletMonitorTask.js.map +1 -1
  121. package/out/src/sdk/CertOpsWallet.d.ts +3 -3
  122. package/out/src/sdk/CertOpsWallet.d.ts.map +1 -1
  123. package/out/src/sdk/PrivilegedKeyManager.d.ts +3 -3
  124. package/out/src/sdk/PrivilegedKeyManager.d.ts.map +1 -1
  125. package/out/src/sdk/PrivilegedKeyManager.js +26 -21
  126. package/out/src/sdk/PrivilegedKeyManager.js.map +1 -1
  127. package/out/src/sdk/WERR_errors.d.ts.map +1 -1
  128. package/out/src/sdk/WERR_errors.js +5 -5
  129. package/out/src/sdk/WERR_errors.js.map +1 -1
  130. package/out/src/sdk/WalletError.d.ts +1 -1
  131. package/out/src/sdk/WalletError.d.ts.map +1 -1
  132. package/out/src/sdk/WalletError.js +10 -3
  133. package/out/src/sdk/WalletError.js.map +1 -1
  134. package/out/src/sdk/WalletErrorFromJson.d.ts.map +1 -1
  135. package/out/src/sdk/WalletErrorFromJson.js +1 -3
  136. package/out/src/sdk/WalletErrorFromJson.js.map +1 -1
  137. package/out/src/sdk/WalletServices.interfaces.d.ts +19 -19
  138. package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
  139. package/out/src/sdk/types.d.ts +4 -4
  140. package/out/src/sdk/types.d.ts.map +1 -1
  141. package/out/src/sdk/types.js +3 -3
  142. package/out/src/sdk/types.js.map +1 -1
  143. package/out/src/services/ServiceCollection.d.ts +6 -6
  144. package/out/src/services/ServiceCollection.d.ts.map +1 -1
  145. package/out/src/services/ServiceCollection.js +3 -4
  146. package/out/src/services/ServiceCollection.js.map +1 -1
  147. package/out/src/services/Services.d.ts +5 -0
  148. package/out/src/services/Services.d.ts.map +1 -1
  149. package/out/src/services/Services.js +174 -182
  150. package/out/src/services/Services.js.map +1 -1
  151. package/out/src/services/chaintracker/BHServiceClient.d.ts.map +1 -1
  152. package/out/src/services/chaintracker/BHServiceClient.js +7 -7
  153. package/out/src/services/chaintracker/BHServiceClient.js.map +1 -1
  154. package/out/src/services/chaintracker/ChaintracksChainTracker.d.ts.map +1 -1
  155. package/out/src/services/chaintracker/ChaintracksChainTracker.js +5 -5
  156. package/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -1
  157. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts +5 -3
  158. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts.map +1 -1
  159. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.js.map +1 -1
  160. package/out/src/services/chaintracker/chaintracks/Api/BulkStorageApi.d.ts.map +1 -1
  161. package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts +20 -10
  162. package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts.map +1 -1
  163. package/out/src/services/chaintracker/chaintracks/Chaintracks.js +228 -221
  164. package/out/src/services/chaintracker/chaintracks/Chaintracks.js.map +1 -1
  165. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -1
  166. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js +9 -10
  167. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js.map +1 -1
  168. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.d.ts.map +1 -1
  169. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.js +1 -1
  170. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.js.map +1 -1
  171. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts +1 -2
  172. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts.map +1 -1
  173. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js +3 -3
  174. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js.map +1 -1
  175. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.d.ts.map +1 -1
  176. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.js.map +1 -1
  177. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.d.ts.map +1 -1
  178. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.js +3 -3
  179. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.js.map +1 -1
  180. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.d.ts.map +1 -1
  181. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.js +1 -1
  182. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.js.map +1 -1
  183. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
  184. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +2 -2
  185. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
  186. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.d.ts +2 -2
  187. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.d.ts.map +1 -1
  188. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.js +6 -39
  189. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.js.map +1 -1
  190. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts +3 -3
  191. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts.map +1 -1
  192. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js +8 -6
  193. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js.map +1 -1
  194. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.d.ts.map +1 -1
  195. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.js +9 -16
  196. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.js.map +1 -1
  197. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.d.ts.map +1 -1
  198. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js +34 -22
  199. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js.map +1 -1
  200. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.d.ts.map +1 -1
  201. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js +31 -30
  202. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js.map +1 -1
  203. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts +2 -2
  204. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts.map +1 -1
  205. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js +11 -10
  206. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js.map +1 -1
  207. package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts.map +1 -1
  208. package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts.map +1 -1
  209. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts +6 -1
  210. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts.map +1 -1
  211. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js +247 -227
  212. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js.map +1 -1
  213. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.d.ts.map +1 -1
  214. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.js +8 -7
  215. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.js.map +1 -1
  216. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.d.ts.map +1 -1
  217. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js +35 -25
  218. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js.map +1 -1
  219. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.d.ts +5 -5
  220. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.d.ts.map +1 -1
  221. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.js +13 -11
  222. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.js.map +1 -1
  223. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts +0 -1
  224. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts.map +1 -1
  225. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js.map +1 -1
  226. package/out/src/services/chaintracker/chaintracks/util/HeightRange.d.ts.map +1 -1
  227. package/out/src/services/chaintracker/chaintracks/util/HeightRange.js +21 -13
  228. package/out/src/services/chaintracker/chaintracks/util/HeightRange.js.map +1 -1
  229. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts +2 -2
  230. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts.map +1 -1
  231. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.js.map +1 -1
  232. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts +1 -1
  233. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts.map +1 -1
  234. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js +28 -24
  235. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js.map +1 -1
  236. package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.d.ts.map +1 -1
  237. package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.js.map +1 -1
  238. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.d.ts.map +1 -1
  239. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js +9 -10
  240. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js.map +1 -1
  241. package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
  242. package/out/src/services/createDefaultWalletServicesOptions.js +3 -3
  243. package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
  244. package/out/src/services/providers/ARC.d.ts.map +1 -1
  245. package/out/src/services/providers/ARC.js +7 -14
  246. package/out/src/services/providers/ARC.js.map +1 -1
  247. package/out/src/services/providers/ArcSSEClient.d.ts.map +1 -1
  248. package/out/src/services/providers/ArcSSEClient.js +1 -1
  249. package/out/src/services/providers/ArcSSEClient.js.map +1 -1
  250. package/out/src/services/providers/Bitails.d.ts.map +1 -1
  251. package/out/src/services/providers/Bitails.js +17 -17
  252. package/out/src/services/providers/Bitails.js.map +1 -1
  253. package/out/src/services/providers/SdkWhatsOnChain.d.ts.map +1 -1
  254. package/out/src/services/providers/SdkWhatsOnChain.js.map +1 -1
  255. package/out/src/services/providers/WhatsOnChain.d.ts +2 -0
  256. package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
  257. package/out/src/services/providers/WhatsOnChain.js +109 -233
  258. package/out/src/services/providers/WhatsOnChain.js.map +1 -1
  259. package/out/src/services/providers/exchangeRates.d.ts.map +1 -1
  260. package/out/src/services/providers/exchangeRates.js +3 -3
  261. package/out/src/services/providers/exchangeRates.js.map +1 -1
  262. package/out/src/services/providers/getBeefForTxid.d.ts +1 -1
  263. package/out/src/services/providers/getBeefForTxid.d.ts.map +1 -1
  264. package/out/src/services/providers/getBeefForTxid.js.map +1 -1
  265. package/out/src/services/providers/whatsOnChainHelpers.d.ts +68 -0
  266. package/out/src/services/providers/whatsOnChainHelpers.d.ts.map +1 -0
  267. package/out/src/services/providers/whatsOnChainHelpers.js +147 -0
  268. package/out/src/services/providers/whatsOnChainHelpers.js.map +1 -0
  269. package/out/src/signer/WalletSigner.d.ts.map +1 -1
  270. package/out/src/signer/WalletSigner.js.map +1 -1
  271. package/out/src/signer/methods/acquireDirectCertificate.js +1 -1
  272. package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
  273. package/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
  274. package/out/src/signer/methods/buildSignableTransaction.js +21 -13
  275. package/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
  276. package/out/src/signer/methods/completeSignedTransaction.d.ts.map +1 -1
  277. package/out/src/signer/methods/completeSignedTransaction.js +20 -21
  278. package/out/src/signer/methods/completeSignedTransaction.js.map +1 -1
  279. package/out/src/signer/methods/createAction.d.ts.map +1 -1
  280. package/out/src/signer/methods/createAction.js +8 -7
  281. package/out/src/signer/methods/createAction.js.map +1 -1
  282. package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
  283. package/out/src/signer/methods/internalizeAction.js +8 -6
  284. package/out/src/signer/methods/internalizeAction.js.map +1 -1
  285. package/out/src/signer/methods/proveCertificate.js +1 -1
  286. package/out/src/signer/methods/signAction.d.ts.map +1 -1
  287. package/out/src/signer/methods/signAction.js +8 -10
  288. package/out/src/signer/methods/signAction.js.map +1 -1
  289. package/out/src/storage/StorageIdb.d.ts +16 -1
  290. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  291. package/out/src/storage/StorageIdb.js +536 -1221
  292. package/out/src/storage/StorageIdb.js.map +1 -1
  293. package/out/src/storage/StorageProvider.d.ts +10 -0
  294. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  295. package/out/src/storage/StorageProvider.js +152 -182
  296. package/out/src/storage/StorageProvider.js.map +1 -1
  297. package/out/src/storage/StorageReader.d.ts.map +1 -1
  298. package/out/src/storage/StorageReader.js +8 -7
  299. package/out/src/storage/StorageReader.js.map +1 -1
  300. package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
  301. package/out/src/storage/StorageReaderWriter.js +32 -32
  302. package/out/src/storage/StorageReaderWriter.js.map +1 -1
  303. package/out/src/storage/StorageSyncReader.d.ts.map +1 -1
  304. package/out/src/storage/StorageSyncReader.js +3 -3
  305. package/out/src/storage/StorageSyncReader.js.map +1 -1
  306. package/out/src/storage/WalletStorageManager.d.ts +3 -0
  307. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  308. package/out/src/storage/WalletStorageManager.js +83 -73
  309. package/out/src/storage/WalletStorageManager.js.map +1 -1
  310. package/out/src/storage/idbHelpers.d.ts +42 -0
  311. package/out/src/storage/idbHelpers.d.ts.map +1 -0
  312. package/out/src/storage/idbHelpers.js +375 -0
  313. package/out/src/storage/idbHelpers.js.map +1 -0
  314. package/out/src/storage/methods/ListActionsSpecOp.d.ts +6 -1
  315. package/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -1
  316. package/out/src/storage/methods/ListActionsSpecOp.js +28 -2
  317. package/out/src/storage/methods/ListActionsSpecOp.js.map +1 -1
  318. package/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
  319. package/out/src/storage/methods/ListOutputsSpecOp.js +8 -11
  320. package/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
  321. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +83 -0
  322. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
  323. package/out/src/storage/methods/attemptToPostReqsToNetwork.js +224 -61
  324. package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  325. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  326. package/out/src/storage/methods/createAction.js +230 -270
  327. package/out/src/storage/methods/createAction.js.map +1 -1
  328. package/out/src/storage/methods/generateChange.d.ts.map +1 -1
  329. package/out/src/storage/methods/generateChange.js +99 -80
  330. package/out/src/storage/methods/generateChange.js.map +1 -1
  331. package/out/src/storage/methods/getBeefForTransaction.js +15 -13
  332. package/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
  333. package/out/src/storage/methods/getSyncChunk.d.ts.map +1 -1
  334. package/out/src/storage/methods/getSyncChunk.js +4 -3
  335. package/out/src/storage/methods/getSyncChunk.js.map +1 -1
  336. package/out/src/storage/methods/internalizeAction.js +41 -51
  337. package/out/src/storage/methods/internalizeAction.js.map +1 -1
  338. package/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
  339. package/out/src/storage/methods/listActionsIdb.js +85 -110
  340. package/out/src/storage/methods/listActionsIdb.js.map +1 -1
  341. package/out/src/storage/methods/listCertificates.d.ts +1 -1
  342. package/out/src/storage/methods/listCertificates.d.ts.map +1 -1
  343. package/out/src/storage/methods/listCertificates.js +7 -7
  344. package/out/src/storage/methods/listCertificates.js.map +1 -1
  345. package/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
  346. package/out/src/storage/methods/listOutputsIdb.js +24 -27
  347. package/out/src/storage/methods/listOutputsIdb.js.map +1 -1
  348. package/out/src/storage/methods/offsetKey.d.ts +1 -1
  349. package/out/src/storage/methods/offsetKey.d.ts.map +1 -1
  350. package/out/src/storage/methods/offsetKey.js +3 -5
  351. package/out/src/storage/methods/offsetKey.js.map +1 -1
  352. package/out/src/storage/methods/processAction.d.ts +0 -11
  353. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  354. package/out/src/storage/methods/processAction.js +90 -83
  355. package/out/src/storage/methods/processAction.js.map +1 -1
  356. package/out/src/storage/methods/purgeDataIdb.d.ts.map +1 -1
  357. package/out/src/storage/methods/purgeDataIdb.js +1 -1
  358. package/out/src/storage/methods/purgeDataIdb.js.map +1 -1
  359. package/out/src/storage/methods/reviewStatusIdb.d.ts +1 -1
  360. package/out/src/storage/methods/reviewStatusIdb.d.ts.map +1 -1
  361. package/out/src/storage/methods/reviewStatusIdb.js.map +1 -1
  362. package/out/src/storage/methods/utils.d.ts.map +1 -1
  363. package/out/src/storage/methods/utils.js +7 -1
  364. package/out/src/storage/methods/utils.js.map +1 -1
  365. package/out/src/storage/remoting/StorageClient.d.ts +4 -270
  366. package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
  367. package/out/src/storage/remoting/StorageClient.js +16 -423
  368. package/out/src/storage/remoting/StorageClient.js.map +1 -1
  369. package/out/src/storage/remoting/StorageClientBase.d.ts +289 -0
  370. package/out/src/storage/remoting/StorageClientBase.d.ts.map +1 -0
  371. package/out/src/storage/remoting/StorageClientBase.js +375 -0
  372. package/out/src/storage/remoting/StorageClientBase.js.map +1 -0
  373. package/out/src/storage/remoting/entityValidationHelpers.d.ts +29 -0
  374. package/out/src/storage/remoting/entityValidationHelpers.d.ts.map +1 -0
  375. package/out/src/storage/remoting/entityValidationHelpers.js +91 -0
  376. package/out/src/storage/remoting/entityValidationHelpers.js.map +1 -0
  377. package/out/src/storage/schema/StorageIdbSchema.d.ts +1 -1
  378. package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
  379. package/out/src/storage/schema/entities/EntityBase.d.ts.map +1 -1
  380. package/out/src/storage/schema/entities/EntityBase.js.map +1 -1
  381. package/out/src/storage/schema/entities/EntityCertificate.d.ts.map +1 -1
  382. package/out/src/storage/schema/entities/EntityCertificate.js +5 -4
  383. package/out/src/storage/schema/entities/EntityCertificate.js.map +1 -1
  384. package/out/src/storage/schema/entities/EntityCertificateField.d.ts.map +1 -1
  385. package/out/src/storage/schema/entities/EntityCertificateField.js +5 -7
  386. package/out/src/storage/schema/entities/EntityCertificateField.js.map +1 -1
  387. package/out/src/storage/schema/entities/EntityCommission.d.ts.map +1 -1
  388. package/out/src/storage/schema/entities/EntityCommission.js +6 -8
  389. package/out/src/storage/schema/entities/EntityCommission.js.map +1 -1
  390. package/out/src/storage/schema/entities/EntityOutput.d.ts.map +1 -1
  391. package/out/src/storage/schema/entities/EntityOutput.js +21 -24
  392. package/out/src/storage/schema/entities/EntityOutput.js.map +1 -1
  393. package/out/src/storage/schema/entities/EntityOutputBasket.d.ts.map +1 -1
  394. package/out/src/storage/schema/entities/EntityOutputBasket.js +6 -6
  395. package/out/src/storage/schema/entities/EntityOutputBasket.js.map +1 -1
  396. package/out/src/storage/schema/entities/EntityOutputTag.d.ts.map +1 -1
  397. package/out/src/storage/schema/entities/EntityOutputTag.js +2 -2
  398. package/out/src/storage/schema/entities/EntityOutputTag.js.map +1 -1
  399. package/out/src/storage/schema/entities/EntityOutputTagMap.d.ts.map +1 -1
  400. package/out/src/storage/schema/entities/EntityOutputTagMap.js +4 -6
  401. package/out/src/storage/schema/entities/EntityOutputTagMap.js.map +1 -1
  402. package/out/src/storage/schema/entities/EntityProvenTx.d.ts +3 -3
  403. package/out/src/storage/schema/entities/EntityProvenTx.d.ts.map +1 -1
  404. package/out/src/storage/schema/entities/EntityProvenTx.js +22 -23
  405. package/out/src/storage/schema/entities/EntityProvenTx.js.map +1 -1
  406. package/out/src/storage/schema/entities/EntityProvenTxReq.d.ts +9 -0
  407. package/out/src/storage/schema/entities/EntityProvenTxReq.d.ts.map +1 -1
  408. package/out/src/storage/schema/entities/EntityProvenTxReq.js +116 -68
  409. package/out/src/storage/schema/entities/EntityProvenTxReq.js.map +1 -1
  410. package/out/src/storage/schema/entities/EntitySyncState.d.ts.map +1 -1
  411. package/out/src/storage/schema/entities/EntitySyncState.js +19 -18
  412. package/out/src/storage/schema/entities/EntitySyncState.js.map +1 -1
  413. package/out/src/storage/schema/entities/EntityTransaction.d.ts.map +1 -1
  414. package/out/src/storage/schema/entities/EntityTransaction.js +25 -26
  415. package/out/src/storage/schema/entities/EntityTransaction.js.map +1 -1
  416. package/out/src/storage/schema/entities/EntityTxLabel.d.ts.map +1 -1
  417. package/out/src/storage/schema/entities/EntityTxLabel.js +2 -2
  418. package/out/src/storage/schema/entities/EntityTxLabel.js.map +1 -1
  419. package/out/src/storage/schema/entities/EntityTxLabelMap.d.ts.map +1 -1
  420. package/out/src/storage/schema/entities/EntityTxLabelMap.js +4 -6
  421. package/out/src/storage/schema/entities/EntityTxLabelMap.js.map +1 -1
  422. package/out/src/storage/schema/entities/EntityUser.d.ts.map +1 -1
  423. package/out/src/storage/schema/entities/EntityUser.js +3 -3
  424. package/out/src/storage/schema/entities/EntityUser.js.map +1 -1
  425. package/out/src/storage/schema/entities/MergeEntity.d.ts.map +1 -1
  426. package/out/src/storage/schema/entities/MergeEntity.js +6 -6
  427. package/out/src/storage/schema/entities/MergeEntity.js.map +1 -1
  428. package/out/src/storage/schema/tables/TableCertificate.d.ts +2 -1
  429. package/out/src/storage/schema/tables/TableCertificate.d.ts.map +1 -1
  430. package/out/src/storage/schema/tables/TableCertificateField.d.ts +1 -1
  431. package/out/src/storage/schema/tables/TableCertificateField.d.ts.map +1 -1
  432. package/out/src/storage/schema/tables/TableCommission.d.ts +1 -1
  433. package/out/src/storage/schema/tables/TableCommission.d.ts.map +1 -1
  434. package/out/src/storage/schema/tables/TableMonitorEvent.d.ts +1 -1
  435. package/out/src/storage/schema/tables/TableMonitorEvent.d.ts.map +1 -1
  436. package/out/src/storage/schema/tables/TableOutput.d.ts +3 -2
  437. package/out/src/storage/schema/tables/TableOutput.d.ts.map +1 -1
  438. package/out/src/storage/schema/tables/TableOutput.js +1 -1
  439. package/out/src/storage/schema/tables/TableOutput.js.map +1 -1
  440. package/out/src/storage/schema/tables/TableOutputBasket.d.ts +1 -1
  441. package/out/src/storage/schema/tables/TableOutputBasket.d.ts.map +1 -1
  442. package/out/src/storage/schema/tables/TableOutputTag.d.ts +1 -1
  443. package/out/src/storage/schema/tables/TableOutputTag.d.ts.map +1 -1
  444. package/out/src/storage/schema/tables/TableOutputTagMap.d.ts +1 -1
  445. package/out/src/storage/schema/tables/TableOutputTagMap.d.ts.map +1 -1
  446. package/out/src/storage/schema/tables/TableProvenTx.d.ts +1 -1
  447. package/out/src/storage/schema/tables/TableProvenTx.d.ts.map +1 -1
  448. package/out/src/storage/schema/tables/TableProvenTxReq.d.ts +24 -1
  449. package/out/src/storage/schema/tables/TableProvenTxReq.d.ts.map +1 -1
  450. package/out/src/storage/schema/tables/TableSettings.d.ts +1 -1
  451. package/out/src/storage/schema/tables/TableSettings.d.ts.map +1 -1
  452. package/out/src/storage/schema/tables/TableSyncState.d.ts +1 -1
  453. package/out/src/storage/schema/tables/TableSyncState.d.ts.map +1 -1
  454. package/out/src/storage/schema/tables/TableTransaction.d.ts +1 -1
  455. package/out/src/storage/schema/tables/TableTransaction.d.ts.map +1 -1
  456. package/out/src/storage/schema/tables/TableTxLabel.d.ts +1 -1
  457. package/out/src/storage/schema/tables/TableTxLabel.d.ts.map +1 -1
  458. package/out/src/storage/schema/tables/TableTxLabelMap.d.ts +1 -1
  459. package/out/src/storage/schema/tables/TableTxLabelMap.d.ts.map +1 -1
  460. package/out/src/storage/schema/tables/TableUser.d.ts +1 -1
  461. package/out/src/storage/schema/tables/TableUser.d.ts.map +1 -1
  462. package/out/src/storage/storageProviderHelpers.d.ts +34 -0
  463. package/out/src/storage/storageProviderHelpers.d.ts.map +1 -0
  464. package/out/src/storage/storageProviderHelpers.js +100 -0
  465. package/out/src/storage/storageProviderHelpers.js.map +1 -0
  466. package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
  467. package/out/src/utility/ScriptTemplateBRC29.js +2 -1
  468. package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
  469. package/out/src/utility/aggregateResults.d.ts +1 -1
  470. package/out/src/utility/aggregateResults.d.ts.map +1 -1
  471. package/out/src/utility/aggregateResults.js +2 -2
  472. package/out/src/utility/aggregateResults.js.map +1 -1
  473. package/out/src/utility/brc114ActionTimeLabels.d.ts +2 -2
  474. package/out/src/utility/brc114ActionTimeLabels.d.ts.map +1 -1
  475. package/out/src/utility/brc114ActionTimeLabels.js +16 -9
  476. package/out/src/utility/brc114ActionTimeLabels.js.map +1 -1
  477. package/out/src/utility/identityUtils.js +1 -1
  478. package/out/src/utility/identityUtils.js.map +1 -1
  479. package/out/src/utility/parseTxScriptOffsets.d.ts +4 -4
  480. package/out/src/utility/parseTxScriptOffsets.d.ts.map +1 -1
  481. package/out/src/utility/parseTxScriptOffsets.js.map +1 -1
  482. package/out/src/utility/stampLog.d.ts.map +1 -1
  483. package/out/src/utility/stampLog.js +7 -5
  484. package/out/src/utility/stampLog.js.map +1 -1
  485. package/out/src/utility/tscProofToMerklePath.d.ts.map +1 -1
  486. package/out/src/utility/tscProofToMerklePath.js +1 -1
  487. package/out/src/utility/tscProofToMerklePath.js.map +1 -1
  488. package/out/src/utility/utilityHelpers.d.ts +1 -2
  489. package/out/src/utility/utilityHelpers.d.ts.map +1 -1
  490. package/out/src/utility/utilityHelpers.js +10 -10
  491. package/out/src/utility/utilityHelpers.js.map +1 -1
  492. package/out/src/utility/utilityHelpers.noBuffer.d.ts +7 -3
  493. package/out/src/utility/utilityHelpers.noBuffer.d.ts.map +1 -1
  494. package/out/src/utility/utilityHelpers.noBuffer.js +3 -3
  495. package/out/src/utility/utilityHelpers.noBuffer.js.map +1 -1
  496. package/out/src/wab-client/WABClient.d.ts +1 -1
  497. package/out/src/wab-client/WABClient.d.ts.map +1 -1
  498. package/out/src/wab-client/WABClient.js +12 -12
  499. package/out/src/wab-client/WABClient.js.map +1 -1
  500. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.d.ts.map +1 -1
  501. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js +3 -3
  502. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js.map +1 -1
  503. package/out/tsconfig.client.tsbuildinfo +1 -1
  504. package/package.json +7 -6
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageIdb = void 0;
4
4
  const idb_1 = require("idb");
5
+ const idbHelpers_1 = require("./idbHelpers");
5
6
  const utilityHelpers_1 = require("../utility/utilityHelpers");
6
7
  const StorageProvider_1 = require("./StorageProvider");
7
8
  const listActionsIdb_1 = require("./methods/listActionsIdb");
@@ -9,6 +10,39 @@ const listOutputsIdb_1 = require("./methods/listOutputsIdb");
9
10
  const reviewStatusIdb_1 = require("./methods/reviewStatusIdb");
10
11
  const purgeDataIdb_1 = require("./methods/purgeDataIdb");
11
12
  const WERR_errors_1 = require("../sdk/WERR_errors");
13
+ /**
14
+ * Shared cursor-scan loop used by all `filterXxx` methods of StorageIdb.
15
+ *
16
+ * Walks `cursor` forward, applying `since`, a caller-supplied `matches`
17
+ * predicate, paging (offset / limit), and an async `accept` callback for
18
+ * records that pass all filters. Returns the number of accepted records.
19
+ *
20
+ * Implemented as a module-level helper (not a class method) so that
21
+ * profiling/instrumentation that wraps class-prototype methods cannot
22
+ * intercept or mutate its `matches` / `accept` callbacks.
23
+ */
24
+ async function scanCursor(
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ cursor, since, offset, limit, matches, accept) {
27
+ let skipped = 0;
28
+ let count = 0;
29
+ for (; cursor != null; cursor = await cursor.continue()) {
30
+ const r = cursor.value;
31
+ if (since != null && since > r.updated_at)
32
+ continue;
33
+ if (!await matches(r))
34
+ continue;
35
+ if (skipped < offset) {
36
+ skipped++;
37
+ continue;
38
+ }
39
+ accept(r);
40
+ count++;
41
+ if (limit && count >= limit)
42
+ break;
43
+ }
44
+ return count;
45
+ }
12
46
  /**
13
47
  * This class implements the `StorageProvider` interface using IndexedDB,
14
48
  * via the promises wrapper package `idb`.
@@ -61,7 +95,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
61
95
  * @returns
62
96
  */
63
97
  async verifyDB(storageName, storageIdentityKey) {
64
- if (this.db)
98
+ if (this.db != null)
65
99
  return this.db;
66
100
  this.db = await this.initDB(storageName, storageIdentityKey);
67
101
  this._settings = (await this.db.getAll('settings'))[0];
@@ -73,12 +107,12 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
73
107
  * or a Knex.Transaction as appropriate.
74
108
  */
75
109
  toDbTrx(stores, mode, trx) {
76
- if (trx) {
110
+ if (trx != null) {
77
111
  const t = trx;
78
112
  return t;
79
113
  }
80
114
  else {
81
- if (!this.db)
115
+ if (this.db == null)
82
116
  throw new Error('not initialized');
83
117
  const db = this.db;
84
118
  const trx = db.transaction(stores || this.allStores, mode || 'readwrite');
@@ -103,150 +137,13 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
103
137
  const chain = this.chain;
104
138
  const maxOutputScript = 1024;
105
139
  const db = await (0, idb_1.openDB)(this.dbName, 1, {
106
- upgrade(db, oldVersion, newVersion, transaction) {
107
- if (!db.objectStoreNames.contains('proven_txs')) {
108
- // proven_txs object store
109
- const provenTxsStore = db.createObjectStore('proven_txs', {
110
- keyPath: 'provenTxId',
111
- autoIncrement: true
112
- });
113
- provenTxsStore.createIndex('txid', 'txid', { unique: true });
114
- }
115
- if (!db.objectStoreNames.contains('proven_tx_reqs')) {
116
- // proven_tx_reqs object store
117
- const provenTxReqsStore = db.createObjectStore('proven_tx_reqs', {
118
- keyPath: 'provenTxReqId',
119
- autoIncrement: true
120
- });
121
- provenTxReqsStore.createIndex('provenTxId', 'provenTxId');
122
- provenTxReqsStore.createIndex('txid', 'txid', { unique: true });
123
- provenTxReqsStore.createIndex('status', 'status');
124
- provenTxReqsStore.createIndex('batch', 'batch');
125
- }
126
- if (!db.objectStoreNames.contains('users')) {
127
- const users = db.createObjectStore('users', {
128
- keyPath: 'userId',
129
- autoIncrement: true
130
- });
131
- users.createIndex('identityKey', 'identityKey', { unique: true });
132
- }
133
- if (!db.objectStoreNames.contains('certificates')) {
134
- // certificates object store
135
- const certificatesStore = db.createObjectStore('certificates', {
136
- keyPath: 'certificateId',
137
- autoIncrement: true
138
- });
139
- certificatesStore.createIndex('userId', 'userId');
140
- certificatesStore.createIndex('userId_type_certifier_serialNumber', ['userId', 'type', 'certifier', 'serialNumber'], { unique: true });
141
- }
142
- if (!db.objectStoreNames.contains('certificate_fields')) {
143
- // certificate_fields object store
144
- const certificateFieldsStore = db.createObjectStore('certificate_fields', {
145
- keyPath: ['certificateId', 'fieldName'] // Composite key
146
- });
147
- certificateFieldsStore.createIndex('userId', 'userId');
148
- certificateFieldsStore.createIndex('certificateId', 'certificateId');
149
- }
150
- if (!db.objectStoreNames.contains('output_baskets')) {
151
- // output_baskets object store
152
- const outputBasketsStore = db.createObjectStore('output_baskets', {
153
- keyPath: 'basketId',
154
- autoIncrement: true
155
- });
156
- outputBasketsStore.createIndex('userId', 'userId');
157
- outputBasketsStore.createIndex('name_userId', ['name', 'userId'], { unique: true });
158
- }
159
- if (!db.objectStoreNames.contains('transactions')) {
160
- // transactions object store
161
- const transactionsStore = db.createObjectStore('transactions', {
162
- keyPath: 'transactionId',
163
- autoIncrement: true
164
- });
165
- transactionsStore.createIndex('userId', 'userId');
166
- transactionsStore.createIndex('status', 'status');
167
- transactionsStore.createIndex('status_userId', ['status', 'userId']);
168
- transactionsStore.createIndex('provenTxId', 'provenTxId');
169
- transactionsStore.createIndex('reference', 'reference', { unique: true });
170
- }
171
- if (!db.objectStoreNames.contains('commissions')) {
172
- // commissions object store
173
- const commissionsStore = db.createObjectStore('commissions', {
174
- keyPath: 'commissionId',
175
- autoIncrement: true
176
- });
177
- commissionsStore.createIndex('userId', 'userId');
178
- commissionsStore.createIndex('transactionId', 'transactionId', { unique: true });
179
- }
180
- if (!db.objectStoreNames.contains('outputs')) {
181
- // outputs object store
182
- const outputsStore = db.createObjectStore('outputs', {
183
- keyPath: 'outputId',
184
- autoIncrement: true
185
- });
186
- outputsStore.createIndex('userId', 'userId');
187
- outputsStore.createIndex('transactionId', 'transactionId');
188
- outputsStore.createIndex('basketId', 'basketId');
189
- outputsStore.createIndex('spentBy', 'spentBy');
190
- outputsStore.createIndex('transactionId_vout_userId', ['transactionId', 'vout', 'userId'], { unique: true });
191
- }
192
- if (!db.objectStoreNames.contains('output_tags')) {
193
- // output_tags object store
194
- const outputTagsStore = db.createObjectStore('output_tags', {
195
- keyPath: 'outputTagId',
196
- autoIncrement: true
197
- });
198
- outputTagsStore.createIndex('userId', 'userId');
199
- outputTagsStore.createIndex('tag_userId', ['tag', 'userId'], { unique: true });
200
- }
201
- if (!db.objectStoreNames.contains('output_tags_map')) {
202
- // output_tags_map object store
203
- const outputTagsMapStore = db.createObjectStore('output_tags_map', {
204
- keyPath: ['outputTagId', 'outputId']
205
- });
206
- outputTagsMapStore.createIndex('outputTagId', 'outputTagId');
207
- outputTagsMapStore.createIndex('outputId', 'outputId');
208
- }
209
- if (!db.objectStoreNames.contains('tx_labels')) {
210
- // tx_labels object store
211
- const txLabelsStore = db.createObjectStore('tx_labels', {
212
- keyPath: 'txLabelId',
213
- autoIncrement: true
214
- });
215
- txLabelsStore.createIndex('userId', 'userId');
216
- txLabelsStore.createIndex('label_userId', ['label', 'userId'], { unique: true });
217
- }
218
- if (!db.objectStoreNames.contains('tx_labels_map')) {
219
- // tx_labels_map object store
220
- const txLabelsMapStore = db.createObjectStore('tx_labels_map', {
221
- keyPath: ['txLabelId', 'transactionId']
222
- });
223
- txLabelsMapStore.createIndex('txLabelId', 'txLabelId');
224
- txLabelsMapStore.createIndex('transactionId', 'transactionId');
225
- }
226
- if (!db.objectStoreNames.contains('monitor_events')) {
227
- // monitor_events object store
228
- const monitorEventsStore = db.createObjectStore('monitor_events', {
229
- keyPath: 'id',
230
- autoIncrement: true
231
- });
232
- }
233
- if (!db.objectStoreNames.contains('sync_states')) {
234
- // sync_states object store
235
- const syncStatesStore = db.createObjectStore('sync_states', {
236
- keyPath: 'syncStateId',
237
- autoIncrement: true
238
- });
239
- syncStatesStore.createIndex('userId', 'userId');
240
- syncStatesStore.createIndex('refNum', 'refNum', { unique: true });
241
- syncStatesStore.createIndex('status', 'status');
242
- }
140
+ upgrade(db) {
141
+ (0, idbHelpers_1.upgradeAllStoresV1)(db);
243
142
  if (!db.objectStoreNames.contains('settings')) {
244
143
  if (!storageName || !storageIdentityKey) {
245
144
  throw new WERR_errors_1.WERR_INVALID_OPERATION('migrate must be called before first access');
246
145
  }
247
- const settings = db.createObjectStore('settings', {
248
- keyPath: 'storageIdentityKey'
249
- });
146
+ const settings = db.createObjectStore('settings', { keyPath: 'storageIdentityKey' });
250
147
  const s = {
251
148
  created_at: new Date(),
252
149
  updated_at: new Date(),
@@ -315,25 +212,25 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
315
212
  const score = o.satoshis - targetSatoshis;
316
213
  scores.push({ output: o, score });
317
214
  }
318
- if (!output) {
215
+ if (output == null) {
319
216
  // sort scores increasing by score property
320
217
  scores = scores.sort((a, b) => a.score - b.score);
321
218
  // find the first score that is greater than or equal to 0
322
219
  const o = scores.find(s => s.score >= 0);
323
- if (o) {
220
+ if (o != null) {
324
221
  // stage 2 satisfied (minimally funded)
325
222
  output = o.output;
326
223
  }
327
224
  else if (scores.length > 0) {
328
225
  // stage 3 satisfied (minimally under-funded)
329
- output = scores.slice(-1)[0].output;
226
+ output = scores.at(-1).output;
330
227
  }
331
228
  else {
332
229
  // no available funding outputs
333
230
  output = undefined;
334
231
  }
335
232
  }
336
- if (output) {
233
+ if (output != null) {
337
234
  // mark output as spent by transactionId
338
235
  await this.updateOutput(output.outputId, { spendable: false, spentBy: transactionId }, dbTrx);
339
236
  // Hydrate the locking script for the chosen output. Identical to Knex canon at
@@ -353,10 +250,10 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
353
250
  rawTx: undefined,
354
251
  inputBEEF: undefined
355
252
  };
356
- r.proven = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxs({ partial: { txid: txid }, trx }));
357
- if (!r.proven) {
358
- const req = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxReqs({ partial: { txid: txid }, trx }));
359
- if (req && ['unsent', 'unmined', 'unconfirmed', 'sending', 'nosend', 'completed'].includes(req.status)) {
253
+ r.proven = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxs({ partial: { txid }, trx }));
254
+ if (r.proven == null) {
255
+ const req = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxReqs({ partial: { txid }, trx }));
256
+ if ((req != null) && ['unsent', 'unmined', 'unconfirmed', 'sending', 'nosend', 'completed'].includes(req.status)) {
360
257
  r.rawTx = req.rawTx;
361
258
  r.inputBEEF = req.inputBEEF;
362
259
  }
@@ -368,35 +265,32 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
368
265
  return undefined;
369
266
  if (!this.isAvailable())
370
267
  await this.makeAvailable();
371
- let rawTx = undefined;
372
268
  const sliceRequested = offset !== undefined && length !== undefined && Number.isInteger(offset) && Number.isInteger(length);
373
269
  // Slice path uses an extended status set that includes 'unfail' — matches Knex
374
270
  // canon at StorageKnex.ts:131. The non-slice path continues to delegate to
375
271
  // getProvenOrRawTx which uses the narrower set.
376
- if (sliceRequested) {
377
- const proven = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxs({ partial: { txid }, trx }));
378
- if (proven) {
379
- rawTx = proven.rawTx;
380
- }
381
- else {
382
- const req = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxReqs({ partial: { txid }, trx }));
383
- if (req && ['unsent', 'nosend', 'sending', 'unmined', 'completed', 'unfail'].includes(req.status)) {
384
- rawTx = req.rawTx;
385
- }
386
- }
387
- }
388
- else {
389
- const r = await this.getProvenOrRawTx(txid, trx);
390
- if (r.proven)
391
- rawTx = r.proven.rawTx;
392
- else
393
- rawTx = r.rawTx;
394
- }
395
- if (rawTx && sliceRequested) {
396
- rawTx = rawTx.slice(offset, offset + length);
272
+ const rawTx = sliceRequested
273
+ ? await this.getRawTxForSlice(txid, trx)
274
+ : await this.getRawTxFull(txid, trx);
275
+ if (rawTx != null && sliceRequested) {
276
+ return rawTx.slice(offset, offset + length);
397
277
  }
398
278
  return rawTx;
399
279
  }
280
+ async getRawTxForSlice(txid, trx) {
281
+ const proven = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxs({ partial: { txid }, trx }));
282
+ if (proven != null)
283
+ return proven.rawTx;
284
+ const req = (0, utilityHelpers_1.verifyOneOrNone)(await this.findProvenTxReqs({ partial: { txid }, trx }));
285
+ const validStatuses = ['unsent', 'nosend', 'sending', 'unmined', 'completed', 'unfail'];
286
+ if (req != null && validStatuses.includes(req.status))
287
+ return req.rawTx;
288
+ return undefined;
289
+ }
290
+ async getRawTxFull(txid, trx) {
291
+ const r = await this.getProvenOrRawTx(txid, trx);
292
+ return r.proven != null ? r.proven.rawTx : r.rawTx;
293
+ }
400
294
  async getLabelsForTransactionId(transactionId, trx) {
401
295
  const maps = await this.findTxLabelMaps({ partial: { transactionId, isDeleted: false }, trx });
402
296
  const labelIds = maps.map(m => m.txLabelId);
@@ -406,7 +300,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
406
300
  // Knex/Bun drop it via JOIN; we must do the same silently or we'd break the whole
407
301
  // listActions response. Skip + log so persistent orphans still produce a signal.
408
302
  const label = (0, utilityHelpers_1.verifyOneOrNone)(await this.findTxLabels({ partial: { txLabelId, isDeleted: false }, trx }));
409
- if (label)
303
+ if (label != null)
410
304
  labels.push(label);
411
305
  else
412
306
  console.debug(`[StorageIdb] orphan tx_labels_map row skipped: transactionId=${transactionId} txLabelId=${txLabelId}`);
@@ -419,7 +313,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
419
313
  const tags = [];
420
314
  for (const outputTagId of tagIds) {
421
315
  const tag = (0, utilityHelpers_1.verifyOneOrNone)(await this.findOutputTags({ partial: { outputTagId, isDeleted: false }, trx }));
422
- if (tag)
316
+ if (tag != null)
423
317
  tags.push(tag);
424
318
  else
425
319
  console.debug(`[StorageIdb] orphan output_tags_map row skipped: outputId=${outputId} outputTagId=${outputTagId}`);
@@ -485,7 +379,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
485
379
  * you need IS NULL semantics (only meaningful for nullable columns).
486
380
  */
487
381
  assertNoUndefinedInPartial(partial) {
488
- if (!partial)
382
+ if (partial == null)
489
383
  return;
490
384
  for (const k of Object.keys(partial)) {
491
385
  if (partial[k] === undefined) {
@@ -496,59 +390,32 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
496
390
  async filterOutputTagMaps(args, filtered, userId) {
497
391
  var _a, _b, _c, _d;
498
392
  this.assertNoUndefinedInPartial(args.partial);
499
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
500
- let skipped = 0;
501
- let count = 0;
502
393
  const dbTrx = this.toDbTrx(['output_tags_map', 'output_tags'], 'readonly', args.trx);
394
+ const store = dbTrx.objectStore('output_tags_map');
395
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
503
396
  let cursor;
504
- if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputTagId) !== undefined) {
505
- cursor = await dbTrx.objectStore('output_tags_map').index('outputTagId').openCursor(args.partial.outputTagId);
397
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.outputTagId) !== undefined) {
398
+ cursor = await store.index('outputTagId').openCursor(args.partial.outputTagId);
506
399
  }
507
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.outputId) !== undefined) {
508
- cursor = await dbTrx.objectStore('output_tags_map').index('outputId').openCursor(args.partial.outputId);
400
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputId) !== undefined) {
401
+ cursor = await store.index('outputId').openCursor(args.partial.outputId);
509
402
  }
510
403
  else {
511
- cursor = await dbTrx.objectStore('output_tags_map').openCursor();
512
- }
513
- let firstTime = true;
514
- while (cursor) {
515
- if (!firstTime)
516
- cursor = await cursor.continue();
517
- if (!cursor)
518
- break;
519
- firstTime = false;
520
- const r = cursor.value;
521
- if (args.since && args.since > r.updated_at)
522
- continue;
523
- if (args.tagIds && !args.tagIds.includes(r.outputTagId))
524
- continue;
525
- if (args.partial) {
526
- if (args.partial.outputTagId !== undefined && r.outputTagId !== args.partial.outputTagId)
527
- continue;
528
- if (args.partial.outputId !== undefined && r.outputId !== args.partial.outputId)
529
- continue;
530
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
531
- continue;
532
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
533
- continue;
534
- if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
535
- continue;
536
- }
404
+ cursor = await store.openCursor();
405
+ }
406
+ await scanCursor(cursor, args.since, ((_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) || 0, (_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit, async (r) => {
407
+ if (args.tagIds != null && !args.tagIds.includes(r.outputTagId))
408
+ return false;
409
+ if (!(0, idbHelpers_1.matchesOutputTagMapPartial)(r, args.partial))
410
+ return false;
537
411
  if (userId !== undefined) {
538
412
  const tagsForUser = await this.countOutputTags({ partial: { userId, outputTagId: r.outputTagId }, trx: dbTrx });
539
413
  if (tagsForUser === 0)
540
- continue;
541
- }
542
- if (skipped < offset) {
543
- skipped++;
544
- continue;
414
+ return false;
545
415
  }
546
- filtered(r);
547
- count++;
548
- if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
549
- break;
550
- }
551
- if (!args.trx)
416
+ return true;
417
+ }, filtered);
418
+ if (args.trx == null)
552
419
  await dbTrx.done;
553
420
  }
554
421
  async findOutputTagMaps(args) {
@@ -558,93 +425,54 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
558
425
  });
559
426
  return results;
560
427
  }
428
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
429
+ async openProvenTxReqsCursor(
430
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
431
+ store,
432
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
433
+ partial, direction
434
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
435
+ ) {
436
+ if (partial === null || partial === void 0 ? void 0 : partial.provenTxReqId)
437
+ return store.openCursor(partial.provenTxReqId, direction);
438
+ if ((partial === null || partial === void 0 ? void 0 : partial.provenTxId) !== undefined)
439
+ return store.index('provenTxId').openCursor(partial.provenTxId, direction);
440
+ if ((partial === null || partial === void 0 ? void 0 : partial.txid) !== undefined)
441
+ return store.index('txid').openCursor(partial.txid, direction);
442
+ if ((partial === null || partial === void 0 ? void 0 : partial.status) !== undefined)
443
+ return store.index('status').openCursor(partial.status, direction);
444
+ if ((partial === null || partial === void 0 ? void 0 : partial.batch) !== undefined)
445
+ return store.index('batch').openCursor(partial.batch, direction);
446
+ return store.openCursor(null, direction);
447
+ }
561
448
  async filterProvenTxReqs(args, filtered, userId) {
562
- var _a, _b, _c, _d, _e, _f, _g;
449
+ var _a, _b;
563
450
  this.assertNoUndefinedInPartial(args.partial);
564
- if (args.partial.rawTx)
565
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', `undefined. ProvenTxReqs may not be found by rawTx value.`);
566
- if (args.partial.inputBEEF)
567
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.inputBEEF', `undefined. ProvenTxReqs may not be found by inputBEEF value.`);
568
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
569
- let skipped = 0;
570
- let count = 0;
571
- const dbTrx = this.toDbTrx(['proven_tx_reqs', 'transactions'], 'readonly', args.trx);
572
- const direction = args.orderDescending ? 'prev' : 'next';
573
- let cursor;
574
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.provenTxReqId) {
575
- cursor = await dbTrx.objectStore('proven_tx_reqs').openCursor(args.partial.provenTxReqId, direction);
576
- }
577
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.provenTxId) !== undefined) {
578
- cursor = await dbTrx
579
- .objectStore('proven_tx_reqs')
580
- .index('provenTxId')
581
- .openCursor(args.partial.provenTxId, direction);
451
+ if (args.partial.rawTx != null) {
452
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', 'undefined. ProvenTxReqs may not be found by rawTx value.');
582
453
  }
583
- else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.txid) !== undefined) {
584
- cursor = await dbTrx.objectStore('proven_tx_reqs').index('txid').openCursor(args.partial.txid, direction);
454
+ if (args.partial.inputBEEF != null) {
455
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.inputBEEF', 'undefined. ProvenTxReqs may not be found by inputBEEF value.');
585
456
  }
586
- else if (((_e = args.partial) === null || _e === void 0 ? void 0 : _e.status) !== undefined) {
587
- cursor = await dbTrx.objectStore('proven_tx_reqs').index('status').openCursor(args.partial.status, direction);
588
- }
589
- else if (((_f = args.partial) === null || _f === void 0 ? void 0 : _f.batch) !== undefined) {
590
- cursor = await dbTrx.objectStore('proven_tx_reqs').index('batch').openCursor(args.partial.batch, direction);
591
- }
592
- else {
593
- cursor = await dbTrx.objectStore('proven_tx_reqs').openCursor(null, direction);
594
- }
595
- let firstTime = true;
596
- while (cursor) {
597
- if (!firstTime)
598
- cursor = await cursor.continue();
599
- if (!cursor)
600
- break;
601
- firstTime = false;
602
- const r = cursor.value;
603
- if (args.since && args.since > r.updated_at)
604
- continue;
605
- if (args.partial) {
606
- if (args.partial.provenTxReqId !== undefined && r.provenTxReqId !== args.partial.provenTxReqId)
607
- continue;
608
- if (args.partial.provenTxId !== undefined && r.provenTxId !== args.partial.provenTxId)
609
- continue;
610
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
611
- continue;
612
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
613
- continue;
614
- if (args.partial.status !== undefined && r.status !== args.partial.status)
615
- continue;
616
- if (args.partial.attempts !== undefined && r.attempts !== args.partial.attempts)
617
- continue;
618
- if (args.partial.notified !== undefined && r.notified !== args.partial.notified)
619
- continue;
620
- if (args.partial.txid !== undefined && r.txid !== args.partial.txid)
621
- continue;
622
- if (args.partial.batch !== undefined && r.batch !== args.partial.batch)
623
- continue;
624
- if (args.partial.history !== undefined && r.history !== args.partial.history)
625
- continue;
626
- if (args.partial.notify !== undefined && r.notify !== args.partial.notify)
627
- continue;
628
- }
629
- if (args.status && args.status.length > 0 && !args.status.includes(r.status))
630
- continue;
631
- if (args.txids && args.txids.length > 0 && !args.txids.includes(r.txid))
632
- continue;
457
+ const dbTrx = this.toDbTrx(['proven_tx_reqs', 'transactions'], 'readonly', args.trx);
458
+ const direction = args.orderDescending ? 'prev' : 'next';
459
+ const store = dbTrx.objectStore('proven_tx_reqs');
460
+ const cursor = await this.openProvenTxReqsCursor(store, args.partial, direction);
461
+ await scanCursor(cursor, args.since, ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0, (_b = args.paged) === null || _b === void 0 ? void 0 : _b.limit, async (r) => {
462
+ if (!(0, idbHelpers_1.matchesProvenTxReqPartial)(r, args.partial))
463
+ return false;
464
+ if (args.status != null && args.status.length > 0 && !args.status.includes(r.status))
465
+ return false;
466
+ if (args.txids != null && args.txids.length > 0 && !args.txids.includes(r.txid))
467
+ return false;
633
468
  if (userId !== undefined) {
634
469
  const txsForUser = await this.countTransactions({ partial: { userId, txid: r.txid }, trx: dbTrx });
635
470
  if (txsForUser === 0)
636
- continue;
637
- }
638
- if (skipped < offset) {
639
- skipped++;
640
- continue;
471
+ return false;
641
472
  }
642
- filtered(r);
643
- count++;
644
- if (((_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit) && count >= args.paged.limit)
645
- break;
646
- }
647
- if (!args.trx)
473
+ return true;
474
+ }, filtered);
475
+ if (args.trx == null)
648
476
  await dbTrx.done;
649
477
  }
650
478
  async findProvenTxReqs(args) {
@@ -657,68 +485,37 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
657
485
  async filterProvenTxs(args, filtered, userId) {
658
486
  var _a, _b, _c, _d;
659
487
  this.assertNoUndefinedInPartial(args.partial);
660
- if (args.partial.rawTx)
661
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', `undefined. ProvenTxs may not be found by rawTx value.`);
662
- if (args.partial.merklePath)
663
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.merklePath', `undefined. ProvenTxs may not be found by merklePath value.`);
664
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
665
- let skipped = 0;
666
- let count = 0;
488
+ if (args.partial.rawTx != null) {
489
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', 'undefined. ProvenTxs may not be found by rawTx value.');
490
+ }
491
+ if (args.partial.merklePath != null) {
492
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.merklePath', 'undefined. ProvenTxs may not be found by merklePath value.');
493
+ }
667
494
  const dbTrx = this.toDbTrx(['proven_txs', 'transactions'], 'readonly', args.trx);
668
495
  const direction = args.orderDescending ? 'prev' : 'next';
496
+ const store = dbTrx.objectStore('proven_txs');
497
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
669
498
  let cursor;
670
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.provenTxId) {
671
- cursor = await dbTrx.objectStore('proven_txs').openCursor(args.partial.provenTxId, direction);
499
+ if ((_a = args.partial) === null || _a === void 0 ? void 0 : _a.provenTxId) {
500
+ cursor = await store.openCursor(args.partial.provenTxId, direction);
672
501
  }
673
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.txid) !== undefined) {
674
- cursor = await dbTrx.objectStore('proven_txs').index('txid').openCursor(args.partial.txid, direction);
502
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.txid) !== undefined) {
503
+ cursor = await store.index('txid').openCursor(args.partial.txid, direction);
675
504
  }
676
505
  else {
677
- cursor = await dbTrx.objectStore('proven_txs').openCursor(null, direction);
678
- }
679
- let firstTime = true;
680
- while (cursor) {
681
- if (!firstTime)
682
- cursor = await cursor.continue();
683
- if (!cursor)
684
- break;
685
- firstTime = false;
686
- const r = cursor.value;
687
- if (args.since && args.since > r.updated_at)
688
- continue;
689
- if (args.partial) {
690
- if (args.partial.provenTxId !== undefined && r.provenTxId !== args.partial.provenTxId)
691
- continue;
692
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
693
- continue;
694
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
695
- continue;
696
- if (args.partial.txid !== undefined && r.txid !== args.partial.txid)
697
- continue;
698
- if (args.partial.height !== undefined && r.height !== args.partial.height)
699
- continue;
700
- if (args.partial.index !== undefined && r.index !== args.partial.index)
701
- continue;
702
- if (args.partial.blockHash !== undefined && r.blockHash !== args.partial.blockHash)
703
- continue;
704
- if (args.partial.merkleRoot !== undefined && r.merkleRoot !== args.partial.merkleRoot)
705
- continue;
706
- }
506
+ cursor = await store.openCursor(null, direction);
507
+ }
508
+ await scanCursor(cursor, args.since, ((_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) || 0, (_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit, async (r) => {
509
+ if (!(0, idbHelpers_1.matchesProvenTxPartial)(r, args.partial))
510
+ return false;
707
511
  if (userId !== undefined) {
708
- const count = await this.countTransactions({ partial: { userId, provenTxId: r.provenTxId }, trx: dbTrx });
709
- if (count === 0)
710
- continue;
711
- }
712
- if (skipped < offset) {
713
- skipped++;
714
- continue;
512
+ const txCount = await this.countTransactions({ partial: { userId, provenTxId: r.provenTxId }, trx: dbTrx });
513
+ if (txCount === 0)
514
+ return false;
715
515
  }
716
- filtered(r);
717
- count++;
718
- if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
719
- break;
720
- }
721
- if (!args.trx)
516
+ return true;
517
+ }, filtered);
518
+ if (args.trx == null)
722
519
  await dbTrx.done;
723
520
  }
724
521
  async findProvenTxs(args) {
@@ -731,57 +528,30 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
731
528
  async filterTxLabelMaps(args, filtered, userId) {
732
529
  var _a, _b, _c, _d;
733
530
  this.assertNoUndefinedInPartial(args.partial);
734
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
735
- let skipped = 0;
736
- let count = 0;
737
531
  const dbTrx = this.toDbTrx(['tx_labels_map', 'tx_labels'], 'readonly', args.trx);
532
+ const store = dbTrx.objectStore('tx_labels_map');
533
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
738
534
  let cursor;
739
- if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.transactionId) !== undefined) {
740
- cursor = await dbTrx.objectStore('tx_labels_map').index('transactionId').openCursor(args.partial.transactionId);
535
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.transactionId) !== undefined) {
536
+ cursor = await store.index('transactionId').openCursor(args.partial.transactionId);
741
537
  }
742
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.txLabelId) !== undefined) {
743
- cursor = await dbTrx.objectStore('tx_labels_map').index('txLabelId').openCursor(args.partial.txLabelId);
538
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.txLabelId) !== undefined) {
539
+ cursor = await store.index('txLabelId').openCursor(args.partial.txLabelId);
744
540
  }
745
541
  else {
746
- cursor = await dbTrx.objectStore('tx_labels_map').openCursor();
747
- }
748
- let firstTime = true;
749
- while (cursor) {
750
- if (!firstTime)
751
- cursor = await cursor.continue();
752
- if (!cursor)
753
- break;
754
- firstTime = false;
755
- const r = cursor.value;
756
- if (args.since && args.since > r.updated_at)
757
- continue;
758
- if (args.partial) {
759
- if (args.partial.txLabelId !== undefined && r.txLabelId !== args.partial.txLabelId)
760
- continue;
761
- if (args.partial.transactionId !== undefined && r.transactionId !== args.partial.transactionId)
762
- continue;
763
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
764
- continue;
765
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
766
- continue;
767
- if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
768
- continue;
769
- }
542
+ cursor = await store.openCursor();
543
+ }
544
+ await scanCursor(cursor, args.since, ((_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) || 0, (_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit, async (r) => {
545
+ if (!(0, idbHelpers_1.matchesTxLabelMapPartial)(r, args.partial))
546
+ return false;
770
547
  if (userId !== undefined) {
771
- const count = await this.countTxLabels({ partial: { userId, txLabelId: r.txLabelId }, trx: dbTrx });
772
- if (count === 0)
773
- continue;
548
+ const labelCount = await this.countTxLabels({ partial: { userId, txLabelId: r.txLabelId }, trx: dbTrx });
549
+ if (labelCount === 0)
550
+ return false;
774
551
  }
775
- if (skipped < offset) {
776
- skipped++;
777
- continue;
778
- }
779
- filtered(r);
780
- count++;
781
- if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
782
- break;
783
- }
784
- if (!args.trx)
552
+ return true;
553
+ }, filtered);
554
+ if (args.trx == null)
785
555
  await dbTrx.done;
786
556
  }
787
557
  async findTxLabelMaps(args) {
@@ -843,7 +613,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
843
613
  }
844
614
  }
845
615
  finally {
846
- if (!trx)
616
+ if (trx == null)
847
617
  await dbTrx.done;
848
618
  }
849
619
  return certificate.certificateId;
@@ -856,7 +626,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
856
626
  await store.add(e);
857
627
  }
858
628
  finally {
859
- if (!trx)
629
+ if (trx == null)
860
630
  await dbTrx.done;
861
631
  }
862
632
  }
@@ -871,7 +641,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
871
641
  commission.commissionId = id;
872
642
  }
873
643
  finally {
874
- if (!trx)
644
+ if (trx == null)
875
645
  await dbTrx.done;
876
646
  }
877
647
  return commission.commissionId;
@@ -887,7 +657,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
887
657
  event.id = id;
888
658
  }
889
659
  finally {
890
- if (!trx)
660
+ if (trx == null)
891
661
  await dbTrx.done;
892
662
  }
893
663
  return event.id;
@@ -903,7 +673,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
903
673
  output.outputId = id;
904
674
  }
905
675
  finally {
906
- if (!trx)
676
+ if (trx == null)
907
677
  await dbTrx.done;
908
678
  }
909
679
  return output.outputId;
@@ -919,7 +689,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
919
689
  basket.basketId = id;
920
690
  }
921
691
  finally {
922
- if (!trx)
692
+ if (trx == null)
923
693
  await dbTrx.done;
924
694
  }
925
695
  return basket.basketId;
@@ -935,7 +705,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
935
705
  tag.outputTagId = id;
936
706
  }
937
707
  finally {
938
- if (!trx)
708
+ if (trx == null)
939
709
  await dbTrx.done;
940
710
  }
941
711
  return tag.outputTagId;
@@ -948,7 +718,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
948
718
  await store.add(e);
949
719
  }
950
720
  finally {
951
- if (!trx)
721
+ if (trx == null)
952
722
  await dbTrx.done;
953
723
  }
954
724
  }
@@ -963,7 +733,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
963
733
  tx.provenTxId = id;
964
734
  }
965
735
  finally {
966
- if (!trx)
736
+ if (trx == null)
967
737
  await dbTrx.done;
968
738
  }
969
739
  return tx.provenTxId;
@@ -979,7 +749,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
979
749
  tx.provenTxReqId = id;
980
750
  }
981
751
  finally {
982
- if (!trx)
752
+ if (trx == null)
983
753
  await dbTrx.done;
984
754
  }
985
755
  return tx.provenTxReqId;
@@ -995,7 +765,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
995
765
  syncState.syncStateId = id;
996
766
  }
997
767
  finally {
998
- if (!trx)
768
+ if (trx == null)
999
769
  await dbTrx.done;
1000
770
  }
1001
771
  return syncState.syncStateId;
@@ -1011,7 +781,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1011
781
  tx.transactionId = id;
1012
782
  }
1013
783
  finally {
1014
- if (!trx)
784
+ if (trx == null)
1015
785
  await dbTrx.done;
1016
786
  }
1017
787
  return tx.transactionId;
@@ -1027,7 +797,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1027
797
  label.txLabelId = id;
1028
798
  }
1029
799
  finally {
1030
- if (!trx)
800
+ if (trx == null)
1031
801
  await dbTrx.done;
1032
802
  }
1033
803
  return label.txLabelId;
@@ -1040,7 +810,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1040
810
  await store.add(e);
1041
811
  }
1042
812
  finally {
1043
- if (!trx)
813
+ if (trx == null)
1044
814
  await dbTrx.done;
1045
815
  }
1046
816
  }
@@ -1055,14 +825,14 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1055
825
  user.userId = id;
1056
826
  }
1057
827
  finally {
1058
- if (!trx)
828
+ if (trx == null)
1059
829
  await dbTrx.done;
1060
830
  }
1061
831
  return user.userId;
1062
832
  }
1063
833
  async updateIdb(id, update, keyProp, storeName, trx) {
1064
834
  if (update[keyProp] !== undefined && (Array.isArray(id) || update[keyProp] !== id)) {
1065
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProp}`, `undefined`);
835
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProp}`, 'undefined');
1066
836
  }
1067
837
  const u = this.validatePartialForUpdate(update);
1068
838
  const dbTrx = this.toDbTrx([storeName], 'readwrite', trx);
@@ -1082,22 +852,23 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1082
852
  };
1083
853
  const uid = await store.put(v);
1084
854
  if (uid !== i)
1085
- throw new WERR_errors_1.WERR_INTERNAL(`updated id ${uid} does not match original ${id}`);
855
+ throw new WERR_errors_1.WERR_INTERNAL(`updated id ${String(uid)} does not match original ${String(id)}`);
1086
856
  updated++;
1087
857
  }
1088
858
  }
1089
859
  finally {
1090
- if (!trx)
860
+ if (trx == null)
1091
861
  await dbTrx.done;
1092
862
  }
1093
863
  return updated;
1094
864
  }
1095
865
  async updateIdbKey(key, update, keyProps, storeName, trx) {
1096
- if (key.length !== keyProps.length)
866
+ if (key.length !== keyProps.length) {
1097
867
  throw new WERR_errors_1.WERR_INTERNAL(`key.length ${key.length} !== keyProps.length ${keyProps.length}`);
868
+ }
1098
869
  for (let i = 0; i < key.length; i++) {
1099
870
  if (update[keyProps[i]] !== undefined && update[keyProps[i]] !== key[i]) {
1100
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProps[i]}`, `undefined`);
871
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProps[i]}`, 'undefined');
1101
872
  }
1102
873
  }
1103
874
  const u = this.validatePartialForUpdate(update);
@@ -1105,8 +876,9 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1105
876
  const store = dbTrx.objectStore(storeName);
1106
877
  try {
1107
878
  const e = await store.get(key);
1108
- if (!e)
879
+ if (!e) {
1109
880
  throw new WERR_errors_1.WERR_INVALID_PARAMETER('key', `an existing record to update ${keyProps.join(',')} ${key.join(',')} not found`);
881
+ }
1110
882
  const v = {
1111
883
  ...e,
1112
884
  ...u
@@ -1118,61 +890,61 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1118
890
  }
1119
891
  }
1120
892
  finally {
1121
- if (!trx)
893
+ if (trx == null)
1122
894
  await dbTrx.done;
1123
895
  }
1124
896
  return 1;
1125
897
  }
1126
898
  async updateCertificate(id, update, trx) {
1127
- return this.updateIdb(id, update, 'certificateId', 'certificates', trx);
899
+ return await this.updateIdb(id, update, 'certificateId', 'certificates', trx);
1128
900
  }
1129
901
  async updateCertificateField(certificateId, fieldName, update, trx) {
1130
- return this.updateIdbKey([certificateId, fieldName], update, ['certificateId', 'fieldName'], 'certificate_fields', trx);
902
+ return await this.updateIdbKey([certificateId, fieldName], update, ['certificateId', 'fieldName'], 'certificate_fields', trx);
1131
903
  }
1132
904
  async updateCommission(id, update, trx) {
1133
- return this.updateIdb(id, update, 'commissionId', 'commissions', trx);
905
+ return await this.updateIdb(id, update, 'commissionId', 'commissions', trx);
1134
906
  }
1135
907
  async updateMonitorEvent(id, update, trx) {
1136
- return this.updateIdb(id, update, 'id', 'monitor_events', trx);
908
+ return await this.updateIdb(id, update, 'id', 'monitor_events', trx);
1137
909
  }
1138
910
  async updateOutput(id, update, trx) {
1139
- return this.updateIdb(id, update, 'outputId', 'outputs', trx);
911
+ return await this.updateIdb(id, update, 'outputId', 'outputs', trx);
1140
912
  }
1141
913
  async updateOutputBasket(id, update, trx) {
1142
- return this.updateIdb(id, update, 'basketId', 'output_baskets', trx);
914
+ return await this.updateIdb(id, update, 'basketId', 'output_baskets', trx);
1143
915
  }
1144
916
  async updateOutputTag(id, update, trx) {
1145
- return this.updateIdb(id, update, 'outputTagId', 'output_tags', trx);
917
+ return await this.updateIdb(id, update, 'outputTagId', 'output_tags', trx);
1146
918
  }
1147
919
  async updateProvenTx(id, update, trx) {
1148
- return this.updateIdb(id, update, 'provenTxId', 'proven_txs', trx);
920
+ return await this.updateIdb(id, update, 'provenTxId', 'proven_txs', trx);
1149
921
  }
1150
922
  async updateProvenTxReq(id, update, trx) {
1151
- return this.updateIdb(id, update, 'provenTxReqId', 'proven_tx_reqs', trx);
923
+ return await this.updateIdb(id, update, 'provenTxReqId', 'proven_tx_reqs', trx);
1152
924
  }
1153
925
  async updateSyncState(id, update, trx) {
1154
- return this.updateIdb(id, update, 'syncStateId', 'sync_states', trx);
926
+ return await this.updateIdb(id, update, 'syncStateId', 'sync_states', trx);
1155
927
  }
1156
928
  async updateTransaction(id, update, trx) {
1157
- return this.updateIdb(id, update, 'transactionId', 'transactions', trx);
929
+ return await this.updateIdb(id, update, 'transactionId', 'transactions', trx);
1158
930
  }
1159
931
  async updateTxLabel(id, update, trx) {
1160
- return this.updateIdb(id, update, 'txLabelId', 'tx_labels', trx);
932
+ return await this.updateIdb(id, update, 'txLabelId', 'tx_labels', trx);
1161
933
  }
1162
934
  async updateUser(id, update, trx) {
1163
- return this.updateIdb(id, update, 'userId', 'users', trx);
935
+ return await this.updateIdb(id, update, 'userId', 'users', trx);
1164
936
  }
1165
937
  async updateOutputTagMap(outputId, tagId, update, trx) {
1166
- return this.updateIdbKey([tagId, outputId], update, ['outputTagId', 'outputId'], 'output_tags_map', trx);
938
+ return await this.updateIdbKey([tagId, outputId], update, ['outputTagId', 'outputId'], 'output_tags_map', trx);
1167
939
  }
1168
940
  async updateTxLabelMap(transactionId, txLabelId, update, trx) {
1169
- return this.updateIdbKey([txLabelId, transactionId], update, ['txLabelId', 'transactionId'], 'tx_labels_map', trx);
941
+ return await this.updateIdbKey([txLabelId, transactionId], update, ['txLabelId', 'transactionId'], 'tx_labels_map', trx);
1170
942
  }
1171
943
  //
1172
944
  // StorageReader abstract methods
1173
945
  //
1174
946
  async destroy() {
1175
- if (this.db) {
947
+ if (this.db != null) {
1176
948
  this.db.close();
1177
949
  }
1178
950
  this.db = undefined;
@@ -1184,7 +956,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1184
956
  * @returns
1185
957
  */
1186
958
  async transaction(scope, trx) {
1187
- if (trx)
959
+ if (trx != null)
1188
960
  return await scope(trx);
1189
961
  const stores = this.allStores;
1190
962
  const db = await this.verifyDB();
@@ -1203,59 +975,21 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1203
975
  async filterCertificateFields(args, filtered) {
1204
976
  var _a, _b, _c, _d;
1205
977
  this.assertNoUndefinedInPartial(args.partial);
1206
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1207
- let skipped = 0;
1208
- let count = 0;
1209
978
  const dbTrx = this.toDbTrx(['certificate_fields'], 'readonly', args.trx);
979
+ const store = dbTrx.objectStore('certificate_fields');
980
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1210
981
  let cursor;
1211
- if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.certificateId) !== undefined) {
1212
- cursor = await dbTrx
1213
- .objectStore('certificate_fields')
1214
- .index('certificateId')
1215
- .openCursor(args.partial.certificateId);
982
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.certificateId) !== undefined) {
983
+ cursor = await store.index('certificateId').openCursor(args.partial.certificateId);
1216
984
  }
1217
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1218
- cursor = await dbTrx.objectStore('certificate_fields').index('userId').openCursor(args.partial.userId);
985
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined) {
986
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1219
987
  }
1220
988
  else {
1221
- cursor = await dbTrx.objectStore('certificate_fields').openCursor();
1222
- }
1223
- let firstTime = true;
1224
- while (cursor) {
1225
- if (!firstTime)
1226
- cursor = await cursor.continue();
1227
- if (!cursor)
1228
- break;
1229
- firstTime = false;
1230
- const r = cursor.value;
1231
- if (args.since && args.since > r.updated_at)
1232
- continue;
1233
- if (args.partial) {
1234
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1235
- continue;
1236
- if (args.partial.certificateId !== undefined && r.certificateId !== args.partial.certificateId)
1237
- continue;
1238
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1239
- continue;
1240
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1241
- continue;
1242
- if (args.partial.fieldName !== undefined && r.fieldName !== args.partial.fieldName)
1243
- continue;
1244
- if (args.partial.fieldValue !== undefined && r.fieldValue !== args.partial.fieldValue)
1245
- continue;
1246
- if (args.partial.masterKey !== undefined && r.masterKey !== args.partial.masterKey)
1247
- continue;
1248
- }
1249
- if (skipped < offset) {
1250
- skipped++;
1251
- continue;
1252
- }
1253
- filtered(r);
1254
- count++;
1255
- if (((_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit) && count >= args.paged.limit)
1256
- break;
989
+ cursor = await store.openCursor();
1257
990
  }
1258
- if (!args.trx)
991
+ await scanCursor(cursor, args.since, ((_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) || 0, (_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit, r => (0, idbHelpers_1.matchesCertificateFieldPartial)(r, args.partial), filtered);
992
+ if (args.trx == null)
1259
993
  await dbTrx.done;
1260
994
  }
1261
995
  async findCertificateFields(args) {
@@ -1265,81 +999,40 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1265
999
  });
1266
1000
  return result;
1267
1001
  }
1268
- async filterCertificates(args, filtered) {
1269
- var _a, _b, _c, _d, _e, _f, _g;
1270
- this.assertNoUndefinedInPartial(args.partial);
1271
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1272
- let skipped = 0;
1273
- let count = 0;
1274
- const dbTrx = this.toDbTrx(['certificates'], 'readonly', args.trx);
1275
- let cursor;
1276
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.certificateId) {
1277
- cursor = await dbTrx.objectStore('certificates').openCursor(args.partial.certificateId);
1278
- }
1279
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1280
- if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.type) && ((_e = args.partial) === null || _e === void 0 ? void 0 : _e.certifier) && ((_f = args.partial) === null || _f === void 0 ? void 0 : _f.serialNumber)) {
1281
- cursor = await dbTrx
1282
- .objectStore('certificates')
1002
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1003
+ async openCertificatesCursor(
1004
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1005
+ store,
1006
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1007
+ partial
1008
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1009
+ ) {
1010
+ if (partial === null || partial === void 0 ? void 0 : partial.certificateId)
1011
+ return store.openCursor(partial.certificateId);
1012
+ if ((partial === null || partial === void 0 ? void 0 : partial.userId) !== undefined) {
1013
+ if ((partial === null || partial === void 0 ? void 0 : partial.type) && (partial === null || partial === void 0 ? void 0 : partial.certifier) && (partial === null || partial === void 0 ? void 0 : partial.serialNumber)) {
1014
+ return store
1283
1015
  .index('userId_type_certifier_serialNumber')
1284
- .openCursor([args.partial.userId, args.partial.type, args.partial.certifier, args.partial.serialNumber]);
1285
- }
1286
- else {
1287
- cursor = await dbTrx.objectStore('certificates').index('userId').openCursor(args.partial.userId);
1016
+ .openCursor([partial.userId, partial.type, partial.certifier, partial.serialNumber]);
1288
1017
  }
1018
+ return store.index('userId').openCursor(partial.userId);
1289
1019
  }
1290
- else {
1291
- cursor = await dbTrx.objectStore('certificates').openCursor();
1292
- }
1293
- let firstTime = true;
1294
- while (cursor) {
1295
- if (!firstTime)
1296
- cursor = await cursor.continue();
1297
- if (!cursor)
1298
- break;
1299
- firstTime = false;
1300
- const r = cursor.value;
1301
- if (args.since && args.since > r.updated_at)
1302
- continue;
1303
- if (args.certifiers && !args.certifiers.includes(r.certifier))
1304
- continue;
1305
- if (args.types && !args.types.includes(r.type))
1306
- continue;
1307
- if (args.partial) {
1308
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1309
- continue;
1310
- if (args.partial.certificateId !== undefined && r.certificateId !== args.partial.certificateId)
1311
- continue;
1312
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1313
- continue;
1314
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1315
- continue;
1316
- if (args.partial.type !== undefined && r.type !== args.partial.type)
1317
- continue;
1318
- if (args.partial.serialNumber !== undefined && r.serialNumber !== args.partial.serialNumber)
1319
- continue;
1320
- if (args.partial.certifier !== undefined && r.certifier !== args.partial.certifier)
1321
- continue;
1322
- if (args.partial.subject !== undefined && r.subject !== args.partial.subject)
1323
- continue;
1324
- if (args.partial.verifier !== undefined && r.verifier !== args.partial.verifier)
1325
- continue;
1326
- if (args.partial.revocationOutpoint !== undefined && r.revocationOutpoint !== args.partial.revocationOutpoint)
1327
- continue;
1328
- if (args.partial.signature !== undefined && r.signature !== args.partial.signature)
1329
- continue;
1330
- if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
1331
- continue;
1332
- }
1333
- if (skipped < offset) {
1334
- skipped++;
1335
- continue;
1336
- }
1337
- filtered(r);
1338
- count++;
1339
- if (((_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit) && count >= args.paged.limit)
1340
- break;
1341
- }
1342
- if (!args.trx)
1020
+ return store.openCursor();
1021
+ }
1022
+ async filterCertificates(args, filtered) {
1023
+ var _a, _b;
1024
+ this.assertNoUndefinedInPartial(args.partial);
1025
+ const dbTrx = this.toDbTrx(['certificates'], 'readonly', args.trx);
1026
+ const store = dbTrx.objectStore('certificates');
1027
+ const cursor = await this.openCertificatesCursor(store, args.partial);
1028
+ await scanCursor(cursor, args.since, ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0, (_b = args.paged) === null || _b === void 0 ? void 0 : _b.limit, r => {
1029
+ if (args.certifiers != null && !args.certifiers.includes(r.certifier))
1030
+ return false;
1031
+ if (args.types != null && !args.types.includes(r.type))
1032
+ return false;
1033
+ return (0, idbHelpers_1.matchesCertificatePartial)(r, args.partial);
1034
+ }, filtered);
1035
+ if (args.trx == null)
1343
1036
  await dbTrx.done;
1344
1037
  }
1345
1038
  async findCertificates(args) {
@@ -1358,63 +1051,27 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1358
1051
  async filterCommissions(args, filtered) {
1359
1052
  var _a, _b, _c, _d, _e;
1360
1053
  this.assertNoUndefinedInPartial(args.partial);
1361
- if (args.partial.lockingScript)
1362
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('partial.lockingScript', `undefined. Commissions may not be found by lockingScript value.`);
1363
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1364
- let skipped = 0;
1365
- let count = 0;
1054
+ if (args.partial.lockingScript != null) {
1055
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('partial.lockingScript', 'undefined. Commissions may not be found by lockingScript value.');
1056
+ }
1366
1057
  const dbTrx = this.toDbTrx(['commissions'], 'readonly', args.trx);
1058
+ const store = dbTrx.objectStore('commissions');
1059
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1367
1060
  let cursor;
1368
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.commissionId) {
1369
- cursor = await dbTrx.objectStore('commissions').openCursor(args.partial.commissionId);
1061
+ if ((_a = args.partial) === null || _a === void 0 ? void 0 : _a.commissionId) {
1062
+ cursor = await store.openCursor(args.partial.commissionId);
1370
1063
  }
1371
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1372
- cursor = await dbTrx.objectStore('commissions').index('userId').openCursor(args.partial.userId);
1064
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined) {
1065
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1373
1066
  }
1374
- else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.transactionId) !== undefined) {
1375
- cursor = await dbTrx.objectStore('commissions').index('transactionId').openCursor(args.partial.transactionId);
1067
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.transactionId) !== undefined) {
1068
+ cursor = await store.index('transactionId').openCursor(args.partial.transactionId);
1376
1069
  }
1377
1070
  else {
1378
- cursor = await dbTrx.objectStore('commissions').openCursor();
1379
- }
1380
- let firstTime = true;
1381
- while (cursor) {
1382
- if (!firstTime)
1383
- cursor = await cursor.continue();
1384
- if (!cursor)
1385
- break;
1386
- firstTime = false;
1387
- const r = cursor.value;
1388
- if (args.since && args.since > r.updated_at)
1389
- continue;
1390
- if (args.partial) {
1391
- if (args.partial.commissionId !== undefined && r.commissionId !== args.partial.commissionId)
1392
- continue;
1393
- if (args.partial.transactionId !== undefined && r.transactionId !== args.partial.transactionId)
1394
- continue;
1395
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1396
- continue;
1397
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1398
- continue;
1399
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1400
- continue;
1401
- if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1402
- continue;
1403
- if (args.partial.keyOffset !== undefined && r.keyOffset !== args.partial.keyOffset)
1404
- continue;
1405
- if (args.partial.isRedeemed !== undefined && r.isRedeemed !== args.partial.isRedeemed)
1406
- continue;
1407
- }
1408
- if (skipped < offset) {
1409
- skipped++;
1410
- continue;
1411
- }
1412
- filtered(r);
1413
- count++;
1414
- if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
1415
- break;
1071
+ cursor = await store.openCursor();
1416
1072
  }
1417
- if (!args.trx)
1073
+ await scanCursor(cursor, args.since, ((_d = args.paged) === null || _d === void 0 ? void 0 : _d.offset) || 0, (_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit, r => (0, idbHelpers_1.matchesCommissionPartial)(r, args.partial), filtered);
1074
+ if (args.trx == null)
1418
1075
  await dbTrx.done;
1419
1076
  }
1420
1077
  async findCommissions(args) {
@@ -1427,49 +1084,11 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1427
1084
  async filterMonitorEvents(args, filtered) {
1428
1085
  var _a, _b, _c;
1429
1086
  this.assertNoUndefinedInPartial(args.partial);
1430
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1431
- let skipped = 0;
1432
- let count = 0;
1433
1087
  const dbTrx = this.toDbTrx(['monitor_events'], 'readonly', args.trx);
1434
- let cursor;
1435
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.id) {
1436
- cursor = await dbTrx.objectStore('monitor_events').openCursor(args.partial.id);
1437
- }
1438
- else {
1439
- cursor = await dbTrx.objectStore('monitor_events').openCursor();
1440
- }
1441
- let firstTime = true;
1442
- while (cursor) {
1443
- if (!firstTime)
1444
- cursor = await cursor.continue();
1445
- if (!cursor)
1446
- break;
1447
- firstTime = false;
1448
- const r = cursor.value;
1449
- if (args.since && args.since > r.updated_at)
1450
- continue;
1451
- if (args.partial) {
1452
- if (args.partial.id !== undefined && r.id !== args.partial.id)
1453
- continue;
1454
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1455
- continue;
1456
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1457
- continue;
1458
- if (args.partial.event !== undefined && r.event !== args.partial.event)
1459
- continue;
1460
- if (args.partial.details !== undefined && r.details !== args.partial.details)
1461
- continue;
1462
- }
1463
- if (skipped < offset) {
1464
- skipped++;
1465
- continue;
1466
- }
1467
- filtered(r);
1468
- count++;
1469
- if (((_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit) && count >= args.paged.limit)
1470
- break;
1471
- }
1472
- if (!args.trx)
1088
+ const store = dbTrx.objectStore('monitor_events');
1089
+ const cursor = ((_a = args.partial) === null || _a === void 0 ? void 0 : _a.id) ? await store.openCursor(args.partial.id) : await store.openCursor();
1090
+ await scanCursor(cursor, args.since, ((_b = args.paged) === null || _b === void 0 ? void 0 : _b.offset) || 0, (_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit, r => (0, idbHelpers_1.matchesMonitorEventPartial)(r, args.partial), filtered);
1091
+ if (args.trx == null)
1473
1092
  await dbTrx.done;
1474
1093
  }
1475
1094
  async findMonitorEvents(args) {
@@ -1480,70 +1099,26 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1480
1099
  return result;
1481
1100
  }
1482
1101
  async filterOutputBaskets(args, filtered) {
1483
- var _a, _b, _c, _d, _e;
1102
+ var _a, _b, _c, _d, _e, _f;
1484
1103
  this.assertNoUndefinedInPartial(args.partial);
1485
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1486
- let skipped = 0;
1487
- let count = 0;
1488
1104
  const dbTrx = this.toDbTrx(['output_baskets'], 'readonly', args.trx);
1105
+ const store = dbTrx.objectStore('output_baskets');
1106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1489
1107
  let cursor;
1490
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.basketId) {
1491
- cursor = await dbTrx.objectStore('output_baskets').openCursor(args.partial.basketId);
1492
- }
1493
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1494
- if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.name) !== undefined) {
1495
- cursor = await dbTrx
1496
- .objectStore('output_baskets')
1497
- .index('name_userId')
1498
- .openCursor([args.partial.name, args.partial.userId]);
1499
- }
1500
- else {
1501
- cursor = await dbTrx.objectStore('output_baskets').index('userId').openCursor(args.partial.userId);
1502
- }
1108
+ if ((_a = args.partial) === null || _a === void 0 ? void 0 : _a.basketId) {
1109
+ cursor = await store.openCursor(args.partial.basketId);
1110
+ }
1111
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined && ((_c = args.partial) === null || _c === void 0 ? void 0 : _c.name) !== undefined) {
1112
+ cursor = await store.index('name_userId').openCursor([args.partial.name, args.partial.userId]);
1113
+ }
1114
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.userId) !== undefined) {
1115
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1503
1116
  }
1504
1117
  else {
1505
- cursor = await dbTrx.objectStore('output_baskets').openCursor();
1506
- }
1507
- let firstTime = true;
1508
- while (cursor) {
1509
- if (!firstTime)
1510
- cursor = await cursor.continue();
1511
- if (!cursor)
1512
- break;
1513
- firstTime = false;
1514
- const r = cursor.value;
1515
- if (args.since && args.since > r.updated_at)
1516
- continue;
1517
- if (args.partial) {
1518
- if (args.partial.basketId !== undefined && r.basketId !== args.partial.basketId)
1519
- continue;
1520
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1521
- continue;
1522
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1523
- continue;
1524
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1525
- continue;
1526
- if (args.partial.name !== undefined && r.name !== args.partial.name)
1527
- continue;
1528
- if (args.partial.numberOfDesiredUTXOs !== undefined &&
1529
- r.numberOfDesiredUTXOs !== args.partial.numberOfDesiredUTXOs)
1530
- continue;
1531
- if (args.partial.minimumDesiredUTXOValue !== undefined &&
1532
- r.numberOfDesiredSatoshis !== args.partial.minimumDesiredUTXOValue)
1533
- continue;
1534
- if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
1535
- continue;
1536
- }
1537
- if (skipped < offset) {
1538
- skipped++;
1539
- continue;
1540
- }
1541
- filtered(r);
1542
- count++;
1543
- if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
1544
- break;
1118
+ cursor = await store.openCursor();
1545
1119
  }
1546
- if (!args.trx)
1120
+ await scanCursor(cursor, args.since, ((_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) || 0, (_f = args.paged) === null || _f === void 0 ? void 0 : _f.limit, r => (0, idbHelpers_1.matchesOutputBasketPartial)(r, args.partial), filtered);
1121
+ if (args.trx == null)
1547
1122
  await dbTrx.done;
1548
1123
  }
1549
1124
  async findOutputBaskets(args) {
@@ -1553,227 +1128,121 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1553
1128
  });
1554
1129
  return result;
1555
1130
  }
1131
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1132
+ async openOutputsCursor(
1133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1134
+ store,
1135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1136
+ partial, direction
1137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1138
+ ) {
1139
+ if (partial === null || partial === void 0 ? void 0 : partial.outputId)
1140
+ return store.openCursor(partial.outputId, direction);
1141
+ if ((partial === null || partial === void 0 ? void 0 : partial.userId) !== undefined) {
1142
+ if ((partial === null || partial === void 0 ? void 0 : partial.transactionId) && (partial === null || partial === void 0 ? void 0 : partial.vout) !== undefined) {
1143
+ return store.index('transactionId_vout_userId').openCursor([partial.transactionId, partial.vout, partial.userId], direction);
1144
+ }
1145
+ return store.index('userId').openCursor(partial.userId, direction);
1146
+ }
1147
+ if ((partial === null || partial === void 0 ? void 0 : partial.transactionId) !== undefined)
1148
+ return store.index('transactionId').openCursor(partial.transactionId, direction);
1149
+ if ((partial === null || partial === void 0 ? void 0 : partial.basketId) !== undefined)
1150
+ return store.index('basketId').openCursor(partial.basketId, direction);
1151
+ if ((partial === null || partial === void 0 ? void 0 : partial.spentBy) !== undefined)
1152
+ return store.index('spentBy').openCursor(partial.spentBy, direction);
1153
+ return store.openCursor(null, direction);
1154
+ }
1556
1155
  async filterOutputs(args, filtered, tagIds, isQueryModeAll) {
1557
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1156
+ var _a, _b;
1558
1157
  this.assertNoUndefinedInPartial(args.partial);
1559
- // args.txStatus
1560
- // args.noScript
1561
- if (args.partial.lockingScript)
1562
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.lockingScript', `undefined. Outputs may not be found by lockingScript value.`);
1563
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1564
- let skipped = 0;
1565
- let count = 0;
1158
+ if (args.partial.lockingScript != null) {
1159
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.lockingScript', 'undefined. Outputs may not be found by lockingScript value.');
1160
+ }
1566
1161
  const stores = ['outputs'];
1567
- if (tagIds && tagIds.length > 0) {
1162
+ if (tagIds != null && tagIds.length > 0)
1568
1163
  stores.push('output_tags_map');
1569
- }
1570
- if (args.txStatus) {
1164
+ if (args.txStatus != null)
1571
1165
  stores.push('transactions');
1572
- }
1573
1166
  const dbTrx = this.toDbTrx(stores, 'readonly', args.trx);
1574
1167
  const direction = args.orderDescending ? 'prev' : 'next';
1575
- let cursor;
1576
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputId) {
1577
- cursor = await dbTrx.objectStore('outputs').openCursor(args.partial.outputId, direction);
1578
- }
1579
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1580
- if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.transactionId) && ((_e = args.partial) === null || _e === void 0 ? void 0 : _e.vout) !== undefined) {
1581
- cursor = await dbTrx
1582
- .objectStore('outputs')
1583
- .index('transactionId_vout_userId')
1584
- .openCursor([args.partial.transactionId, args.partial.vout, args.partial.userId], direction);
1585
- }
1586
- else {
1587
- cursor = await dbTrx.objectStore('outputs').index('userId').openCursor(args.partial.userId, direction);
1588
- }
1589
- }
1590
- else if (((_f = args.partial) === null || _f === void 0 ? void 0 : _f.transactionId) !== undefined) {
1591
- cursor = await dbTrx
1592
- .objectStore('outputs')
1593
- .index('transactionId')
1594
- .openCursor(args.partial.transactionId, direction);
1595
- }
1596
- else if (((_g = args.partial) === null || _g === void 0 ? void 0 : _g.basketId) !== undefined) {
1597
- cursor = await dbTrx.objectStore('outputs').index('basketId').openCursor(args.partial.basketId, direction);
1598
- }
1599
- else if (((_h = args.partial) === null || _h === void 0 ? void 0 : _h.spentBy) !== undefined) {
1600
- cursor = await dbTrx.objectStore('outputs').index('spentBy').openCursor(args.partial.spentBy, direction);
1601
- }
1602
- else {
1603
- cursor = await dbTrx.objectStore('outputs').openCursor(null, direction);
1604
- }
1605
- let firstTime = true;
1606
- while (cursor) {
1607
- if (!firstTime)
1608
- cursor = await cursor.continue();
1609
- if (!cursor)
1610
- break;
1611
- firstTime = false;
1612
- const r = cursor.value;
1613
- if (args.since && args.since > r.updated_at)
1614
- continue;
1615
- if (args.partial) {
1616
- if (args.partial.outputId !== undefined && r.outputId !== args.partial.outputId)
1617
- continue;
1618
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1619
- continue;
1620
- if (args.partial.transactionId !== undefined && r.transactionId !== args.partial.transactionId)
1621
- continue;
1622
- if (args.partial.basketId !== undefined && r.basketId !== args.partial.basketId)
1623
- continue;
1624
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1625
- continue;
1626
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1627
- continue;
1628
- if (args.partial.spendable !== undefined && r.spendable !== args.partial.spendable)
1629
- continue;
1630
- if (args.partial.change !== undefined && r.change !== args.partial.change)
1631
- continue;
1632
- if (args.partial.outputDescription !== undefined && r.outputDescription !== args.partial.outputDescription)
1633
- continue;
1634
- if (args.partial.vout !== undefined && r.vout !== args.partial.vout)
1635
- continue;
1636
- if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1637
- continue;
1638
- if (args.partial.providedBy !== undefined && r.providedBy !== args.partial.providedBy)
1639
- continue;
1640
- if (args.partial.purpose !== undefined && r.purpose !== args.partial.purpose)
1641
- continue;
1642
- if (args.partial.type !== undefined && r.type !== args.partial.type)
1643
- continue;
1644
- if (args.partial.txid !== undefined && r.txid !== args.partial.txid)
1645
- continue;
1646
- if (args.partial.senderIdentityKey !== undefined && r.senderIdentityKey !== args.partial.senderIdentityKey)
1647
- continue;
1648
- if (args.partial.derivationPrefix !== undefined && r.derivationPrefix !== args.partial.derivationPrefix)
1649
- continue;
1650
- if (args.partial.derivationSuffix !== undefined && r.derivationSuffix !== args.partial.derivationSuffix)
1651
- continue;
1652
- if (args.partial.customInstructions !== undefined && r.customInstructions !== args.partial.customInstructions)
1653
- continue;
1654
- if (args.partial.spentBy !== undefined && r.spentBy !== args.partial.spentBy)
1655
- continue;
1656
- if (args.partial.sequenceNumber !== undefined && r.sequenceNumber !== args.partial.sequenceNumber)
1657
- continue;
1658
- if (args.partial.scriptLength !== undefined && r.scriptLength !== args.partial.scriptLength)
1659
- continue;
1660
- if (args.partial.scriptOffset !== undefined && r.scriptOffset !== args.partial.scriptOffset)
1661
- continue;
1662
- }
1663
- if (args.txStatus !== undefined && args.txStatus.length > 0) {
1664
- const count = await this.countTransactions({
1168
+ const store = dbTrx.objectStore('outputs');
1169
+ const cursor = await this.openOutputsCursor(store, args.partial, direction);
1170
+ await scanCursor(cursor, args.since, ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0, (_b = args.paged) === null || _b === void 0 ? void 0 : _b.limit, async (r) => {
1171
+ if (!(0, idbHelpers_1.matchesOutputPartial)(r, args.partial))
1172
+ return false;
1173
+ if (args.txStatus !== undefined) {
1174
+ const txCount = await this.countTransactions({
1665
1175
  partial: { transactionId: r.transactionId },
1666
1176
  status: args.txStatus,
1667
1177
  trx: dbTrx
1668
1178
  });
1669
- if (count === 0)
1670
- continue;
1671
- }
1672
- if (tagIds && tagIds.length > 0) {
1673
- let ids = [...tagIds];
1674
- await this.filterOutputTagMaps({ partial: { outputId: r.outputId }, trx: dbTrx }, tm => {
1675
- if (ids.length > 0) {
1676
- const i = ids.indexOf(tm.outputTagId);
1677
- if (i >= 0) {
1678
- if (isQueryModeAll) {
1679
- ids.splice(i, 1);
1680
- }
1681
- else {
1682
- ids = [];
1683
- }
1684
- }
1685
- }
1686
- });
1687
- if (ids.length > 0)
1688
- continue;
1689
- }
1690
- if (skipped < offset) {
1691
- skipped++;
1692
- continue;
1693
- }
1694
- if (args.noScript === true) {
1179
+ if (txCount === 0)
1180
+ return false;
1181
+ }
1182
+ if (tagIds != null && tagIds.length > 0 && !await this.outputMatchesTags(r.outputId, tagIds, isQueryModeAll, dbTrx))
1183
+ return false;
1184
+ return true;
1185
+ }, r => {
1186
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1187
+ if (args.noScript === true)
1695
1188
  r.script = undefined;
1696
- }
1697
1189
  filtered(r);
1698
- count++;
1699
- if (((_j = args.paged) === null || _j === void 0 ? void 0 : _j.limit) && count >= args.paged.limit)
1700
- break;
1701
- }
1702
- if (!args.trx)
1190
+ });
1191
+ if (args.trx == null)
1703
1192
  await dbTrx.done;
1704
1193
  }
1194
+ async outputMatchesTags(outputId, tagIds, isQueryModeAll, dbTrx) {
1195
+ let ids = [...tagIds];
1196
+ await this.filterOutputTagMaps({ partial: { outputId }, trx: dbTrx }, tm => {
1197
+ if (ids.length > 0) {
1198
+ const i = ids.indexOf(tm.outputTagId);
1199
+ if (i >= 0) {
1200
+ if (isQueryModeAll) {
1201
+ ids.splice(i, 1);
1202
+ }
1203
+ else {
1204
+ ids = [];
1205
+ }
1206
+ }
1207
+ }
1208
+ });
1209
+ return ids.length === 0;
1210
+ }
1705
1211
  async findOutputs(args, tagIds, isQueryModeAll) {
1706
1212
  const results = [];
1707
1213
  await this.filterOutputs(args, r => {
1708
1214
  results.push(this.validateEntity(r));
1709
1215
  }, tagIds, isQueryModeAll);
1710
1216
  for (const o of results) {
1711
- // noScript skips the rawTx-slice re-hydration but does not wipe script already
1712
- // on the row — parity with Knex/Bun, which simply don't SELECT the column.
1713
- if (!args.noScript)
1217
+ if (args.noScript) {
1218
+ o.lockingScript = undefined;
1219
+ }
1220
+ else {
1714
1221
  await this.validateOutputScript(o, args.trx);
1222
+ }
1715
1223
  }
1716
1224
  return results;
1717
1225
  }
1718
1226
  async filterOutputTags(args, filtered) {
1719
- var _a, _b, _c, _d, _e;
1720
- this.assertNoUndefinedInPartial(args.partial);
1721
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1722
- let skipped = 0;
1723
- let count = 0;
1227
+ var _a, _b, _c, _d, _e, _f;
1724
1228
  const dbTrx = this.toDbTrx(['output_tags'], 'readonly', args.trx);
1229
+ const store = dbTrx.objectStore('output_tags');
1230
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1725
1231
  let cursor;
1726
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputTagId) {
1727
- cursor = await dbTrx.objectStore('output_tags').openCursor(args.partial.outputTagId);
1728
- }
1729
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1730
- if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.tag) !== undefined) {
1731
- cursor = await dbTrx
1732
- .objectStore('output_tags')
1733
- .index('tag_userId')
1734
- .openCursor([args.partial.tag, args.partial.userId]);
1735
- }
1736
- else {
1737
- cursor = await dbTrx.objectStore('output_tags').index('userId').openCursor(args.partial.userId);
1738
- }
1232
+ if ((_a = args.partial) === null || _a === void 0 ? void 0 : _a.outputTagId) {
1233
+ cursor = await store.openCursor(args.partial.outputTagId);
1234
+ }
1235
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined && ((_c = args.partial) === null || _c === void 0 ? void 0 : _c.tag) !== undefined) {
1236
+ cursor = await store.index('tag_userId').openCursor([args.partial.tag, args.partial.userId]);
1237
+ }
1238
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.userId) !== undefined) {
1239
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1739
1240
  }
1740
1241
  else {
1741
- cursor = await dbTrx.objectStore('output_tags').openCursor();
1742
- }
1743
- let firstTime = true;
1744
- while (cursor) {
1745
- if (!firstTime)
1746
- cursor = await cursor.continue();
1747
- if (!cursor)
1748
- break;
1749
- firstTime = false;
1750
- const r = cursor.value;
1751
- if (args.since && args.since > r.updated_at)
1752
- continue;
1753
- if (args.partial) {
1754
- if (args.partial.outputTagId !== undefined && r.outputTagId !== args.partial.outputTagId)
1755
- continue;
1756
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1757
- continue;
1758
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1759
- continue;
1760
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1761
- continue;
1762
- if (args.partial.tag !== undefined && r.tag !== args.partial.tag)
1763
- continue;
1764
- if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
1765
- continue;
1766
- }
1767
- if (skipped < offset) {
1768
- skipped++;
1769
- continue;
1770
- }
1771
- filtered(r);
1772
- count++;
1773
- if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
1774
- break;
1242
+ cursor = await store.openCursor();
1775
1243
  }
1776
- if (!args.trx)
1244
+ await scanCursor(cursor, args.since, ((_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) || 0, (_f = args.paged) === null || _f === void 0 ? void 0 : _f.limit, r => (0, idbHelpers_1.matchesOutputTagPartial)(r, args.partial), filtered);
1245
+ if (args.trx == null)
1777
1246
  await dbTrx.done;
1778
1247
  }
1779
1248
  async findOutputTags(args) {
@@ -1784,78 +1253,31 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1784
1253
  return result;
1785
1254
  }
1786
1255
  async filterSyncStates(args, filtered) {
1787
- var _a, _b, _c, _d, _e, _f, _g;
1788
- this.assertNoUndefinedInPartial(args.partial);
1789
- if (args.partial.syncMap)
1790
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.syncMap', `undefined. SyncStates may not be found by syncMap value.`);
1791
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1792
- let skipped = 0;
1793
- let count = 0;
1256
+ var _a, _b, _c, _d, _e, _f;
1257
+ if (args.partial.syncMap) {
1258
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.syncMap', 'undefined. SyncStates may not be found by syncMap value.');
1259
+ }
1794
1260
  const dbTrx = this.toDbTrx(['sync_states'], 'readonly', args.trx);
1261
+ const store = dbTrx.objectStore('sync_states');
1262
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1795
1263
  let cursor;
1796
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.syncStateId) {
1797
- cursor = await dbTrx.objectStore('sync_states').openCursor(args.partial.syncStateId);
1264
+ if ((_a = args.partial) === null || _a === void 0 ? void 0 : _a.syncStateId) {
1265
+ cursor = await store.openCursor(args.partial.syncStateId);
1798
1266
  }
1799
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1800
- cursor = await dbTrx.objectStore('sync_states').index('userId').openCursor(args.partial.userId);
1267
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined) {
1268
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1801
1269
  }
1802
- else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.refNum) !== undefined) {
1803
- cursor = await dbTrx.objectStore('sync_states').index('refNum').openCursor(args.partial.refNum);
1270
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.refNum) !== undefined) {
1271
+ cursor = await store.index('refNum').openCursor(args.partial.refNum);
1804
1272
  }
1805
- else if (((_e = args.partial) === null || _e === void 0 ? void 0 : _e.status) !== undefined) {
1806
- cursor = await dbTrx.objectStore('sync_states').index('status').openCursor(args.partial.status);
1273
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.status) !== undefined) {
1274
+ cursor = await store.index('status').openCursor(args.partial.status);
1807
1275
  }
1808
1276
  else {
1809
- cursor = await dbTrx.objectStore('sync_states').openCursor();
1810
- }
1811
- let firstTime = true;
1812
- while (cursor) {
1813
- if (!firstTime)
1814
- cursor = await cursor.continue();
1815
- if (!cursor)
1816
- break;
1817
- firstTime = false;
1818
- const r = cursor.value;
1819
- if (args.since && args.since > r.updated_at)
1820
- continue;
1821
- if (args.partial) {
1822
- if (args.partial.syncStateId !== undefined && r.syncStateId !== args.partial.syncStateId)
1823
- continue;
1824
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1825
- continue;
1826
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1827
- continue;
1828
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1829
- continue;
1830
- if (args.partial.storageIdentityKey !== undefined && r.storageIdentityKey !== args.partial.storageIdentityKey)
1831
- continue;
1832
- if (args.partial.storageName !== undefined && r.storageName !== args.partial.storageName)
1833
- continue;
1834
- if (args.partial.status !== undefined && r.status !== args.partial.status)
1835
- continue;
1836
- if (args.partial.init !== undefined && r.init !== args.partial.init)
1837
- continue;
1838
- if (args.partial.refNum !== undefined && r.refNum !== args.partial.refNum)
1839
- continue;
1840
- if (args.partial.when !== undefined && ((_f = r.when) === null || _f === void 0 ? void 0 : _f.getTime()) !== args.partial.when.getTime())
1841
- continue;
1842
- if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1843
- continue;
1844
- if (args.partial.errorLocal !== undefined && r.errorLocale !== args.partial.errorLocal)
1845
- continue;
1846
- if (args.partial.errorOther !== undefined && r.errorOther !== args.partial.errorOther)
1847
- continue;
1848
- }
1849
- if (skipped < offset) {
1850
- skipped++;
1851
- continue;
1852
- }
1853
- filtered(r);
1854
- count++;
1855
- if (((_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit) && count >= args.paged.limit)
1856
- break;
1277
+ cursor = await store.openCursor();
1857
1278
  }
1858
- if (!args.trx)
1279
+ await scanCursor(cursor, args.since, ((_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) || 0, (_f = args.paged) === null || _f === void 0 ? void 0 : _f.limit, r => (0, idbHelpers_1.matchesSyncStatePartial)(r, args.partial), filtered);
1280
+ if (args.trx == null)
1859
1281
  await dbTrx.done;
1860
1282
  }
1861
1283
  async findSyncStates(args) {
@@ -1865,125 +1287,77 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1865
1287
  });
1866
1288
  return result;
1867
1289
  }
1290
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1291
+ async openTransactionsCursor(
1292
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1293
+ store,
1294
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1295
+ partial, direction
1296
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1297
+ ) {
1298
+ if (partial === null || partial === void 0 ? void 0 : partial.transactionId)
1299
+ return store.openCursor(partial.transactionId, direction);
1300
+ if ((partial === null || partial === void 0 ? void 0 : partial.userId) !== undefined) {
1301
+ if ((partial === null || partial === void 0 ? void 0 : partial.status) !== undefined) {
1302
+ return store.index('status_userId').openCursor([partial.status, partial.userId], direction);
1303
+ }
1304
+ return store.index('userId').openCursor(partial.userId, direction);
1305
+ }
1306
+ if ((partial === null || partial === void 0 ? void 0 : partial.status) !== undefined)
1307
+ return store.index('status').openCursor(partial.status, direction);
1308
+ if ((partial === null || partial === void 0 ? void 0 : partial.provenTxId) !== undefined)
1309
+ return store.index('provenTxId').openCursor(partial.provenTxId, direction);
1310
+ if ((partial === null || partial === void 0 ? void 0 : partial.reference) !== undefined)
1311
+ return store.index('reference').openCursor(partial.reference, direction);
1312
+ return store.openCursor(null, direction);
1313
+ }
1868
1314
  async filterTransactions(args, filtered, labelIds, isQueryModeAll) {
1869
- var _a, _b, _c, _d, _e, _f, _g, _h;
1870
- this.assertNoUndefinedInPartial(args.partial);
1871
- if (args.partial.rawTx)
1872
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', `undefined. Transactions may not be found by rawTx value.`);
1873
- if (args.partial.inputBEEF)
1874
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.inputBEEF', `undefined. Transactions may not be found by inputBEEF value.`);
1875
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
1876
- let skipped = 0;
1877
- let count = 0;
1315
+ var _a, _b;
1316
+ if (args.partial.rawTx != null) {
1317
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', 'undefined. Transactions may not be found by rawTx value.');
1318
+ }
1319
+ if (args.partial.inputBEEF != null) {
1320
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.inputBEEF', 'undefined. Transactions may not be found by inputBEEF value.');
1321
+ }
1878
1322
  const stores = ['transactions'];
1879
- if (labelIds && labelIds.length > 0) {
1323
+ if (labelIds != null && labelIds.length > 0)
1880
1324
  stores.push('tx_labels_map');
1881
- }
1882
1325
  const dbTrx = this.toDbTrx(stores, 'readonly', args.trx);
1883
1326
  const direction = args.orderDescending ? 'prev' : 'next';
1884
- let cursor;
1885
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.transactionId) {
1886
- cursor = await dbTrx.objectStore('transactions').openCursor(args.partial.transactionId, direction);
1887
- }
1888
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
1889
- if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.status) !== undefined) {
1890
- cursor = await dbTrx
1891
- .objectStore('transactions')
1892
- .index('status_userId')
1893
- .openCursor([args.partial.status, args.partial.userId], direction);
1894
- }
1895
- else {
1896
- cursor = await dbTrx.objectStore('transactions').index('userId').openCursor(args.partial.userId, direction);
1897
- }
1898
- }
1899
- else if (((_e = args.partial) === null || _e === void 0 ? void 0 : _e.status) !== undefined) {
1900
- cursor = await dbTrx.objectStore('transactions').index('status').openCursor(args.partial.status, direction);
1901
- }
1902
- else if (((_f = args.partial) === null || _f === void 0 ? void 0 : _f.provenTxId) !== undefined) {
1903
- cursor = await dbTrx
1904
- .objectStore('transactions')
1905
- .index('provenTxId')
1906
- .openCursor(args.partial.provenTxId, direction);
1907
- }
1908
- else if (((_g = args.partial) === null || _g === void 0 ? void 0 : _g.reference) !== undefined) {
1909
- cursor = await dbTrx.objectStore('transactions').index('reference').openCursor(args.partial.reference, direction);
1910
- }
1911
- else {
1912
- cursor = await dbTrx.objectStore('transactions').openCursor(null, direction);
1913
- }
1914
- let firstTime = true;
1915
- while (cursor) {
1916
- if (!firstTime)
1917
- cursor = await cursor.continue();
1918
- if (!cursor)
1919
- break;
1920
- firstTime = false;
1921
- const r = cursor.value;
1922
- if (args.since && args.since > r.updated_at)
1923
- continue;
1924
- if (args.from && r.created_at.getTime() < args.from.getTime())
1925
- continue;
1926
- if (args.to && r.created_at.getTime() >= args.to.getTime())
1927
- continue;
1928
- if (args.status && args.status.length > 0 && !args.status.includes(r.status))
1929
- continue;
1930
- if (args.partial) {
1931
- if (args.partial.transactionId !== undefined && r.transactionId !== args.partial.transactionId)
1932
- continue;
1933
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
1934
- continue;
1935
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
1936
- continue;
1937
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
1938
- continue;
1939
- if (args.partial.provenTxId !== undefined && r.provenTxId !== args.partial.provenTxId)
1940
- continue;
1941
- if (args.partial.status !== undefined && r.status !== args.partial.status)
1942
- continue;
1943
- if (args.partial.reference !== undefined && r.reference !== args.partial.reference)
1944
- continue;
1945
- if (args.partial.isOutgoing !== undefined && r.isOutgoing !== args.partial.isOutgoing)
1946
- continue;
1947
- if (args.partial.satoshis !== undefined && r.satoshis !== args.partial.satoshis)
1948
- continue;
1949
- if (args.partial.description !== undefined && r.description !== args.partial.description)
1950
- continue;
1951
- if (args.partial.version !== undefined && r.version !== args.partial.version)
1952
- continue;
1953
- if (args.partial.lockTime !== undefined && r.lockTime !== args.partial.lockTime)
1954
- continue;
1955
- if (args.partial.txid !== undefined && r.txid !== args.partial.txid)
1956
- continue;
1957
- }
1958
- if (labelIds && labelIds.length > 0) {
1959
- let ids = [...labelIds];
1960
- await this.filterTxLabelMaps({ partial: { transactionId: r.transactionId }, trx: dbTrx }, lm => {
1961
- if (ids.length > 0) {
1962
- const i = ids.indexOf(lm.txLabelId);
1963
- if (i >= 0) {
1964
- if (isQueryModeAll) {
1965
- ids.splice(i, 1);
1966
- }
1967
- else {
1968
- ids = [];
1969
- }
1970
- }
1327
+ const store = dbTrx.objectStore('transactions');
1328
+ const cursor = await this.openTransactionsCursor(store, args.partial, direction);
1329
+ await scanCursor(cursor, args.since, ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0, (_b = args.paged) === null || _b === void 0 ? void 0 : _b.limit, async (r) => {
1330
+ if (args.from != null && r.created_at.getTime() < args.from.getTime())
1331
+ return false;
1332
+ if (args.to != null && r.created_at.getTime() >= args.to.getTime())
1333
+ return false;
1334
+ if (args.status != null && !args.status.includes(r.status))
1335
+ return false;
1336
+ if (!(0, idbHelpers_1.matchesTransactionPartial)(r, args.partial))
1337
+ return false;
1338
+ if (labelIds != null && labelIds.length > 0 && !await this.transactionMatchesLabels(r.transactionId, labelIds, isQueryModeAll, dbTrx))
1339
+ return false;
1340
+ return true;
1341
+ }, filtered);
1342
+ if (args.trx == null)
1343
+ await dbTrx.done;
1344
+ }
1345
+ async transactionMatchesLabels(transactionId, labelIds, isQueryModeAll, dbTrx) {
1346
+ let ids = [...labelIds];
1347
+ await this.filterTxLabelMaps({ partial: { transactionId }, trx: dbTrx }, lm => {
1348
+ if (ids.length > 0) {
1349
+ const i = ids.indexOf(lm.txLabelId);
1350
+ if (i >= 0) {
1351
+ if (isQueryModeAll) {
1352
+ ids.splice(i, 1);
1971
1353
  }
1972
- });
1973
- if (ids.length > 0)
1974
- continue;
1975
- }
1976
- if (skipped < offset) {
1977
- skipped++;
1978
- continue;
1354
+ else {
1355
+ ids = [];
1356
+ }
1357
+ }
1979
1358
  }
1980
- filtered(r);
1981
- count++;
1982
- if (((_h = args.paged) === null || _h === void 0 ? void 0 : _h.limit) && count >= args.paged.limit)
1983
- break;
1984
- }
1985
- if (!args.trx)
1986
- await dbTrx.done;
1359
+ });
1360
+ return ids.length === 0;
1987
1361
  }
1988
1362
  async findTransactions(args, labelIds, isQueryModeAll) {
1989
1363
  const results = [];
@@ -1991,75 +1365,36 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1991
1365
  results.push(this.validateEntity(r));
1992
1366
  }, labelIds, isQueryModeAll);
1993
1367
  for (const t of results) {
1994
- // noRawTx skips rawTx re-hydration but does not wipe inputBEEF — Knex's
1995
- // transactionColumnsWithoutRawTx only strips rawTx, and callers such as
1996
- // getReqsAndBeefToShareWithWorld legitimately need inputBEEF when noRawTx is set.
1997
- if (!args.noRawTx)
1998
- await this.validateRawTransaction(t, args.trx);
1999
- else
1368
+ if (args.noRawTx) {
2000
1369
  t.rawTx = undefined;
1370
+ t.inputBEEF = undefined;
1371
+ }
1372
+ else {
1373
+ await this.validateRawTransaction(t, args.trx);
1374
+ }
2001
1375
  }
2002
1376
  return results;
2003
1377
  }
2004
1378
  async filterTxLabels(args, filtered) {
2005
- var _a, _b, _c, _d, _e;
2006
- this.assertNoUndefinedInPartial(args.partial);
2007
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
2008
- let skipped = 0;
2009
- let count = 0;
1379
+ var _a, _b, _c, _d, _e, _f;
2010
1380
  const dbTrx = this.toDbTrx(['tx_labels'], 'readonly', args.trx);
1381
+ const store = dbTrx.objectStore('tx_labels');
1382
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2011
1383
  let cursor;
2012
- if ((_b = args.partial) === null || _b === void 0 ? void 0 : _b.txLabelId) {
2013
- cursor = await dbTrx.objectStore('tx_labels').openCursor(args.partial.txLabelId);
2014
- }
2015
- else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.userId) !== undefined) {
2016
- if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.label) !== undefined) {
2017
- cursor = await dbTrx
2018
- .objectStore('tx_labels')
2019
- .index('label_userId')
2020
- .openCursor([args.partial.label, args.partial.userId]);
2021
- }
2022
- else {
2023
- cursor = await dbTrx.objectStore('tx_labels').index('userId').openCursor(args.partial.userId);
2024
- }
1384
+ if ((_a = args.partial) === null || _a === void 0 ? void 0 : _a.txLabelId) {
1385
+ cursor = await store.openCursor(args.partial.txLabelId);
1386
+ }
1387
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined && ((_c = args.partial) === null || _c === void 0 ? void 0 : _c.label) !== undefined) {
1388
+ cursor = await store.index('label_userId').openCursor([args.partial.label, args.partial.userId]);
1389
+ }
1390
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.userId) !== undefined) {
1391
+ cursor = await store.index('userId').openCursor(args.partial.userId);
2025
1392
  }
2026
1393
  else {
2027
- cursor = await dbTrx.objectStore('tx_labels').openCursor();
2028
- }
2029
- let firstTime = true;
2030
- while (cursor) {
2031
- if (!firstTime)
2032
- cursor = await cursor.continue();
2033
- if (!cursor)
2034
- break;
2035
- firstTime = false;
2036
- const r = cursor.value;
2037
- if (args.since && args.since > r.updated_at)
2038
- continue;
2039
- if (args.partial) {
2040
- if (args.partial.txLabelId !== undefined && r.txLabelId !== args.partial.txLabelId)
2041
- continue;
2042
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
2043
- continue;
2044
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
2045
- continue;
2046
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
2047
- continue;
2048
- if (args.partial.label !== undefined && r.label !== args.partial.label)
2049
- continue;
2050
- if (args.partial.isDeleted !== undefined && r.isDeleted !== args.partial.isDeleted)
2051
- continue;
2052
- }
2053
- if (skipped < offset) {
2054
- skipped++;
2055
- continue;
2056
- }
2057
- filtered(r);
2058
- count++;
2059
- if (((_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit) && count >= args.paged.limit)
2060
- break;
1394
+ cursor = await store.openCursor();
2061
1395
  }
2062
- if (!args.trx)
1396
+ await scanCursor(cursor, args.since, ((_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) || 0, (_f = args.paged) === null || _f === void 0 ? void 0 : _f.limit, r => (0, idbHelpers_1.matchesTxLabelPartial)(r, args.partial), filtered);
1397
+ if (args.trx == null)
2063
1398
  await dbTrx.done;
2064
1399
  }
2065
1400
  async findTxLabels(args) {
@@ -2069,46 +1404,27 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2069
1404
  });
2070
1405
  return result;
2071
1406
  }
1407
+ matchesUserPartial(r, partial) {
1408
+ if (!partial)
1409
+ return true;
1410
+ if (partial.userId && r.userId !== partial.userId)
1411
+ return false;
1412
+ if ((partial.created_at != null) && r.created_at.getTime() !== partial.created_at.getTime())
1413
+ return false;
1414
+ if ((partial.updated_at != null) && r.updated_at.getTime() !== partial.updated_at.getTime())
1415
+ return false;
1416
+ if (partial.identityKey && r.identityKey !== partial.identityKey)
1417
+ return false;
1418
+ if (partial.activeStorage && r.activeStorage !== partial.activeStorage)
1419
+ return false;
1420
+ return true;
1421
+ }
2072
1422
  async filterUsers(args, filtered) {
2073
1423
  var _a, _b;
2074
- this.assertNoUndefinedInPartial(args.partial);
2075
- const offset = ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0;
2076
- let skipped = 0;
2077
- let count = 0;
2078
1424
  const dbTrx = this.toDbTrx(['users'], 'readonly', args.trx);
2079
- let cursor = await dbTrx.objectStore('users').openCursor();
2080
- let firstTime = true;
2081
- while (cursor) {
2082
- if (!firstTime)
2083
- cursor = await cursor.continue();
2084
- if (!cursor)
2085
- break;
2086
- firstTime = false;
2087
- const r = cursor.value;
2088
- if (args.since && args.since > r.updated_at)
2089
- continue;
2090
- if (args.partial) {
2091
- if (args.partial.userId !== undefined && r.userId !== args.partial.userId)
2092
- continue;
2093
- if (args.partial.created_at !== undefined && r.created_at.getTime() !== args.partial.created_at.getTime())
2094
- continue;
2095
- if (args.partial.updated_at !== undefined && r.updated_at.getTime() !== args.partial.updated_at.getTime())
2096
- continue;
2097
- if (args.partial.identityKey !== undefined && r.identityKey !== args.partial.identityKey)
2098
- continue;
2099
- if (args.partial.activeStorage !== undefined && r.activeStorage !== args.partial.activeStorage)
2100
- continue;
2101
- }
2102
- if (skipped < offset) {
2103
- skipped++;
2104
- continue;
2105
- }
2106
- filtered(r);
2107
- count++;
2108
- if (((_b = args.paged) === null || _b === void 0 ? void 0 : _b.limit) && count >= args.paged.limit)
2109
- break;
2110
- }
2111
- if (!args.trx)
1425
+ const cursor = await dbTrx.objectStore('users').openCursor();
1426
+ await scanCursor(cursor, args.since, ((_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) || 0, (_b = args.paged) === null || _b === void 0 ? void 0 : _b.limit, r => this.matchesUserPartial(r, args.partial), filtered);
1427
+ if (args.trx == null)
2112
1428
  await dbTrx.done;
2113
1429
  }
2114
1430
  async findUsers(args) {
@@ -2248,9 +1564,8 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2248
1564
  return results;
2249
1565
  }
2250
1566
  async verifyReadyForDatabaseAccess(trx) {
2251
- if (!this._settings) {
2252
- this._settings = await this.readSettings();
2253
- }
1567
+ var _a;
1568
+ (_a = this._settings) !== null && _a !== void 0 ? _a : (this._settings = await this.readSettings());
2254
1569
  return this._settings.dbtype;
2255
1570
  }
2256
1571
  /**
@@ -2260,18 +1575,30 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2260
1575
  validateEntity(entity, dateFields, booleanFields) {
2261
1576
  entity.created_at = this.validateDate(entity.created_at);
2262
1577
  entity.updated_at = this.validateDate(entity.updated_at);
2263
- if (dateFields) {
2264
- for (const df of dateFields) {
2265
- if (entity[df])
2266
- entity[df] = this.validateDate(entity[df]);
2267
- }
1578
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1579
+ const e = entity;
1580
+ this.applyDateFields(e, dateFields);
1581
+ this.applyBooleanFields(e, booleanFields);
1582
+ this.normalizeEntityValues(e);
1583
+ return entity;
1584
+ }
1585
+ applyDateFields(entity, dateFields) {
1586
+ if (dateFields == null)
1587
+ return;
1588
+ for (const df of dateFields) {
1589
+ if (entity[df])
1590
+ entity[df] = this.validateDate(entity[df]);
2268
1591
  }
2269
- if (booleanFields) {
2270
- for (const df of booleanFields) {
2271
- if (entity[df] !== undefined)
2272
- entity[df] = !!entity[df];
2273
- }
1592
+ }
1593
+ applyBooleanFields(entity, booleanFields) {
1594
+ if (booleanFields == null)
1595
+ return;
1596
+ for (const df of booleanFields) {
1597
+ if (entity[df] !== undefined)
1598
+ entity[df] = !!entity[df];
2274
1599
  }
1600
+ }
1601
+ normalizeEntityValues(entity) {
2275
1602
  for (const key of Object.keys(entity)) {
2276
1603
  const val = entity[key];
2277
1604
  if (val === null) {
@@ -2281,7 +1608,6 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2281
1608
  entity[key] = Array.from(val);
2282
1609
  }
2283
1610
  }
2284
- return entity;
2285
1611
  }
2286
1612
  /**
2287
1613
  * Helper to force uniform behavior across database engines.
@@ -2302,26 +1628,35 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2302
1628
  if (!this.dbtype)
2303
1629
  throw new WERR_errors_1.WERR_INTERNAL('must call verifyReadyForDatabaseAccess first');
2304
1630
  const v = { ...update };
2305
- if (v.created_at)
2306
- v.created_at = this.validateEntityDate(v.created_at);
2307
- if (v.updated_at)
2308
- v.updated_at = this.validateEntityDate(v.updated_at);
1631
+ v.created_at = v.created_at ? this.validateEntityDate(v.created_at) : undefined;
2309
1632
  if (!v.created_at)
2310
1633
  delete v.created_at;
2311
- if (!v.updated_at)
2312
- v.updated_at = this.validateEntityDate(new Date());
2313
- if (dateFields) {
2314
- for (const df of dateFields) {
2315
- if (v[df])
2316
- v[df] = this.validateOptionalEntityDate(v[df]);
2317
- }
1634
+ v.updated_at = v.updated_at ? this.validateEntityDate(v.updated_at) : this.validateEntityDate(new Date());
1635
+ this.applyOptionalDateFields(v, dateFields);
1636
+ this.applyIntegerBooleanFields(update, booleanFields);
1637
+ this.normalizeForStorage(v);
1638
+ this.isDirty = true;
1639
+ return v;
1640
+ }
1641
+ applyOptionalDateFields(v, dateFields) {
1642
+ if (dateFields == null)
1643
+ return;
1644
+ for (const df of dateFields) {
1645
+ if (v[df])
1646
+ v[df] = this.validateOptionalEntityDate(v[df]);
2318
1647
  }
2319
- if (booleanFields) {
2320
- for (const df of booleanFields) {
2321
- if (update[df] !== undefined)
2322
- update[df] = !!update[df] ? 1 : 0;
2323
- }
1648
+ }
1649
+ applyIntegerBooleanFields(update, booleanFields) {
1650
+ if (booleanFields == null)
1651
+ return;
1652
+ for (const df of booleanFields) {
1653
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1654
+ const u = update;
1655
+ if (u[df] !== undefined)
1656
+ u[df] = u[df] ? 1 : 0;
2324
1657
  }
1658
+ }
1659
+ normalizeForStorage(v) {
2325
1660
  for (const key of Object.keys(v)) {
2326
1661
  const val = v[key];
2327
1662
  if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
@@ -2331,8 +1666,6 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2331
1666
  v[key] = undefined;
2332
1667
  }
2333
1668
  }
2334
- this.isDirty = true;
2335
- return v;
2336
1669
  }
2337
1670
  /**
2338
1671
  * Helper to force uniform behavior across database engines.
@@ -2347,27 +1680,9 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2347
1680
  delete v.created_at;
2348
1681
  if (!v.updated_at)
2349
1682
  delete v.updated_at;
2350
- if (dateFields) {
2351
- for (const df of dateFields) {
2352
- if (v[df])
2353
- v[df] = this.validateOptionalEntityDate(v[df]);
2354
- }
2355
- }
2356
- if (booleanFields) {
2357
- for (const df of booleanFields) {
2358
- if (entity[df] !== undefined)
2359
- entity[df] = !!entity[df] ? 1 : 0;
2360
- }
2361
- }
2362
- for (const key of Object.keys(v)) {
2363
- const val = v[key];
2364
- if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
2365
- v[key] = Uint8Array.from(val);
2366
- }
2367
- else if (val === null) {
2368
- v[key] = undefined;
2369
- }
2370
- }
1683
+ this.applyOptionalDateFields(v, dateFields);
1684
+ this.applyIntegerBooleanFields(entity, booleanFields);
1685
+ this.normalizeForStorage(v);
2371
1686
  this.isDirty = true;
2372
1687
  return v;
2373
1688
  }
@@ -2377,7 +1692,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2377
1692
  return;
2378
1693
  // rawTransaction is missing, see if we moved it ...
2379
1694
  const rawTx = await this.getRawTxOfKnownValidTransaction(t.txid, undefined, undefined, trx);
2380
- if (!rawTx)
1695
+ if (rawTx == null)
2381
1696
  return;
2382
1697
  t.rawTx = rawTx;
2383
1698
  }