@bsv/wallet-toolbox-client 2.1.24 → 2.1.26

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 (520) 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 +8 -8
  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 +201 -243
  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 +63 -80
  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 +32 -24
  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 +28 -20
  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/WalletStorage.interfaces.d.ts +59 -59
  140. package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  141. package/out/src/sdk/types.d.ts +4 -4
  142. package/out/src/sdk/types.d.ts.map +1 -1
  143. package/out/src/sdk/types.js +3 -3
  144. package/out/src/sdk/types.js.map +1 -1
  145. package/out/src/services/ServiceCollection.d.ts +6 -6
  146. package/out/src/services/ServiceCollection.d.ts.map +1 -1
  147. package/out/src/services/ServiceCollection.js +6 -8
  148. package/out/src/services/ServiceCollection.js.map +1 -1
  149. package/out/src/services/Services.d.ts +5 -0
  150. package/out/src/services/Services.d.ts.map +1 -1
  151. package/out/src/services/Services.js +190 -196
  152. package/out/src/services/Services.js.map +1 -1
  153. package/out/src/services/chaintracker/BHServiceClient.d.ts.map +1 -1
  154. package/out/src/services/chaintracker/BHServiceClient.js +7 -7
  155. package/out/src/services/chaintracker/BHServiceClient.js.map +1 -1
  156. package/out/src/services/chaintracker/ChaintracksChainTracker.d.ts.map +1 -1
  157. package/out/src/services/chaintracker/ChaintracksChainTracker.js +5 -5
  158. package/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -1
  159. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts +5 -3
  160. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts.map +1 -1
  161. package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.js.map +1 -1
  162. package/out/src/services/chaintracker/chaintracks/Api/BulkStorageApi.d.ts.map +1 -1
  163. package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts +20 -10
  164. package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts.map +1 -1
  165. package/out/src/services/chaintracker/chaintracks/Chaintracks.js +228 -221
  166. package/out/src/services/chaintracker/chaintracks/Chaintracks.js.map +1 -1
  167. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -1
  168. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js +9 -10
  169. package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js.map +1 -1
  170. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.d.ts.map +1 -1
  171. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.js +1 -1
  172. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorBase.js.map +1 -1
  173. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts +1 -2
  174. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts.map +1 -1
  175. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js +3 -3
  176. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js.map +1 -1
  177. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.d.ts.map +1 -1
  178. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDNBabbage.js.map +1 -1
  179. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.d.ts.map +1 -1
  180. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.js +3 -3
  181. package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorWhatsOnChainCdn.js.map +1 -1
  182. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.d.ts.map +1 -1
  183. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.js +1 -1
  184. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorBase.js.map +1 -1
  185. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
  186. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +2 -2
  187. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
  188. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.d.ts +2 -2
  189. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.d.ts.map +1 -1
  190. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.js +6 -39
  191. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainIngestorWs.js.map +1 -1
  192. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts +3 -3
  193. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts.map +1 -1
  194. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js +8 -6
  195. package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js.map +1 -1
  196. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.d.ts.map +1 -1
  197. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.js +9 -16
  198. package/out/src/services/chaintracker/chaintracks/Storage/BulkStorageBase.js.map +1 -1
  199. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.d.ts.map +1 -1
  200. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js +34 -22
  201. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js.map +1 -1
  202. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.d.ts.map +1 -1
  203. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js +31 -30
  204. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageIdb.js.map +1 -1
  205. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts +2 -2
  206. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.d.ts.map +1 -1
  207. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js +11 -10
  208. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageNoDb.js.map +1 -1
  209. package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts.map +1 -1
  210. package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts.map +1 -1
  211. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts +6 -1
  212. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts.map +1 -1
  213. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js +247 -227
  214. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js.map +1 -1
  215. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.d.ts.map +1 -1
  216. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.js +8 -7
  217. package/out/src/services/chaintracker/chaintracks/util/BulkFileDataReader.js.map +1 -1
  218. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.d.ts.map +1 -1
  219. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js +35 -25
  220. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js.map +1 -1
  221. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.d.ts +5 -5
  222. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.d.ts.map +1 -1
  223. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.js +13 -11
  224. package/out/src/services/chaintracker/chaintracks/util/BulkHeaderFile.js.map +1 -1
  225. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts +0 -1
  226. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts.map +1 -1
  227. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js.map +1 -1
  228. package/out/src/services/chaintracker/chaintracks/util/HeightRange.d.ts.map +1 -1
  229. package/out/src/services/chaintracker/chaintracks/util/HeightRange.js +21 -13
  230. package/out/src/services/chaintracker/chaintracks/util/HeightRange.js.map +1 -1
  231. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts +2 -2
  232. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts.map +1 -1
  233. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.js.map +1 -1
  234. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts +1 -1
  235. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts.map +1 -1
  236. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js +28 -24
  237. package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js.map +1 -1
  238. package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.d.ts.map +1 -1
  239. package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.js.map +1 -1
  240. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.d.ts.map +1 -1
  241. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js +9 -10
  242. package/out/src/services/chaintracker/chaintracks/util/validBulkHeaderFilesByFileHash.js.map +1 -1
  243. package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
  244. package/out/src/services/createDefaultWalletServicesOptions.js +3 -3
  245. package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
  246. package/out/src/services/providers/ARC.d.ts.map +1 -1
  247. package/out/src/services/providers/ARC.js +7 -14
  248. package/out/src/services/providers/ARC.js.map +1 -1
  249. package/out/src/services/providers/ArcSSEClient.d.ts.map +1 -1
  250. package/out/src/services/providers/ArcSSEClient.js +1 -1
  251. package/out/src/services/providers/ArcSSEClient.js.map +1 -1
  252. package/out/src/services/providers/Bitails.d.ts.map +1 -1
  253. package/out/src/services/providers/Bitails.js +17 -17
  254. package/out/src/services/providers/Bitails.js.map +1 -1
  255. package/out/src/services/providers/SdkWhatsOnChain.d.ts.map +1 -1
  256. package/out/src/services/providers/SdkWhatsOnChain.js.map +1 -1
  257. package/out/src/services/providers/WhatsOnChain.d.ts +2 -0
  258. package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
  259. package/out/src/services/providers/WhatsOnChain.js +109 -233
  260. package/out/src/services/providers/WhatsOnChain.js.map +1 -1
  261. package/out/src/services/providers/exchangeRates.d.ts.map +1 -1
  262. package/out/src/services/providers/exchangeRates.js +3 -3
  263. package/out/src/services/providers/exchangeRates.js.map +1 -1
  264. package/out/src/services/providers/getBeefForTxid.d.ts +1 -1
  265. package/out/src/services/providers/getBeefForTxid.d.ts.map +1 -1
  266. package/out/src/services/providers/getBeefForTxid.js.map +1 -1
  267. package/out/src/services/providers/whatsOnChainHelpers.d.ts +68 -0
  268. package/out/src/services/providers/whatsOnChainHelpers.d.ts.map +1 -0
  269. package/out/src/services/providers/whatsOnChainHelpers.js +147 -0
  270. package/out/src/services/providers/whatsOnChainHelpers.js.map +1 -0
  271. package/out/src/signer/WalletSigner.d.ts.map +1 -1
  272. package/out/src/signer/WalletSigner.js.map +1 -1
  273. package/out/src/signer/methods/acquireDirectCertificate.js +1 -1
  274. package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
  275. package/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
  276. package/out/src/signer/methods/buildSignableTransaction.js +21 -13
  277. package/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
  278. package/out/src/signer/methods/completeSignedTransaction.d.ts.map +1 -1
  279. package/out/src/signer/methods/completeSignedTransaction.js +20 -21
  280. package/out/src/signer/methods/completeSignedTransaction.js.map +1 -1
  281. package/out/src/signer/methods/createAction.d.ts.map +1 -1
  282. package/out/src/signer/methods/createAction.js +8 -7
  283. package/out/src/signer/methods/createAction.js.map +1 -1
  284. package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
  285. package/out/src/signer/methods/internalizeAction.js +8 -6
  286. package/out/src/signer/methods/internalizeAction.js.map +1 -1
  287. package/out/src/signer/methods/proveCertificate.js +1 -1
  288. package/out/src/signer/methods/signAction.d.ts.map +1 -1
  289. package/out/src/signer/methods/signAction.js +8 -10
  290. package/out/src/signer/methods/signAction.js.map +1 -1
  291. package/out/src/storage/StorageIdb.d.ts +16 -1
  292. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  293. package/out/src/storage/StorageIdb.js +578 -1258
  294. package/out/src/storage/StorageIdb.js.map +1 -1
  295. package/out/src/storage/StorageProvider.d.ts +10 -0
  296. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  297. package/out/src/storage/StorageProvider.js +171 -197
  298. package/out/src/storage/StorageProvider.js.map +1 -1
  299. package/out/src/storage/StorageReader.d.ts.map +1 -1
  300. package/out/src/storage/StorageReader.js +14 -13
  301. package/out/src/storage/StorageReader.js.map +1 -1
  302. package/out/src/storage/StorageReaderWriter.d.ts +0 -1
  303. package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
  304. package/out/src/storage/StorageReaderWriter.js +32 -35
  305. package/out/src/storage/StorageReaderWriter.js.map +1 -1
  306. package/out/src/storage/StorageSyncReader.d.ts.map +1 -1
  307. package/out/src/storage/StorageSyncReader.js +4 -4
  308. package/out/src/storage/StorageSyncReader.js.map +1 -1
  309. package/out/src/storage/WalletStorageManager.d.ts +3 -0
  310. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  311. package/out/src/storage/WalletStorageManager.js +95 -84
  312. package/out/src/storage/WalletStorageManager.js.map +1 -1
  313. package/out/src/storage/idbHelpers.d.ts +42 -0
  314. package/out/src/storage/idbHelpers.d.ts.map +1 -0
  315. package/out/src/storage/idbHelpers.js +375 -0
  316. package/out/src/storage/idbHelpers.js.map +1 -0
  317. package/out/src/storage/index.client.d.ts +3 -0
  318. package/out/src/storage/index.client.d.ts.map +1 -1
  319. package/out/src/storage/index.client.js +3 -0
  320. package/out/src/storage/index.client.js.map +1 -1
  321. package/out/src/storage/methods/ListActionsSpecOp.d.ts +6 -1
  322. package/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -1
  323. package/out/src/storage/methods/ListActionsSpecOp.js +28 -2
  324. package/out/src/storage/methods/ListActionsSpecOp.js.map +1 -1
  325. package/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
  326. package/out/src/storage/methods/ListOutputsSpecOp.js +8 -11
  327. package/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
  328. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +83 -0
  329. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
  330. package/out/src/storage/methods/attemptToPostReqsToNetwork.js +224 -61
  331. package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  332. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  333. package/out/src/storage/methods/createAction.js +230 -270
  334. package/out/src/storage/methods/createAction.js.map +1 -1
  335. package/out/src/storage/methods/generateChange.d.ts.map +1 -1
  336. package/out/src/storage/methods/generateChange.js +99 -80
  337. package/out/src/storage/methods/generateChange.js.map +1 -1
  338. package/out/src/storage/methods/getBeefForTransaction.js +15 -13
  339. package/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
  340. package/out/src/storage/methods/getSyncChunk.d.ts.map +1 -1
  341. package/out/src/storage/methods/getSyncChunk.js +4 -3
  342. package/out/src/storage/methods/getSyncChunk.js.map +1 -1
  343. package/out/src/storage/methods/internalizeAction.js +41 -51
  344. package/out/src/storage/methods/internalizeAction.js.map +1 -1
  345. package/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
  346. package/out/src/storage/methods/listActionsIdb.js +85 -110
  347. package/out/src/storage/methods/listActionsIdb.js.map +1 -1
  348. package/out/src/storage/methods/listCertificates.d.ts +1 -1
  349. package/out/src/storage/methods/listCertificates.d.ts.map +1 -1
  350. package/out/src/storage/methods/listCertificates.js +7 -7
  351. package/out/src/storage/methods/listCertificates.js.map +1 -1
  352. package/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
  353. package/out/src/storage/methods/listOutputsIdb.js +24 -27
  354. package/out/src/storage/methods/listOutputsIdb.js.map +1 -1
  355. package/out/src/storage/methods/offsetKey.d.ts +1 -1
  356. package/out/src/storage/methods/offsetKey.d.ts.map +1 -1
  357. package/out/src/storage/methods/offsetKey.js +3 -5
  358. package/out/src/storage/methods/offsetKey.js.map +1 -1
  359. package/out/src/storage/methods/processAction.d.ts +0 -11
  360. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  361. package/out/src/storage/methods/processAction.js +90 -83
  362. package/out/src/storage/methods/processAction.js.map +1 -1
  363. package/out/src/storage/methods/purgeDataIdb.d.ts.map +1 -1
  364. package/out/src/storage/methods/purgeDataIdb.js +1 -1
  365. package/out/src/storage/methods/purgeDataIdb.js.map +1 -1
  366. package/out/src/storage/methods/reviewStatusIdb.d.ts +1 -1
  367. package/out/src/storage/methods/reviewStatusIdb.d.ts.map +1 -1
  368. package/out/src/storage/methods/reviewStatusIdb.js.map +1 -1
  369. package/out/src/storage/methods/utils.d.ts.map +1 -1
  370. package/out/src/storage/methods/utils.js +7 -1
  371. package/out/src/storage/methods/utils.js.map +1 -1
  372. package/out/src/storage/portable/index.d.ts +55 -0
  373. package/out/src/storage/portable/index.d.ts.map +1 -0
  374. package/out/src/storage/portable/index.js +830 -0
  375. package/out/src/storage/portable/index.js.map +1 -0
  376. package/out/src/storage/remoting/StorageClient.d.ts +4 -270
  377. package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
  378. package/out/src/storage/remoting/StorageClient.js +16 -423
  379. package/out/src/storage/remoting/StorageClient.js.map +1 -1
  380. package/out/src/storage/remoting/StorageClientBase.d.ts +289 -0
  381. package/out/src/storage/remoting/StorageClientBase.d.ts.map +1 -0
  382. package/out/src/storage/remoting/StorageClientBase.js +375 -0
  383. package/out/src/storage/remoting/StorageClientBase.js.map +1 -0
  384. package/out/src/storage/remoting/entityValidationHelpers.d.ts +29 -0
  385. package/out/src/storage/remoting/entityValidationHelpers.d.ts.map +1 -0
  386. package/out/src/storage/remoting/entityValidationHelpers.js +91 -0
  387. package/out/src/storage/remoting/entityValidationHelpers.js.map +1 -0
  388. package/out/src/storage/schema/StorageIdbSchema.d.ts +1 -1
  389. package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
  390. package/out/src/storage/schema/entities/EntityBase.d.ts.map +1 -1
  391. package/out/src/storage/schema/entities/EntityBase.js.map +1 -1
  392. package/out/src/storage/schema/entities/EntityCertificate.d.ts.map +1 -1
  393. package/out/src/storage/schema/entities/EntityCertificate.js +5 -4
  394. package/out/src/storage/schema/entities/EntityCertificate.js.map +1 -1
  395. package/out/src/storage/schema/entities/EntityCertificateField.d.ts.map +1 -1
  396. package/out/src/storage/schema/entities/EntityCertificateField.js +5 -7
  397. package/out/src/storage/schema/entities/EntityCertificateField.js.map +1 -1
  398. package/out/src/storage/schema/entities/EntityCommission.d.ts.map +1 -1
  399. package/out/src/storage/schema/entities/EntityCommission.js +6 -8
  400. package/out/src/storage/schema/entities/EntityCommission.js.map +1 -1
  401. package/out/src/storage/schema/entities/EntityOutput.d.ts.map +1 -1
  402. package/out/src/storage/schema/entities/EntityOutput.js +21 -24
  403. package/out/src/storage/schema/entities/EntityOutput.js.map +1 -1
  404. package/out/src/storage/schema/entities/EntityOutputBasket.d.ts.map +1 -1
  405. package/out/src/storage/schema/entities/EntityOutputBasket.js +6 -6
  406. package/out/src/storage/schema/entities/EntityOutputBasket.js.map +1 -1
  407. package/out/src/storage/schema/entities/EntityOutputTag.d.ts.map +1 -1
  408. package/out/src/storage/schema/entities/EntityOutputTag.js +2 -2
  409. package/out/src/storage/schema/entities/EntityOutputTag.js.map +1 -1
  410. package/out/src/storage/schema/entities/EntityOutputTagMap.d.ts.map +1 -1
  411. package/out/src/storage/schema/entities/EntityOutputTagMap.js +4 -6
  412. package/out/src/storage/schema/entities/EntityOutputTagMap.js.map +1 -1
  413. package/out/src/storage/schema/entities/EntityProvenTx.d.ts +3 -3
  414. package/out/src/storage/schema/entities/EntityProvenTx.d.ts.map +1 -1
  415. package/out/src/storage/schema/entities/EntityProvenTx.js +22 -23
  416. package/out/src/storage/schema/entities/EntityProvenTx.js.map +1 -1
  417. package/out/src/storage/schema/entities/EntityProvenTxReq.d.ts +9 -0
  418. package/out/src/storage/schema/entities/EntityProvenTxReq.d.ts.map +1 -1
  419. package/out/src/storage/schema/entities/EntityProvenTxReq.js +116 -68
  420. package/out/src/storage/schema/entities/EntityProvenTxReq.js.map +1 -1
  421. package/out/src/storage/schema/entities/EntitySyncState.d.ts.map +1 -1
  422. package/out/src/storage/schema/entities/EntitySyncState.js +19 -18
  423. package/out/src/storage/schema/entities/EntitySyncState.js.map +1 -1
  424. package/out/src/storage/schema/entities/EntityTransaction.d.ts.map +1 -1
  425. package/out/src/storage/schema/entities/EntityTransaction.js +25 -26
  426. package/out/src/storage/schema/entities/EntityTransaction.js.map +1 -1
  427. package/out/src/storage/schema/entities/EntityTxLabel.d.ts.map +1 -1
  428. package/out/src/storage/schema/entities/EntityTxLabel.js +2 -2
  429. package/out/src/storage/schema/entities/EntityTxLabel.js.map +1 -1
  430. package/out/src/storage/schema/entities/EntityTxLabelMap.d.ts.map +1 -1
  431. package/out/src/storage/schema/entities/EntityTxLabelMap.js +4 -6
  432. package/out/src/storage/schema/entities/EntityTxLabelMap.js.map +1 -1
  433. package/out/src/storage/schema/entities/EntityUser.d.ts.map +1 -1
  434. package/out/src/storage/schema/entities/EntityUser.js +3 -3
  435. package/out/src/storage/schema/entities/EntityUser.js.map +1 -1
  436. package/out/src/storage/schema/entities/MergeEntity.d.ts.map +1 -1
  437. package/out/src/storage/schema/entities/MergeEntity.js +6 -6
  438. package/out/src/storage/schema/entities/MergeEntity.js.map +1 -1
  439. package/out/src/storage/schema/tables/TableCertificate.d.ts +2 -1
  440. package/out/src/storage/schema/tables/TableCertificate.d.ts.map +1 -1
  441. package/out/src/storage/schema/tables/TableCertificateField.d.ts +1 -1
  442. package/out/src/storage/schema/tables/TableCertificateField.d.ts.map +1 -1
  443. package/out/src/storage/schema/tables/TableCommission.d.ts +1 -1
  444. package/out/src/storage/schema/tables/TableCommission.d.ts.map +1 -1
  445. package/out/src/storage/schema/tables/TableMonitorEvent.d.ts +1 -1
  446. package/out/src/storage/schema/tables/TableMonitorEvent.d.ts.map +1 -1
  447. package/out/src/storage/schema/tables/TableOutput.d.ts +3 -2
  448. package/out/src/storage/schema/tables/TableOutput.d.ts.map +1 -1
  449. package/out/src/storage/schema/tables/TableOutput.js +1 -1
  450. package/out/src/storage/schema/tables/TableOutput.js.map +1 -1
  451. package/out/src/storage/schema/tables/TableOutputBasket.d.ts +1 -1
  452. package/out/src/storage/schema/tables/TableOutputBasket.d.ts.map +1 -1
  453. package/out/src/storage/schema/tables/TableOutputTag.d.ts +1 -1
  454. package/out/src/storage/schema/tables/TableOutputTag.d.ts.map +1 -1
  455. package/out/src/storage/schema/tables/TableOutputTagMap.d.ts +1 -1
  456. package/out/src/storage/schema/tables/TableOutputTagMap.d.ts.map +1 -1
  457. package/out/src/storage/schema/tables/TableProvenTx.d.ts +1 -1
  458. package/out/src/storage/schema/tables/TableProvenTx.d.ts.map +1 -1
  459. package/out/src/storage/schema/tables/TableProvenTxReq.d.ts +24 -1
  460. package/out/src/storage/schema/tables/TableProvenTxReq.d.ts.map +1 -1
  461. package/out/src/storage/schema/tables/TableSettings.d.ts +1 -1
  462. package/out/src/storage/schema/tables/TableSettings.d.ts.map +1 -1
  463. package/out/src/storage/schema/tables/TableSyncState.d.ts +1 -1
  464. package/out/src/storage/schema/tables/TableSyncState.d.ts.map +1 -1
  465. package/out/src/storage/schema/tables/TableTransaction.d.ts +1 -1
  466. package/out/src/storage/schema/tables/TableTransaction.d.ts.map +1 -1
  467. package/out/src/storage/schema/tables/TableTxLabel.d.ts +1 -1
  468. package/out/src/storage/schema/tables/TableTxLabel.d.ts.map +1 -1
  469. package/out/src/storage/schema/tables/TableTxLabelMap.d.ts +1 -1
  470. package/out/src/storage/schema/tables/TableTxLabelMap.d.ts.map +1 -1
  471. package/out/src/storage/schema/tables/TableUser.d.ts +1 -1
  472. package/out/src/storage/schema/tables/TableUser.d.ts.map +1 -1
  473. package/out/src/storage/storageProviderHelpers.d.ts +34 -0
  474. package/out/src/storage/storageProviderHelpers.d.ts.map +1 -0
  475. package/out/src/storage/storageProviderHelpers.js +100 -0
  476. package/out/src/storage/storageProviderHelpers.js.map +1 -0
  477. package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
  478. package/out/src/utility/ScriptTemplateBRC29.js +4 -2
  479. package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
  480. package/out/src/utility/aggregateResults.d.ts +1 -1
  481. package/out/src/utility/aggregateResults.d.ts.map +1 -1
  482. package/out/src/utility/aggregateResults.js +2 -2
  483. package/out/src/utility/aggregateResults.js.map +1 -1
  484. package/out/src/utility/brc114ActionTimeLabels.d.ts +2 -2
  485. package/out/src/utility/brc114ActionTimeLabels.d.ts.map +1 -1
  486. package/out/src/utility/brc114ActionTimeLabels.js +17 -10
  487. package/out/src/utility/brc114ActionTimeLabels.js.map +1 -1
  488. package/out/src/utility/identityUtils.d.ts.map +1 -1
  489. package/out/src/utility/identityUtils.js +6 -6
  490. package/out/src/utility/identityUtils.js.map +1 -1
  491. package/out/src/utility/index.client.d.ts +1 -0
  492. package/out/src/utility/index.client.d.ts.map +1 -1
  493. package/out/src/utility/index.client.js +1 -0
  494. package/out/src/utility/index.client.js.map +1 -1
  495. package/out/src/utility/parseTxScriptOffsets.d.ts +4 -4
  496. package/out/src/utility/parseTxScriptOffsets.d.ts.map +1 -1
  497. package/out/src/utility/parseTxScriptOffsets.js.map +1 -1
  498. package/out/src/utility/stampLog.d.ts.map +1 -1
  499. package/out/src/utility/stampLog.js +6 -4
  500. package/out/src/utility/stampLog.js.map +1 -1
  501. package/out/src/utility/tscProofToMerklePath.d.ts.map +1 -1
  502. package/out/src/utility/tscProofToMerklePath.js +1 -1
  503. package/out/src/utility/tscProofToMerklePath.js.map +1 -1
  504. package/out/src/utility/utilityHelpers.d.ts +1 -2
  505. package/out/src/utility/utilityHelpers.d.ts.map +1 -1
  506. package/out/src/utility/utilityHelpers.js +12 -12
  507. package/out/src/utility/utilityHelpers.js.map +1 -1
  508. package/out/src/utility/utilityHelpers.noBuffer.d.ts +7 -3
  509. package/out/src/utility/utilityHelpers.noBuffer.d.ts.map +1 -1
  510. package/out/src/utility/utilityHelpers.noBuffer.js +3 -3
  511. package/out/src/utility/utilityHelpers.noBuffer.js.map +1 -1
  512. package/out/src/wab-client/WABClient.d.ts +3 -3
  513. package/out/src/wab-client/WABClient.d.ts.map +1 -1
  514. package/out/src/wab-client/WABClient.js +12 -12
  515. package/out/src/wab-client/WABClient.js.map +1 -1
  516. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.d.ts.map +1 -1
  517. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js +3 -3
  518. package/out/src/wab-client/auth-method-interactors/AuthMethodInteractor.js.map +1 -1
  519. package/out/tsconfig.client.tsbuildinfo +1 -1
  520. 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 !== null && limit !== void 0 ? limit : 0) > 0 && 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,15 +107,15 @@ 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
- const trx = db.transaction(stores || this.allStores, mode || 'readwrite');
118
+ const trx = db.transaction(stores.length > 0 ? stores : this.allStores, mode);
85
119
  this.whenLastAccess = new Date();
86
120
  return trx;
87
121
  }
@@ -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
- if (!storageName || !storageIdentityKey) {
143
+ if (storageName == null || storageName === '' || storageIdentityKey == null || 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(),
@@ -256,7 +153,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
256
153
  dbtype: 'IndexedDB',
257
154
  maxOutputScript
258
155
  };
259
- settings.put(s);
156
+ void settings.put(s);
260
157
  }
261
158
  }
262
159
  });
@@ -308,32 +205,32 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
308
205
  let output;
309
206
  let scores = [];
310
207
  for (const o of outputs) {
311
- if (exactSatoshis && o.satoshis === exactSatoshis) {
208
+ if (exactSatoshis != null && exactSatoshis !== 0 && o.satoshis === exactSatoshis) {
312
209
  output = o;
313
210
  break;
314
211
  }
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
  }
@@ -364,39 +261,36 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
364
261
  return r;
365
262
  }
366
263
  async getRawTxOfKnownValidTransaction(txid, offset, length, trx) {
367
- if (!txid)
264
+ if (txid == null || txid === '')
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,10 +300,12 @@ 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
- else
412
- console.debug(`[StorageIdb] orphan tx_labels_map row skipped: transactionId=${transactionId} txLabelId=${txLabelId}`);
305
+ }
306
+ else {
307
+ console.debug(`[StorageIdb] orphan tx_labels_map row skipped: transactionId=${String(transactionId)} txLabelId=${txLabelId}`);
308
+ }
413
309
  }
414
310
  return labels;
415
311
  }
@@ -419,20 +315,22 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
419
315
  const tags = [];
420
316
  for (const outputTagId of tagIds) {
421
317
  const tag = (0, utilityHelpers_1.verifyOneOrNone)(await this.findOutputTags({ partial: { outputTagId, isDeleted: false }, trx }));
422
- if (tag)
318
+ if (tag != null) {
423
319
  tags.push(tag);
424
- else
320
+ }
321
+ else {
425
322
  console.debug(`[StorageIdb] orphan output_tags_map row skipped: outputId=${outputId} outputTagId=${outputTagId}`);
323
+ }
426
324
  }
427
325
  return tags;
428
326
  }
429
327
  async listActions(auth, vargs) {
430
- if (!auth.userId)
328
+ if (auth.userId == null)
431
329
  throw new WERR_errors_1.WERR_UNAUTHORIZED();
432
330
  return await (0, listActionsIdb_1.listActionsIdb)(this, auth, vargs);
433
331
  }
434
332
  async listOutputs(auth, vargs) {
435
- if (!auth.userId)
333
+ if (auth.userId == null)
436
334
  throw new WERR_errors_1.WERR_UNAUTHORIZED();
437
335
  return await (0, listOutputsIdb_1.listOutputsIdb)(this, auth, vargs);
438
336
  }
@@ -448,25 +346,25 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
448
346
  return count;
449
347
  }
450
348
  async findCertificatesAuth(auth, args) {
451
- if (!auth.userId || (args.partial.userId && args.partial.userId !== auth.userId))
349
+ if (auth.userId == null || (args.partial.userId != null && args.partial.userId !== 0 && args.partial.userId !== auth.userId))
452
350
  throw new WERR_errors_1.WERR_UNAUTHORIZED();
453
351
  args.partial.userId = auth.userId;
454
352
  return await this.findCertificates(args);
455
353
  }
456
354
  async findOutputBasketsAuth(auth, args) {
457
- if (!auth.userId || (args.partial.userId && args.partial.userId !== auth.userId))
355
+ if (auth.userId == null || (args.partial.userId != null && args.partial.userId !== 0 && args.partial.userId !== auth.userId))
458
356
  throw new WERR_errors_1.WERR_UNAUTHORIZED();
459
357
  args.partial.userId = auth.userId;
460
358
  return await this.findOutputBaskets(args);
461
359
  }
462
360
  async findOutputsAuth(auth, args) {
463
- if (!auth.userId || (args.partial.userId && args.partial.userId !== auth.userId))
361
+ if (auth.userId == null || (args.partial.userId != null && args.partial.userId !== 0 && args.partial.userId !== auth.userId))
464
362
  throw new WERR_errors_1.WERR_UNAUTHORIZED();
465
363
  args.partial.userId = auth.userId;
466
364
  return await this.findOutputs(args);
467
365
  }
468
366
  async insertCertificateAuth(auth, certificate) {
469
- if (!auth.userId || (certificate.userId && certificate.userId !== auth.userId))
367
+ if (auth.userId == null || (certificate.userId != null && certificate.userId !== 0 && certificate.userId !== auth.userId))
470
368
  throw new WERR_errors_1.WERR_UNAUTHORIZED();
471
369
  certificate.userId = auth.userId;
472
370
  return await this.insertCertificate(certificate);
@@ -485,70 +383,43 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
485
383
  * you need IS NULL semantics (only meaningful for nullable columns).
486
384
  */
487
385
  assertNoUndefinedInPartial(partial) {
488
- if (!partial)
386
+ if (partial == null)
489
387
  return;
490
388
  for (const k of Object.keys(partial)) {
491
389
  if (partial[k] === undefined) {
492
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`args.partial.${k}`, `not undefined. Passing undefined as a filter value is not supported — omit the key to skip filtering. Matches Knex semantics.`);
390
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`args.partial.${k}`, 'not undefined. Passing undefined as a filter value is not supported — omit the key to skip filtering. Matches Knex semantics.');
493
391
  }
494
392
  }
495
393
  }
496
394
  async filterOutputTagMaps(args, filtered, userId) {
497
- var _a, _b, _c, _d;
395
+ var _a, _b, _c, _d, _e;
498
396
  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
397
  const dbTrx = this.toDbTrx(['output_tags_map', 'output_tags'], 'readonly', args.trx);
398
+ const store = dbTrx.objectStore('output_tags_map');
399
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
503
400
  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);
401
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.outputTagId) !== undefined) {
402
+ cursor = await store.index('outputTagId').openCursor(args.partial.outputTagId);
506
403
  }
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);
404
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.outputId) !== undefined) {
405
+ cursor = await store.index('outputId').openCursor(args.partial.outputId);
509
406
  }
510
407
  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
- }
408
+ cursor = await store.openCursor();
409
+ }
410
+ await scanCursor(cursor, args.since, (_d = (_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) !== null && _d !== void 0 ? _d : 0, (_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit, async (r) => {
411
+ if (args.tagIds != null && !args.tagIds.includes(r.outputTagId))
412
+ return false;
413
+ if (!(0, idbHelpers_1.matchesOutputTagMapPartial)(r, args.partial))
414
+ return false;
537
415
  if (userId !== undefined) {
538
416
  const tagsForUser = await this.countOutputTags({ partial: { userId, outputTagId: r.outputTagId }, trx: dbTrx });
539
417
  if (tagsForUser === 0)
540
- continue;
541
- }
542
- if (skipped < offset) {
543
- skipped++;
544
- continue;
418
+ return false;
545
419
  }
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)
420
+ return true;
421
+ }, filtered);
422
+ if (args.trx == null)
552
423
  await dbTrx.done;
553
424
  }
554
425
  async findOutputTagMaps(args) {
@@ -558,93 +429,54 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
558
429
  });
559
430
  return results;
560
431
  }
432
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
433
+ async openProvenTxReqsCursor(
434
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
435
+ store,
436
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
437
+ partial, direction
438
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
439
+ ) {
440
+ if ((partial === null || partial === void 0 ? void 0 : partial.provenTxReqId) != null && partial.provenTxReqId !== 0)
441
+ return store.openCursor(partial.provenTxReqId, direction);
442
+ if ((partial === null || partial === void 0 ? void 0 : partial.provenTxId) !== undefined)
443
+ return store.index('provenTxId').openCursor(partial.provenTxId, direction);
444
+ if ((partial === null || partial === void 0 ? void 0 : partial.txid) !== undefined)
445
+ return store.index('txid').openCursor(partial.txid, direction);
446
+ if ((partial === null || partial === void 0 ? void 0 : partial.status) !== undefined)
447
+ return store.index('status').openCursor(partial.status, direction);
448
+ if ((partial === null || partial === void 0 ? void 0 : partial.batch) !== undefined)
449
+ return store.index('batch').openCursor(partial.batch, direction);
450
+ return store.openCursor(null, direction);
451
+ }
561
452
  async filterProvenTxReqs(args, filtered, userId) {
562
- var _a, _b, _c, _d, _e, _f, _g;
453
+ var _a, _b, _c;
563
454
  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);
455
+ if (args.partial.rawTx != null) {
456
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', 'undefined. ProvenTxReqs may not be found by rawTx value.');
576
457
  }
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);
458
+ if (args.partial.inputBEEF != null) {
459
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.inputBEEF', 'undefined. ProvenTxReqs may not be found by inputBEEF value.');
582
460
  }
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);
585
- }
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;
461
+ const dbTrx = this.toDbTrx(['proven_tx_reqs', 'transactions'], 'readonly', args.trx);
462
+ const direction = args.orderDescending === true ? 'prev' : 'next';
463
+ const store = dbTrx.objectStore('proven_tx_reqs');
464
+ const cursor = await this.openProvenTxReqsCursor(store, args.partial, direction);
465
+ await scanCursor(cursor, args.since, (_b = (_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : 0, (_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit, async (r) => {
466
+ if (!(0, idbHelpers_1.matchesProvenTxReqPartial)(r, args.partial))
467
+ return false;
468
+ if (args.status != null && args.status.length > 0 && !args.status.includes(r.status))
469
+ return false;
470
+ if (args.txids != null && args.txids.length > 0 && !args.txids.includes(r.txid))
471
+ return false;
633
472
  if (userId !== undefined) {
634
473
  const txsForUser = await this.countTransactions({ partial: { userId, txid: r.txid }, trx: dbTrx });
635
474
  if (txsForUser === 0)
636
- continue;
637
- }
638
- if (skipped < offset) {
639
- skipped++;
640
- continue;
475
+ return false;
641
476
  }
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)
477
+ return true;
478
+ }, filtered);
479
+ if (args.trx == null)
648
480
  await dbTrx.done;
649
481
  }
650
482
  async findProvenTxReqs(args) {
@@ -655,70 +487,39 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
655
487
  return results;
656
488
  }
657
489
  async filterProvenTxs(args, filtered, userId) {
658
- var _a, _b, _c, _d;
490
+ var _a, _b, _c, _d, _e;
659
491
  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;
492
+ if (args.partial.rawTx != null) {
493
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', 'undefined. ProvenTxs may not be found by rawTx value.');
494
+ }
495
+ if (args.partial.merklePath != null) {
496
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.merklePath', 'undefined. ProvenTxs may not be found by merklePath value.');
497
+ }
667
498
  const dbTrx = this.toDbTrx(['proven_txs', 'transactions'], 'readonly', args.trx);
668
- const direction = args.orderDescending ? 'prev' : 'next';
499
+ const direction = args.orderDescending === true ? 'prev' : 'next';
500
+ const store = dbTrx.objectStore('proven_txs');
501
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
669
502
  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);
503
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.provenTxId) != null && args.partial.provenTxId > 0) {
504
+ cursor = await store.openCursor(args.partial.provenTxId, direction);
672
505
  }
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);
506
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.txid) !== undefined) {
507
+ cursor = await store.index('txid').openCursor(args.partial.txid, direction);
675
508
  }
676
509
  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
- }
510
+ cursor = await store.openCursor(null, direction);
511
+ }
512
+ await scanCursor(cursor, args.since, (_d = (_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) !== null && _d !== void 0 ? _d : 0, (_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit, async (r) => {
513
+ if (!(0, idbHelpers_1.matchesProvenTxPartial)(r, args.partial))
514
+ return false;
707
515
  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;
516
+ const txCount = await this.countTransactions({ partial: { userId, provenTxId: r.provenTxId }, trx: dbTrx });
517
+ if (txCount === 0)
518
+ return false;
715
519
  }
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)
520
+ return true;
521
+ }, filtered);
522
+ if (args.trx == null)
722
523
  await dbTrx.done;
723
524
  }
724
525
  async findProvenTxs(args) {
@@ -729,59 +530,32 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
729
530
  return results;
730
531
  }
731
532
  async filterTxLabelMaps(args, filtered, userId) {
732
- var _a, _b, _c, _d;
533
+ var _a, _b, _c, _d, _e;
733
534
  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
535
  const dbTrx = this.toDbTrx(['tx_labels_map', 'tx_labels'], 'readonly', args.trx);
536
+ const store = dbTrx.objectStore('tx_labels_map');
537
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
738
538
  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);
539
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.transactionId) !== undefined) {
540
+ cursor = await store.index('transactionId').openCursor(args.partial.transactionId);
741
541
  }
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);
542
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.txLabelId) !== undefined) {
543
+ cursor = await store.index('txLabelId').openCursor(args.partial.txLabelId);
744
544
  }
745
545
  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
- }
546
+ cursor = await store.openCursor();
547
+ }
548
+ await scanCursor(cursor, args.since, (_d = (_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) !== null && _d !== void 0 ? _d : 0, (_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit, async (r) => {
549
+ if (!(0, idbHelpers_1.matchesTxLabelMapPartial)(r, args.partial))
550
+ return false;
770
551
  if (userId !== undefined) {
771
- const count = await this.countTxLabels({ partial: { userId, txLabelId: r.txLabelId }, trx: dbTrx });
772
- if (count === 0)
773
- continue;
774
- }
775
- if (skipped < offset) {
776
- skipped++;
777
- continue;
552
+ const labelCount = await this.countTxLabels({ partial: { userId, txLabelId: r.txLabelId }, trx: dbTrx });
553
+ if (labelCount === 0)
554
+ return false;
778
555
  }
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)
556
+ return true;
557
+ }, filtered);
558
+ if (args.trx == null)
785
559
  await dbTrx.done;
786
560
  }
787
561
  async findTxLabelMaps(args) {
@@ -822,10 +596,10 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
822
596
  async insertCertificate(certificate, trx) {
823
597
  const e = await this.validateEntityForInsert(certificate, trx, undefined, ['isDeleted']);
824
598
  // Strip non-schema runtime fields before insert. Matches Knex canon.
825
- if (e.logger)
599
+ if (e.logger != null)
826
600
  delete e.logger;
827
601
  const fields = e.fields;
828
- if (e.fields)
602
+ if (e.fields != null)
829
603
  delete e.fields;
830
604
  if (e.certificateId === 0)
831
605
  delete e.certificateId;
@@ -834,7 +608,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
834
608
  try {
835
609
  const id = Number(await store.add(e));
836
610
  certificate.certificateId = id;
837
- if (fields) {
611
+ if (fields != null) {
838
612
  for (const field of fields) {
839
613
  field.certificateId = certificate.certificateId;
840
614
  field.userId = certificate.userId;
@@ -843,7 +617,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
843
617
  }
844
618
  }
845
619
  finally {
846
- if (!trx)
620
+ if (trx == null)
847
621
  await dbTrx.done;
848
622
  }
849
623
  return certificate.certificateId;
@@ -856,7 +630,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
856
630
  await store.add(e);
857
631
  }
858
632
  finally {
859
- if (!trx)
633
+ if (trx == null)
860
634
  await dbTrx.done;
861
635
  }
862
636
  }
@@ -871,7 +645,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
871
645
  commission.commissionId = id;
872
646
  }
873
647
  finally {
874
- if (!trx)
648
+ if (trx == null)
875
649
  await dbTrx.done;
876
650
  }
877
651
  return commission.commissionId;
@@ -887,7 +661,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
887
661
  event.id = id;
888
662
  }
889
663
  finally {
890
- if (!trx)
664
+ if (trx == null)
891
665
  await dbTrx.done;
892
666
  }
893
667
  return event.id;
@@ -903,7 +677,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
903
677
  output.outputId = id;
904
678
  }
905
679
  finally {
906
- if (!trx)
680
+ if (trx == null)
907
681
  await dbTrx.done;
908
682
  }
909
683
  return output.outputId;
@@ -919,7 +693,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
919
693
  basket.basketId = id;
920
694
  }
921
695
  finally {
922
- if (!trx)
696
+ if (trx == null)
923
697
  await dbTrx.done;
924
698
  }
925
699
  return basket.basketId;
@@ -935,7 +709,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
935
709
  tag.outputTagId = id;
936
710
  }
937
711
  finally {
938
- if (!trx)
712
+ if (trx == null)
939
713
  await dbTrx.done;
940
714
  }
941
715
  return tag.outputTagId;
@@ -948,7 +722,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
948
722
  await store.add(e);
949
723
  }
950
724
  finally {
951
- if (!trx)
725
+ if (trx == null)
952
726
  await dbTrx.done;
953
727
  }
954
728
  }
@@ -963,7 +737,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
963
737
  tx.provenTxId = id;
964
738
  }
965
739
  finally {
966
- if (!trx)
740
+ if (trx == null)
967
741
  await dbTrx.done;
968
742
  }
969
743
  return tx.provenTxId;
@@ -979,7 +753,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
979
753
  tx.provenTxReqId = id;
980
754
  }
981
755
  finally {
982
- if (!trx)
756
+ if (trx == null)
983
757
  await dbTrx.done;
984
758
  }
985
759
  return tx.provenTxReqId;
@@ -995,7 +769,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
995
769
  syncState.syncStateId = id;
996
770
  }
997
771
  finally {
998
- if (!trx)
772
+ if (trx == null)
999
773
  await dbTrx.done;
1000
774
  }
1001
775
  return syncState.syncStateId;
@@ -1011,7 +785,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1011
785
  tx.transactionId = id;
1012
786
  }
1013
787
  finally {
1014
- if (!trx)
788
+ if (trx == null)
1015
789
  await dbTrx.done;
1016
790
  }
1017
791
  return tx.transactionId;
@@ -1027,7 +801,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1027
801
  label.txLabelId = id;
1028
802
  }
1029
803
  finally {
1030
- if (!trx)
804
+ if (trx == null)
1031
805
  await dbTrx.done;
1032
806
  }
1033
807
  return label.txLabelId;
@@ -1040,7 +814,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1040
814
  await store.add(e);
1041
815
  }
1042
816
  finally {
1043
- if (!trx)
817
+ if (trx == null)
1044
818
  await dbTrx.done;
1045
819
  }
1046
820
  }
@@ -1055,14 +829,14 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1055
829
  user.userId = id;
1056
830
  }
1057
831
  finally {
1058
- if (!trx)
832
+ if (trx == null)
1059
833
  await dbTrx.done;
1060
834
  }
1061
835
  return user.userId;
1062
836
  }
1063
837
  async updateIdb(id, update, keyProp, storeName, trx) {
1064
838
  if (update[keyProp] !== undefined && (Array.isArray(id) || update[keyProp] !== id)) {
1065
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProp}`, `undefined`);
839
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProp}`, 'undefined');
1066
840
  }
1067
841
  const u = this.validatePartialForUpdate(update);
1068
842
  const dbTrx = this.toDbTrx([storeName], 'readwrite', trx);
@@ -1074,7 +848,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1074
848
  const e = await store.get(i);
1075
849
  // Match Knex/Bun semantics: missing rows produce a 0-row result, not an error.
1076
850
  // Caller receives the true updated count and can decide how to react.
1077
- if (!e)
851
+ if (e == null)
1078
852
  continue;
1079
853
  const v = {
1080
854
  ...e,
@@ -1082,22 +856,23 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1082
856
  };
1083
857
  const uid = await store.put(v);
1084
858
  if (uid !== i)
1085
- throw new WERR_errors_1.WERR_INTERNAL(`updated id ${uid} does not match original ${id}`);
859
+ throw new WERR_errors_1.WERR_INTERNAL(`updated id ${String(uid)} does not match original ${String(id)}`);
1086
860
  updated++;
1087
861
  }
1088
862
  }
1089
863
  finally {
1090
- if (!trx)
864
+ if (trx == null)
1091
865
  await dbTrx.done;
1092
866
  }
1093
867
  return updated;
1094
868
  }
1095
869
  async updateIdbKey(key, update, keyProps, storeName, trx) {
1096
- if (key.length !== keyProps.length)
870
+ if (key.length !== keyProps.length) {
1097
871
  throw new WERR_errors_1.WERR_INTERNAL(`key.length ${key.length} !== keyProps.length ${keyProps.length}`);
872
+ }
1098
873
  for (let i = 0; i < key.length; i++) {
1099
874
  if (update[keyProps[i]] !== undefined && update[keyProps[i]] !== key[i]) {
1100
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProps[i]}`, `undefined`);
875
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER(`update.${keyProps[i]}`, 'undefined');
1101
876
  }
1102
877
  }
1103
878
  const u = this.validatePartialForUpdate(update);
@@ -1105,8 +880,9 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1105
880
  const store = dbTrx.objectStore(storeName);
1106
881
  try {
1107
882
  const e = await store.get(key);
1108
- if (!e)
883
+ if (e == null) {
1109
884
  throw new WERR_errors_1.WERR_INVALID_PARAMETER('key', `an existing record to update ${keyProps.join(',')} ${key.join(',')} not found`);
885
+ }
1110
886
  const v = {
1111
887
  ...e,
1112
888
  ...u
@@ -1114,65 +890,65 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1114
890
  const uid = await store.put(v);
1115
891
  for (let i = 0; i < key.length; i++) {
1116
892
  if (uid[i] !== key[i])
1117
- throw new WERR_errors_1.WERR_INTERNAL(`updated key ${uid[i]} does not match original ${key[i]}`);
893
+ throw new WERR_errors_1.WERR_INTERNAL(`updated key ${String(uid[i])} does not match original ${String(key[i])}`);
1118
894
  }
1119
895
  }
1120
896
  finally {
1121
- if (!trx)
897
+ if (trx == null)
1122
898
  await dbTrx.done;
1123
899
  }
1124
900
  return 1;
1125
901
  }
1126
902
  async updateCertificate(id, update, trx) {
1127
- return this.updateIdb(id, update, 'certificateId', 'certificates', trx);
903
+ return await this.updateIdb(id, update, 'certificateId', 'certificates', trx);
1128
904
  }
1129
905
  async updateCertificateField(certificateId, fieldName, update, trx) {
1130
- return this.updateIdbKey([certificateId, fieldName], update, ['certificateId', 'fieldName'], 'certificate_fields', trx);
906
+ return await this.updateIdbKey([certificateId, fieldName], update, ['certificateId', 'fieldName'], 'certificate_fields', trx);
1131
907
  }
1132
908
  async updateCommission(id, update, trx) {
1133
- return this.updateIdb(id, update, 'commissionId', 'commissions', trx);
909
+ return await this.updateIdb(id, update, 'commissionId', 'commissions', trx);
1134
910
  }
1135
911
  async updateMonitorEvent(id, update, trx) {
1136
- return this.updateIdb(id, update, 'id', 'monitor_events', trx);
912
+ return await this.updateIdb(id, update, 'id', 'monitor_events', trx);
1137
913
  }
1138
914
  async updateOutput(id, update, trx) {
1139
- return this.updateIdb(id, update, 'outputId', 'outputs', trx);
915
+ return await this.updateIdb(id, update, 'outputId', 'outputs', trx);
1140
916
  }
1141
917
  async updateOutputBasket(id, update, trx) {
1142
- return this.updateIdb(id, update, 'basketId', 'output_baskets', trx);
918
+ return await this.updateIdb(id, update, 'basketId', 'output_baskets', trx);
1143
919
  }
1144
920
  async updateOutputTag(id, update, trx) {
1145
- return this.updateIdb(id, update, 'outputTagId', 'output_tags', trx);
921
+ return await this.updateIdb(id, update, 'outputTagId', 'output_tags', trx);
1146
922
  }
1147
923
  async updateProvenTx(id, update, trx) {
1148
- return this.updateIdb(id, update, 'provenTxId', 'proven_txs', trx);
924
+ return await this.updateIdb(id, update, 'provenTxId', 'proven_txs', trx);
1149
925
  }
1150
926
  async updateProvenTxReq(id, update, trx) {
1151
- return this.updateIdb(id, update, 'provenTxReqId', 'proven_tx_reqs', trx);
927
+ return await this.updateIdb(id, update, 'provenTxReqId', 'proven_tx_reqs', trx);
1152
928
  }
1153
929
  async updateSyncState(id, update, trx) {
1154
- return this.updateIdb(id, update, 'syncStateId', 'sync_states', trx);
930
+ return await this.updateIdb(id, update, 'syncStateId', 'sync_states', trx);
1155
931
  }
1156
932
  async updateTransaction(id, update, trx) {
1157
- return this.updateIdb(id, update, 'transactionId', 'transactions', trx);
933
+ return await this.updateIdb(id, update, 'transactionId', 'transactions', trx);
1158
934
  }
1159
935
  async updateTxLabel(id, update, trx) {
1160
- return this.updateIdb(id, update, 'txLabelId', 'tx_labels', trx);
936
+ return await this.updateIdb(id, update, 'txLabelId', 'tx_labels', trx);
1161
937
  }
1162
938
  async updateUser(id, update, trx) {
1163
- return this.updateIdb(id, update, 'userId', 'users', trx);
939
+ return await this.updateIdb(id, update, 'userId', 'users', trx);
1164
940
  }
1165
941
  async updateOutputTagMap(outputId, tagId, update, trx) {
1166
- return this.updateIdbKey([tagId, outputId], update, ['outputTagId', 'outputId'], 'output_tags_map', trx);
942
+ return await this.updateIdbKey([tagId, outputId], update, ['outputTagId', 'outputId'], 'output_tags_map', trx);
1167
943
  }
1168
944
  async updateTxLabelMap(transactionId, txLabelId, update, trx) {
1169
- return this.updateIdbKey([txLabelId, transactionId], update, ['txLabelId', 'transactionId'], 'tx_labels_map', trx);
945
+ return await this.updateIdbKey([txLabelId, transactionId], update, ['txLabelId', 'transactionId'], 'tx_labels_map', trx);
1170
946
  }
1171
947
  //
1172
948
  // StorageReader abstract methods
1173
949
  //
1174
950
  async destroy() {
1175
- if (this.db) {
951
+ if (this.db != null) {
1176
952
  this.db.close();
1177
953
  }
1178
954
  this.db = undefined;
@@ -1184,7 +960,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1184
960
  * @returns
1185
961
  */
1186
962
  async transaction(scope, trx) {
1187
- if (trx)
963
+ if (trx != null)
1188
964
  return await scope(trx);
1189
965
  const stores = this.allStores;
1190
966
  const db = await this.verifyDB();
@@ -1201,61 +977,23 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1201
977
  }
1202
978
  }
1203
979
  async filterCertificateFields(args, filtered) {
1204
- var _a, _b, _c, _d;
980
+ var _a, _b, _c, _d, _e;
1205
981
  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
982
  const dbTrx = this.toDbTrx(['certificate_fields'], 'readonly', args.trx);
983
+ const store = dbTrx.objectStore('certificate_fields');
984
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1210
985
  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);
986
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.certificateId) !== undefined) {
987
+ cursor = await store.index('certificateId').openCursor(args.partial.certificateId);
1216
988
  }
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);
989
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined) {
990
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1219
991
  }
1220
992
  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;
993
+ cursor = await store.openCursor();
1257
994
  }
1258
- if (!args.trx)
995
+ await scanCursor(cursor, args.since, (_d = (_c = args.paged) === null || _c === void 0 ? void 0 : _c.offset) !== null && _d !== void 0 ? _d : 0, (_e = args.paged) === null || _e === void 0 ? void 0 : _e.limit, r => (0, idbHelpers_1.matchesCertificateFieldPartial)(r, args.partial), filtered);
996
+ if (args.trx == null)
1259
997
  await dbTrx.done;
1260
998
  }
1261
999
  async findCertificateFields(args) {
@@ -1265,81 +1003,40 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1265
1003
  });
1266
1004
  return result;
1267
1005
  }
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')
1006
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1007
+ async openCertificatesCursor(
1008
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1009
+ store,
1010
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1011
+ partial
1012
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1013
+ ) {
1014
+ if ((partial === null || partial === void 0 ? void 0 : partial.certificateId) != null && partial.certificateId !== 0)
1015
+ return store.openCursor(partial.certificateId);
1016
+ if ((partial === null || partial === void 0 ? void 0 : partial.userId) !== undefined) {
1017
+ if ((partial === null || partial === void 0 ? void 0 : partial.type) != null && (partial === null || partial === void 0 ? void 0 : partial.certifier) != null && (partial === null || partial === void 0 ? void 0 : partial.serialNumber) != null) {
1018
+ return store
1283
1019
  .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);
1020
+ .openCursor([partial.userId, partial.type, partial.certifier, partial.serialNumber]);
1288
1021
  }
1022
+ return store.index('userId').openCursor(partial.userId);
1289
1023
  }
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)
1024
+ return store.openCursor();
1025
+ }
1026
+ async filterCertificates(args, filtered) {
1027
+ var _a, _b, _c;
1028
+ this.assertNoUndefinedInPartial(args.partial);
1029
+ const dbTrx = this.toDbTrx(['certificates'], 'readonly', args.trx);
1030
+ const store = dbTrx.objectStore('certificates');
1031
+ const cursor = await this.openCertificatesCursor(store, args.partial);
1032
+ await scanCursor(cursor, args.since, (_b = (_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : 0, (_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit, r => {
1033
+ if (args.certifiers != null && !args.certifiers.includes(r.certifier))
1034
+ return false;
1035
+ if (args.types != null && !args.types.includes(r.type))
1036
+ return false;
1037
+ return (0, idbHelpers_1.matchesCertificatePartial)(r, args.partial);
1038
+ }, filtered);
1039
+ if (args.trx == null)
1343
1040
  await dbTrx.done;
1344
1041
  }
1345
1042
  async findCertificates(args) {
@@ -1347,7 +1044,7 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1347
1044
  await this.filterCertificates(args, r => {
1348
1045
  result.push(this.validateEntity(r));
1349
1046
  });
1350
- if (args.includeFields) {
1047
+ if (args.includeFields === true) {
1351
1048
  for (const c of result) {
1352
1049
  const fields = await this.findCertificateFields({ partial: { certificateId: c.certificateId }, trx: args.trx });
1353
1050
  c.fields = fields;
@@ -1356,65 +1053,29 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1356
1053
  return result;
1357
1054
  }
1358
1055
  async filterCommissions(args, filtered) {
1359
- var _a, _b, _c, _d, _e;
1056
+ var _a, _b, _c, _d, _e, _f;
1360
1057
  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;
1058
+ if (args.partial.lockingScript != null) {
1059
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('partial.lockingScript', 'undefined. Commissions may not be found by lockingScript value.');
1060
+ }
1366
1061
  const dbTrx = this.toDbTrx(['commissions'], 'readonly', args.trx);
1062
+ const store = dbTrx.objectStore('commissions');
1063
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1367
1064
  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);
1065
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.commissionId) != null && args.partial.commissionId !== 0) {
1066
+ cursor = await store.openCursor(args.partial.commissionId);
1370
1067
  }
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);
1068
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined) {
1069
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1373
1070
  }
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);
1071
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.transactionId) !== undefined) {
1072
+ cursor = await store.index('transactionId').openCursor(args.partial.transactionId);
1376
1073
  }
1377
1074
  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;
1075
+ cursor = await store.openCursor();
1416
1076
  }
1417
- if (!args.trx)
1077
+ await scanCursor(cursor, args.since, (_e = (_d = args.paged) === null || _d === void 0 ? void 0 : _d.offset) !== null && _e !== void 0 ? _e : 0, (_f = args.paged) === null || _f === void 0 ? void 0 : _f.limit, r => (0, idbHelpers_1.matchesCommissionPartial)(r, args.partial), filtered);
1078
+ if (args.trx == null)
1418
1079
  await dbTrx.done;
1419
1080
  }
1420
1081
  async findCommissions(args) {
@@ -1425,51 +1086,13 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1425
1086
  return result;
1426
1087
  }
1427
1088
  async filterMonitorEvents(args, filtered) {
1428
- var _a, _b, _c;
1089
+ var _a, _b, _c, _d;
1429
1090
  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
1091
  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)
1092
+ const store = dbTrx.objectStore('monitor_events');
1093
+ const cursor = (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.id) != null && args.partial.id !== 0) ? await store.openCursor(args.partial.id) : await store.openCursor();
1094
+ await scanCursor(cursor, args.since, (_c = (_b = args.paged) === null || _b === void 0 ? void 0 : _b.offset) !== null && _c !== void 0 ? _c : 0, (_d = args.paged) === null || _d === void 0 ? void 0 : _d.limit, r => (0, idbHelpers_1.matchesMonitorEventPartial)(r, args.partial), filtered);
1095
+ if (args.trx == null)
1473
1096
  await dbTrx.done;
1474
1097
  }
1475
1098
  async findMonitorEvents(args) {
@@ -1480,70 +1103,26 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1480
1103
  return result;
1481
1104
  }
1482
1105
  async filterOutputBaskets(args, filtered) {
1483
- var _a, _b, _c, _d, _e;
1106
+ var _a, _b, _c, _d, _e, _f, _g;
1484
1107
  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
1108
  const dbTrx = this.toDbTrx(['output_baskets'], 'readonly', args.trx);
1109
+ const store = dbTrx.objectStore('output_baskets');
1110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1489
1111
  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
- }
1112
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.basketId) != null && args.partial.basketId !== 0) {
1113
+ cursor = await store.openCursor(args.partial.basketId);
1114
+ }
1115
+ 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) {
1116
+ cursor = await store.index('name_userId').openCursor([args.partial.name, args.partial.userId]);
1117
+ }
1118
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.userId) !== undefined) {
1119
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1503
1120
  }
1504
1121
  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;
1122
+ cursor = await store.openCursor();
1545
1123
  }
1546
- if (!args.trx)
1124
+ await scanCursor(cursor, args.since, (_f = (_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) !== null && _f !== void 0 ? _f : 0, (_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit, r => (0, idbHelpers_1.matchesOutputBasketPartial)(r, args.partial), filtered);
1125
+ if (args.trx == null)
1547
1126
  await dbTrx.done;
1548
1127
  }
1549
1128
  async findOutputBaskets(args) {
@@ -1553,227 +1132,121 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1553
1132
  });
1554
1133
  return result;
1555
1134
  }
1135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1136
+ async openOutputsCursor(
1137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1138
+ store,
1139
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1140
+ partial, direction
1141
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1142
+ ) {
1143
+ if ((partial === null || partial === void 0 ? void 0 : partial.outputId) != null && partial.outputId !== 0)
1144
+ return store.openCursor(partial.outputId, direction);
1145
+ if ((partial === null || partial === void 0 ? void 0 : partial.userId) !== undefined) {
1146
+ if ((partial === null || partial === void 0 ? void 0 : partial.transactionId) != null && partial.transactionId !== 0 && (partial === null || partial === void 0 ? void 0 : partial.vout) !== undefined) {
1147
+ return store.index('transactionId_vout_userId').openCursor([partial.transactionId, partial.vout, partial.userId], direction);
1148
+ }
1149
+ return store.index('userId').openCursor(partial.userId, direction);
1150
+ }
1151
+ if ((partial === null || partial === void 0 ? void 0 : partial.transactionId) !== undefined)
1152
+ return store.index('transactionId').openCursor(partial.transactionId, direction);
1153
+ if ((partial === null || partial === void 0 ? void 0 : partial.basketId) !== undefined)
1154
+ return store.index('basketId').openCursor(partial.basketId, direction);
1155
+ if ((partial === null || partial === void 0 ? void 0 : partial.spentBy) !== undefined)
1156
+ return store.index('spentBy').openCursor(partial.spentBy, direction);
1157
+ return store.openCursor(null, direction);
1158
+ }
1556
1159
  async filterOutputs(args, filtered, tagIds, isQueryModeAll) {
1557
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1160
+ var _a, _b, _c;
1558
1161
  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;
1162
+ if (args.partial.lockingScript != null) {
1163
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.lockingScript', 'undefined. Outputs may not be found by lockingScript value.');
1164
+ }
1566
1165
  const stores = ['outputs'];
1567
- if (tagIds && tagIds.length > 0) {
1166
+ if (tagIds != null && tagIds.length > 0)
1568
1167
  stores.push('output_tags_map');
1569
- }
1570
- if (args.txStatus) {
1168
+ if (args.txStatus != null)
1571
1169
  stores.push('transactions');
1572
- }
1573
1170
  const dbTrx = this.toDbTrx(stores, 'readonly', args.trx);
1574
- 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({
1171
+ const direction = args.orderDescending === true ? 'prev' : 'next';
1172
+ const store = dbTrx.objectStore('outputs');
1173
+ const cursor = await this.openOutputsCursor(store, args.partial, direction);
1174
+ await scanCursor(cursor, args.since, (_b = (_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : 0, (_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit, async (r) => {
1175
+ if (!(0, idbHelpers_1.matchesOutputPartial)(r, args.partial))
1176
+ return false;
1177
+ if (args.txStatus !== undefined) {
1178
+ const txCount = await this.countTransactions({
1665
1179
  partial: { transactionId: r.transactionId },
1666
1180
  status: args.txStatus,
1667
1181
  trx: dbTrx
1668
1182
  });
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) {
1183
+ if (txCount === 0)
1184
+ return false;
1185
+ }
1186
+ if (tagIds != null && tagIds.length > 0 && !await this.outputMatchesTags(r.outputId, tagIds, isQueryModeAll, dbTrx))
1187
+ return false;
1188
+ return true;
1189
+ }, r => {
1190
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1191
+ if (args.noScript === true)
1695
1192
  r.script = undefined;
1696
- }
1697
1193
  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)
1194
+ });
1195
+ if (args.trx == null)
1703
1196
  await dbTrx.done;
1704
1197
  }
1198
+ async outputMatchesTags(outputId, tagIds, isQueryModeAll, dbTrx) {
1199
+ let ids = [...tagIds];
1200
+ await this.filterOutputTagMaps({ partial: { outputId }, trx: dbTrx }, tm => {
1201
+ if (ids.length > 0) {
1202
+ const i = ids.indexOf(tm.outputTagId);
1203
+ if (i >= 0) {
1204
+ if (isQueryModeAll === true) {
1205
+ ids.splice(i, 1);
1206
+ }
1207
+ else {
1208
+ ids = [];
1209
+ }
1210
+ }
1211
+ }
1212
+ });
1213
+ return ids.length === 0;
1214
+ }
1705
1215
  async findOutputs(args, tagIds, isQueryModeAll) {
1706
1216
  const results = [];
1707
1217
  await this.filterOutputs(args, r => {
1708
1218
  results.push(this.validateEntity(r));
1709
1219
  }, tagIds, isQueryModeAll);
1710
1220
  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)
1221
+ if (args.noScript === true) {
1222
+ o.lockingScript = undefined;
1223
+ }
1224
+ else {
1714
1225
  await this.validateOutputScript(o, args.trx);
1226
+ }
1715
1227
  }
1716
1228
  return results;
1717
1229
  }
1718
1230
  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;
1231
+ var _a, _b, _c, _d, _e, _f, _g;
1724
1232
  const dbTrx = this.toDbTrx(['output_tags'], 'readonly', args.trx);
1233
+ const store = dbTrx.objectStore('output_tags');
1234
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1725
1235
  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
- }
1236
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.outputTagId) != null && args.partial.outputTagId !== 0) {
1237
+ cursor = await store.openCursor(args.partial.outputTagId);
1238
+ }
1239
+ 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) {
1240
+ cursor = await store.index('tag_userId').openCursor([args.partial.tag, args.partial.userId]);
1241
+ }
1242
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.userId) !== undefined) {
1243
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1739
1244
  }
1740
1245
  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;
1246
+ cursor = await store.openCursor();
1775
1247
  }
1776
- if (!args.trx)
1248
+ await scanCursor(cursor, args.since, (_f = (_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) !== null && _f !== void 0 ? _f : 0, (_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit, r => (0, idbHelpers_1.matchesOutputTagPartial)(r, args.partial), filtered);
1249
+ if (args.trx == null)
1777
1250
  await dbTrx.done;
1778
1251
  }
1779
1252
  async findOutputTags(args) {
@@ -1785,77 +1258,30 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1785
1258
  }
1786
1259
  async filterSyncStates(args, filtered) {
1787
1260
  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;
1261
+ if (args.partial.syncMap != null && args.partial.syncMap !== '') {
1262
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.syncMap', 'undefined. SyncStates may not be found by syncMap value.');
1263
+ }
1794
1264
  const dbTrx = this.toDbTrx(['sync_states'], 'readonly', args.trx);
1265
+ const store = dbTrx.objectStore('sync_states');
1266
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1795
1267
  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);
1268
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.syncStateId) != null && args.partial.syncStateId !== 0) {
1269
+ cursor = await store.openCursor(args.partial.syncStateId);
1798
1270
  }
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);
1271
+ else if (((_b = args.partial) === null || _b === void 0 ? void 0 : _b.userId) !== undefined) {
1272
+ cursor = await store.index('userId').openCursor(args.partial.userId);
1801
1273
  }
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);
1274
+ else if (((_c = args.partial) === null || _c === void 0 ? void 0 : _c.refNum) !== undefined) {
1275
+ cursor = await store.index('refNum').openCursor(args.partial.refNum);
1804
1276
  }
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);
1277
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.status) !== undefined) {
1278
+ cursor = await store.index('status').openCursor(args.partial.status);
1807
1279
  }
1808
1280
  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;
1281
+ cursor = await store.openCursor();
1857
1282
  }
1858
- if (!args.trx)
1283
+ await scanCursor(cursor, args.since, (_f = (_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) !== null && _f !== void 0 ? _f : 0, (_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit, r => (0, idbHelpers_1.matchesSyncStatePartial)(r, args.partial), filtered);
1284
+ if (args.trx == null)
1859
1285
  await dbTrx.done;
1860
1286
  }
1861
1287
  async findSyncStates(args) {
@@ -1865,125 +1291,77 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1865
1291
  });
1866
1292
  return result;
1867
1293
  }
1294
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1295
+ async openTransactionsCursor(
1296
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1297
+ store,
1298
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1299
+ partial, direction
1300
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1301
+ ) {
1302
+ if ((partial === null || partial === void 0 ? void 0 : partial.transactionId) != null && partial.transactionId !== 0)
1303
+ return store.openCursor(partial.transactionId, direction);
1304
+ if ((partial === null || partial === void 0 ? void 0 : partial.userId) !== undefined) {
1305
+ if ((partial === null || partial === void 0 ? void 0 : partial.status) !== undefined) {
1306
+ return store.index('status_userId').openCursor([partial.status, partial.userId], direction);
1307
+ }
1308
+ return store.index('userId').openCursor(partial.userId, direction);
1309
+ }
1310
+ if ((partial === null || partial === void 0 ? void 0 : partial.status) !== undefined)
1311
+ return store.index('status').openCursor(partial.status, direction);
1312
+ if ((partial === null || partial === void 0 ? void 0 : partial.provenTxId) !== undefined)
1313
+ return store.index('provenTxId').openCursor(partial.provenTxId, direction);
1314
+ if ((partial === null || partial === void 0 ? void 0 : partial.reference) !== undefined)
1315
+ return store.index('reference').openCursor(partial.reference, direction);
1316
+ return store.openCursor(null, direction);
1317
+ }
1868
1318
  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;
1319
+ var _a, _b, _c;
1320
+ if (args.partial.rawTx != null) {
1321
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.rawTx', 'undefined. Transactions may not be found by rawTx value.');
1322
+ }
1323
+ if (args.partial.inputBEEF != null) {
1324
+ throw new WERR_errors_1.WERR_INVALID_PARAMETER('args.partial.inputBEEF', 'undefined. Transactions may not be found by inputBEEF value.');
1325
+ }
1878
1326
  const stores = ['transactions'];
1879
- if (labelIds && labelIds.length > 0) {
1327
+ if (labelIds != null && labelIds.length > 0)
1880
1328
  stores.push('tx_labels_map');
1881
- }
1882
1329
  const dbTrx = this.toDbTrx(stores, 'readonly', args.trx);
1883
- 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
- }
1330
+ const direction = args.orderDescending === true ? 'prev' : 'next';
1331
+ const store = dbTrx.objectStore('transactions');
1332
+ const cursor = await this.openTransactionsCursor(store, args.partial, direction);
1333
+ await scanCursor(cursor, args.since, (_b = (_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : 0, (_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit, async (r) => {
1334
+ if (args.from != null && r.created_at.getTime() < args.from.getTime())
1335
+ return false;
1336
+ if (args.to != null && r.created_at.getTime() >= args.to.getTime())
1337
+ return false;
1338
+ if (args.status != null && !args.status.includes(r.status))
1339
+ return false;
1340
+ if (!(0, idbHelpers_1.matchesTransactionPartial)(r, args.partial))
1341
+ return false;
1342
+ if (labelIds != null && labelIds.length > 0 && !await this.transactionMatchesLabels(r.transactionId, labelIds, isQueryModeAll, dbTrx))
1343
+ return false;
1344
+ return true;
1345
+ }, filtered);
1346
+ if (args.trx == null)
1347
+ await dbTrx.done;
1348
+ }
1349
+ async transactionMatchesLabels(transactionId, labelIds, isQueryModeAll, dbTrx) {
1350
+ let ids = [...labelIds];
1351
+ await this.filterTxLabelMaps({ partial: { transactionId }, trx: dbTrx }, lm => {
1352
+ if (ids.length > 0) {
1353
+ const i = ids.indexOf(lm.txLabelId);
1354
+ if (i >= 0) {
1355
+ if (isQueryModeAll === true) {
1356
+ ids.splice(i, 1);
1971
1357
  }
1972
- });
1973
- if (ids.length > 0)
1974
- continue;
1975
- }
1976
- if (skipped < offset) {
1977
- skipped++;
1978
- continue;
1358
+ else {
1359
+ ids = [];
1360
+ }
1361
+ }
1979
1362
  }
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;
1363
+ });
1364
+ return ids.length === 0;
1987
1365
  }
1988
1366
  async findTransactions(args, labelIds, isQueryModeAll) {
1989
1367
  const results = [];
@@ -1991,75 +1369,36 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
1991
1369
  results.push(this.validateEntity(r));
1992
1370
  }, labelIds, isQueryModeAll);
1993
1371
  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
1372
+ if (args.noRawTx === true) {
2000
1373
  t.rawTx = undefined;
1374
+ t.inputBEEF = undefined;
1375
+ }
1376
+ else {
1377
+ await this.validateRawTransaction(t, args.trx);
1378
+ }
2001
1379
  }
2002
1380
  return results;
2003
1381
  }
2004
1382
  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;
1383
+ var _a, _b, _c, _d, _e, _f, _g;
2010
1384
  const dbTrx = this.toDbTrx(['tx_labels'], 'readonly', args.trx);
1385
+ const store = dbTrx.objectStore('tx_labels');
1386
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2011
1387
  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
- }
1388
+ if (((_a = args.partial) === null || _a === void 0 ? void 0 : _a.txLabelId) != null && args.partial.txLabelId !== 0) {
1389
+ cursor = await store.openCursor(args.partial.txLabelId);
1390
+ }
1391
+ 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) {
1392
+ cursor = await store.index('label_userId').openCursor([args.partial.label, args.partial.userId]);
1393
+ }
1394
+ else if (((_d = args.partial) === null || _d === void 0 ? void 0 : _d.userId) !== undefined) {
1395
+ cursor = await store.index('userId').openCursor(args.partial.userId);
2025
1396
  }
2026
1397
  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;
1398
+ cursor = await store.openCursor();
2061
1399
  }
2062
- if (!args.trx)
1400
+ await scanCursor(cursor, args.since, (_f = (_e = args.paged) === null || _e === void 0 ? void 0 : _e.offset) !== null && _f !== void 0 ? _f : 0, (_g = args.paged) === null || _g === void 0 ? void 0 : _g.limit, r => (0, idbHelpers_1.matchesTxLabelPartial)(r, args.partial), filtered);
1401
+ if (args.trx == null)
2063
1402
  await dbTrx.done;
2064
1403
  }
2065
1404
  async findTxLabels(args) {
@@ -2069,46 +1408,27 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2069
1408
  });
2070
1409
  return result;
2071
1410
  }
1411
+ matchesUserPartial(r, partial) {
1412
+ if (partial == null)
1413
+ return true;
1414
+ if (partial.userId != null && partial.userId !== 0 && r.userId !== partial.userId)
1415
+ return false;
1416
+ if ((partial.created_at != null) && r.created_at.getTime() !== partial.created_at.getTime())
1417
+ return false;
1418
+ if ((partial.updated_at != null) && r.updated_at.getTime() !== partial.updated_at.getTime())
1419
+ return false;
1420
+ if (partial.identityKey != null && partial.identityKey !== '' && r.identityKey !== partial.identityKey)
1421
+ return false;
1422
+ if (partial.activeStorage != null && partial.activeStorage !== '' && r.activeStorage !== partial.activeStorage)
1423
+ return false;
1424
+ return true;
1425
+ }
2072
1426
  async filterUsers(args, filtered) {
2073
- 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;
1427
+ var _a, _b, _c;
2078
1428
  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)
1429
+ const cursor = await dbTrx.objectStore('users').openCursor();
1430
+ await scanCursor(cursor, args.since, (_b = (_a = args.paged) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : 0, (_c = args.paged) === null || _c === void 0 ? void 0 : _c.limit, r => this.matchesUserPartial(r, args.partial), filtered);
1431
+ if (args.trx == null)
2112
1432
  await dbTrx.done;
2113
1433
  }
2114
1434
  async findUsers(args) {
@@ -2248,9 +1568,8 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2248
1568
  return results;
2249
1569
  }
2250
1570
  async verifyReadyForDatabaseAccess(trx) {
2251
- if (!this._settings) {
2252
- this._settings = await this.readSettings();
2253
- }
1571
+ var _a;
1572
+ (_a = this._settings) !== null && _a !== void 0 ? _a : (this._settings = await this.readSettings());
2254
1573
  return this._settings.dbtype;
2255
1574
  }
2256
1575
  /**
@@ -2260,18 +1579,30 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2260
1579
  validateEntity(entity, dateFields, booleanFields) {
2261
1580
  entity.created_at = this.validateDate(entity.created_at);
2262
1581
  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
- }
1582
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1583
+ const e = entity;
1584
+ this.applyDateFields(e, dateFields);
1585
+ this.applyBooleanFields(e, booleanFields);
1586
+ this.normalizeEntityValues(e);
1587
+ return entity;
1588
+ }
1589
+ applyDateFields(entity, dateFields) {
1590
+ if (dateFields == null)
1591
+ return;
1592
+ for (const df of dateFields) {
1593
+ if (entity[df] != null)
1594
+ entity[df] = this.validateDate(entity[df]);
2268
1595
  }
2269
- if (booleanFields) {
2270
- for (const df of booleanFields) {
2271
- if (entity[df] !== undefined)
2272
- entity[df] = !!entity[df];
2273
- }
1596
+ }
1597
+ applyBooleanFields(entity, booleanFields) {
1598
+ if (booleanFields == null)
1599
+ return;
1600
+ for (const df of booleanFields) {
1601
+ if (entity[df] !== undefined)
1602
+ entity[df] = entity[df] !== 0 && entity[df] != null && entity[df] !== false;
2274
1603
  }
1604
+ }
1605
+ normalizeEntityValues(entity) {
2275
1606
  for (const key of Object.keys(entity)) {
2276
1607
  const val = entity[key];
2277
1608
  if (val === null) {
@@ -2281,7 +1612,6 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2281
1612
  entity[key] = Array.from(val);
2282
1613
  }
2283
1614
  }
2284
- return entity;
2285
1615
  }
2286
1616
  /**
2287
1617
  * Helper to force uniform behavior across database engines.
@@ -2299,29 +1629,38 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2299
1629
  * Use to process the update template for entities being updated.
2300
1630
  */
2301
1631
  validatePartialForUpdate(update, dateFields, booleanFields) {
2302
- if (!this.dbtype)
1632
+ if (this.dbtype == null)
2303
1633
  throw new WERR_errors_1.WERR_INTERNAL('must call verifyReadyForDatabaseAccess first');
2304
1634
  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);
2309
- if (!v.created_at)
1635
+ v.created_at = v.created_at != null ? this.validateEntityDate(v.created_at) : undefined;
1636
+ if (v.created_at == null)
2310
1637
  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
- }
1638
+ v.updated_at = v.updated_at != null ? this.validateEntityDate(v.updated_at) : this.validateEntityDate(new Date());
1639
+ this.applyOptionalDateFields(v, dateFields);
1640
+ this.applyIntegerBooleanFields(update, booleanFields);
1641
+ this.normalizeForStorage(v);
1642
+ this.isDirty = true;
1643
+ return v;
1644
+ }
1645
+ applyOptionalDateFields(v, dateFields) {
1646
+ if (dateFields == null)
1647
+ return;
1648
+ for (const df of dateFields) {
1649
+ if (v[df] != null)
1650
+ v[df] = this.validateOptionalEntityDate(v[df]);
2318
1651
  }
2319
- if (booleanFields) {
2320
- for (const df of booleanFields) {
2321
- if (update[df] !== undefined)
2322
- update[df] = !!update[df] ? 1 : 0;
2323
- }
1652
+ }
1653
+ applyIntegerBooleanFields(update, booleanFields) {
1654
+ if (booleanFields == null)
1655
+ return;
1656
+ for (const df of booleanFields) {
1657
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1658
+ const u = update;
1659
+ if (u[df] !== undefined)
1660
+ u[df] = u[df] != null && u[df] !== false ? 1 : 0;
2324
1661
  }
1662
+ }
1663
+ normalizeForStorage(v) {
2325
1664
  for (const key of Object.keys(v)) {
2326
1665
  const val = v[key];
2327
1666
  if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
@@ -2331,53 +1670,34 @@ class StorageIdb extends StorageProvider_1.StorageProvider {
2331
1670
  v[key] = undefined;
2332
1671
  }
2333
1672
  }
2334
- this.isDirty = true;
2335
- return v;
2336
1673
  }
2337
1674
  /**
2338
1675
  * Helper to force uniform behavior across database engines.
2339
1676
  * Use to process new entities being inserted into the database.
2340
1677
  */
2341
1678
  async validateEntityForInsert(entity, trx, dateFields, booleanFields) {
1679
+ var _a, _b;
2342
1680
  await this.verifyReadyForDatabaseAccess(trx);
2343
1681
  const v = { ...entity };
2344
- v.created_at = this.validateOptionalEntityDate(v.created_at, true);
2345
- v.updated_at = this.validateOptionalEntityDate(v.updated_at, true);
2346
- if (!v.created_at)
1682
+ v.created_at = (_a = this.validateOptionalEntityDate(v.created_at, true)) !== null && _a !== void 0 ? _a : new Date();
1683
+ v.updated_at = (_b = this.validateOptionalEntityDate(v.updated_at, true)) !== null && _b !== void 0 ? _b : new Date();
1684
+ if (v.created_at == null)
2347
1685
  delete v.created_at;
2348
- if (!v.updated_at)
1686
+ if (v.updated_at == null)
2349
1687
  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
- }
1688
+ this.applyOptionalDateFields(v, dateFields);
1689
+ this.applyIntegerBooleanFields(entity, booleanFields);
1690
+ this.normalizeForStorage(v);
2371
1691
  this.isDirty = true;
2372
1692
  return v;
2373
1693
  }
2374
1694
  async validateRawTransaction(t, trx) {
2375
1695
  // if there is no txid or there is a rawTransaction return what we have.
2376
- if (t.rawTx || !t.txid)
1696
+ if (t.rawTx != null || t.txid == null || t.txid === '')
2377
1697
  return;
2378
1698
  // rawTransaction is missing, see if we moved it ...
2379
1699
  const rawTx = await this.getRawTxOfKnownValidTransaction(t.txid, undefined, undefined, trx);
2380
- if (!rawTx)
1700
+ if (rawTx == null)
2381
1701
  return;
2382
1702
  t.rawTx = rawTx;
2383
1703
  }