@bsv/wallet-toolbox 2.1.25 → 3.0.0-alpha.0

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 (257) hide show
  1. package/docs/CREATEACTION_BLOCKERS.md +391 -0
  2. package/docs/CUTOVER_RUNBOOK.md +95 -0
  3. package/docs/REQUIREMENTS_COMPLIANCE.md +157 -0
  4. package/docs/ROLLOUT_PLAN.md +273 -0
  5. package/docs/SESSION_HANDOFF.md +298 -0
  6. package/docs/STORAGE_METHOD_WIRING.md +176 -0
  7. package/docs/client.md +3765 -1325
  8. package/docs/monitor.md +255 -33
  9. package/docs/services.md +304 -280
  10. package/docs/setup.md +24 -24
  11. package/docs/storage.md +2783 -251
  12. package/docs/v3-upgrade/index.html +911 -0
  13. package/docs/wallet.md +4956 -9455
  14. package/out/src/Wallet.d.ts.map +1 -1
  15. package/out/src/Wallet.js.map +1 -1
  16. package/out/src/WalletLogger.d.ts.map +1 -1
  17. package/out/src/WalletLogger.js.map +1 -1
  18. package/out/src/__tests/CWIStyleWalletManager.test.js.map +1 -1
  19. package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts.map +1 -1
  20. package/out/src/__tests/WalletPermissionsManager.fixtures.js.map +1 -1
  21. package/out/src/entropy/EntropyCollector.d.ts.map +1 -1
  22. package/out/src/entropy/EntropyCollector.js.map +1 -1
  23. package/out/src/monitor/LeasedMonitorTask.d.ts +43 -0
  24. package/out/src/monitor/LeasedMonitorTask.d.ts.map +1 -0
  25. package/out/src/monitor/LeasedMonitorTask.js +89 -0
  26. package/out/src/monitor/LeasedMonitorTask.js.map +1 -0
  27. package/out/src/monitor/Monitor.d.ts +7 -0
  28. package/out/src/monitor/Monitor.d.ts.map +1 -1
  29. package/out/src/monitor/Monitor.js +7 -0
  30. package/out/src/monitor/Monitor.js.map +1 -1
  31. package/out/src/monitor/MonitorDaemon.d.ts.map +1 -1
  32. package/out/src/monitor/MonitorDaemon.js.map +1 -1
  33. package/out/src/monitor/V7LeasedTask.d.ts +43 -0
  34. package/out/src/monitor/V7LeasedTask.d.ts.map +1 -0
  35. package/out/src/monitor/V7LeasedTask.js +89 -0
  36. package/out/src/monitor/V7LeasedTask.js.map +1 -0
  37. package/out/src/monitor/index.all.d.ts +1 -0
  38. package/out/src/monitor/index.all.d.ts.map +1 -1
  39. package/out/src/monitor/index.all.js +1 -0
  40. package/out/src/monitor/index.all.js.map +1 -1
  41. package/out/src/monitor/tasks/TaskCheckForProofs.d.ts +2 -0
  42. package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
  43. package/out/src/monitor/tasks/TaskCheckForProofs.js +55 -0
  44. package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
  45. package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
  46. package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
  47. package/out/src/sdk/WalletStorage.interfaces.d.ts +59 -59
  48. package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  49. package/out/src/sdk/types.d.ts +32 -0
  50. package/out/src/sdk/types.d.ts.map +1 -1
  51. package/out/src/sdk/types.js +50 -1
  52. package/out/src/sdk/types.js.map +1 -1
  53. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
  54. package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
  55. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.d.ts.map +1 -1
  56. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js.map +1 -1
  57. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.d.ts.map +1 -1
  58. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js.map +1 -1
  59. package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.d.ts.map +1 -1
  60. package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.js.map +1 -1
  61. package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.d.ts.map +1 -1
  62. package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.js.map +1 -1
  63. package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.d.ts.map +1 -1
  64. package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.js.map +1 -1
  65. package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts.map +1 -1
  66. package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.js.map +1 -1
  67. package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.d.ts.map +1 -1
  68. package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.js.map +1 -1
  69. package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts.map +1 -1
  70. package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.js.map +1 -1
  71. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.d.ts.map +1 -1
  72. package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js.map +1 -1
  73. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFs.d.ts.map +1 -1
  74. package/out/src/services/chaintracker/chaintracks/util/ChaintracksFs.js.map +1 -1
  75. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts.map +1 -1
  76. package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.js.map +1 -1
  77. package/out/src/services/chaintracker/chaintracks/util/__tests/SingleWriterMultiReaderLock.test.js.map +1 -1
  78. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  79. package/out/src/storage/StorageIdb.js +10 -5
  80. package/out/src/storage/StorageIdb.js.map +1 -1
  81. package/out/src/storage/StorageKnex.d.ts +133 -3
  82. package/out/src/storage/StorageKnex.d.ts.map +1 -1
  83. package/out/src/storage/StorageKnex.js +691 -94
  84. package/out/src/storage/StorageKnex.js.map +1 -1
  85. package/out/src/storage/StorageProvider.d.ts +114 -1
  86. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  87. package/out/src/storage/StorageProvider.js +164 -4
  88. package/out/src/storage/StorageProvider.js.map +1 -1
  89. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  90. package/out/src/storage/WalletStorageManager.js.map +1 -1
  91. package/out/src/storage/idbHelpers.d.ts +5 -0
  92. package/out/src/storage/idbHelpers.d.ts.map +1 -1
  93. package/out/src/storage/idbHelpers.js +42 -0
  94. package/out/src/storage/idbHelpers.js.map +1 -1
  95. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
  96. package/out/src/storage/methods/attemptToPostReqsToNetwork.js +116 -4
  97. package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  98. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  99. package/out/src/storage/methods/createAction.js +22 -5
  100. package/out/src/storage/methods/createAction.js.map +1 -1
  101. package/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
  102. package/out/src/storage/methods/internalizeAction.js +172 -5
  103. package/out/src/storage/methods/internalizeAction.js.map +1 -1
  104. package/out/src/storage/methods/listActionsKnex.d.ts +49 -0
  105. package/out/src/storage/methods/listActionsKnex.d.ts.map +1 -1
  106. package/out/src/storage/methods/listActionsKnex.js +179 -69
  107. package/out/src/storage/methods/listActionsKnex.js.map +1 -1
  108. package/out/src/storage/methods/listOutputsKnex.d.ts.map +1 -1
  109. package/out/src/storage/methods/listOutputsKnex.js +51 -4
  110. package/out/src/storage/methods/listOutputsKnex.js.map +1 -1
  111. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  112. package/out/src/storage/methods/processAction.js +82 -14
  113. package/out/src/storage/methods/processAction.js.map +1 -1
  114. package/out/src/storage/methods/purgeData.d.ts.map +1 -1
  115. package/out/src/storage/methods/purgeData.js +22 -14
  116. package/out/src/storage/methods/purgeData.js.map +1 -1
  117. package/out/src/storage/methods/reviewStatus.d.ts.map +1 -1
  118. package/out/src/storage/methods/reviewStatus.js +18 -9
  119. package/out/src/storage/methods/reviewStatus.js.map +1 -1
  120. package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
  121. package/out/src/storage/schema/KnexMigrations.js +134 -0
  122. package/out/src/storage/schema/KnexMigrations.js.map +1 -1
  123. package/out/src/storage/schema/StorageIdbSchema.d.ts +43 -2
  124. package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
  125. package/out/src/storage/schema/__tests/backfill.runner.test.d.ts +2 -0
  126. package/out/src/storage/schema/__tests/backfill.runner.test.d.ts.map +1 -0
  127. package/out/src/storage/schema/__tests/backfill.runner.test.js +148 -0
  128. package/out/src/storage/schema/__tests/backfill.runner.test.js.map +1 -0
  129. package/out/src/storage/schema/__tests/backfill.test.d.ts +2 -0
  130. package/out/src/storage/schema/__tests/backfill.test.d.ts.map +1 -0
  131. package/out/src/storage/schema/__tests/backfill.test.js +96 -0
  132. package/out/src/storage/schema/__tests/backfill.test.js.map +1 -0
  133. package/out/src/storage/schema/__tests/processingFsm.test.d.ts +2 -0
  134. package/out/src/storage/schema/__tests/processingFsm.test.d.ts.map +1 -0
  135. package/out/src/storage/schema/__tests/processingFsm.test.js +42 -0
  136. package/out/src/storage/schema/__tests/processingFsm.test.js.map +1 -0
  137. package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.d.ts +2 -0
  138. package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.d.ts.map +1 -0
  139. package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.js +82 -0
  140. package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.js.map +1 -0
  141. package/out/src/storage/schema/__tests/spendabilityRule.test.d.ts +2 -0
  142. package/out/src/storage/schema/__tests/spendabilityRule.test.d.ts.map +1 -0
  143. package/out/src/storage/schema/__tests/spendabilityRule.test.js +29 -0
  144. package/out/src/storage/schema/__tests/spendabilityRule.test.js.map +1 -0
  145. package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.d.ts +2 -0
  146. package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.d.ts.map +1 -0
  147. package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.js +77 -0
  148. package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.js.map +1 -0
  149. package/out/src/storage/schema/backfill.d.ts +35 -0
  150. package/out/src/storage/schema/backfill.d.ts.map +1 -0
  151. package/out/src/storage/schema/backfill.idb.d.ts +32 -0
  152. package/out/src/storage/schema/backfill.idb.d.ts.map +1 -0
  153. package/out/src/storage/schema/backfill.idb.js +95 -0
  154. package/out/src/storage/schema/backfill.idb.js.map +1 -0
  155. package/out/src/storage/schema/backfill.js +150 -0
  156. package/out/src/storage/schema/backfill.js.map +1 -0
  157. package/out/src/storage/schema/backfill.knex.d.ts +32 -0
  158. package/out/src/storage/schema/backfill.knex.d.ts.map +1 -0
  159. package/out/src/storage/schema/backfill.knex.js +240 -0
  160. package/out/src/storage/schema/backfill.knex.js.map +1 -0
  161. package/out/src/storage/schema/backfill.runner.d.ts +63 -0
  162. package/out/src/storage/schema/backfill.runner.d.ts.map +1 -0
  163. package/out/src/storage/schema/backfill.runner.js +64 -0
  164. package/out/src/storage/schema/backfill.runner.js.map +1 -0
  165. package/out/src/storage/schema/coinbaseMaturityBackfill.d.ts +25 -0
  166. package/out/src/storage/schema/coinbaseMaturityBackfill.d.ts.map +1 -0
  167. package/out/src/storage/schema/coinbaseMaturityBackfill.js +75 -0
  168. package/out/src/storage/schema/coinbaseMaturityBackfill.js.map +1 -0
  169. package/out/src/storage/schema/monitorLease.d.ts +57 -0
  170. package/out/src/storage/schema/monitorLease.d.ts.map +1 -0
  171. package/out/src/storage/schema/monitorLease.js +101 -0
  172. package/out/src/storage/schema/monitorLease.js.map +1 -0
  173. package/out/src/storage/schema/processingFsm.d.ts +27 -0
  174. package/out/src/storage/schema/processingFsm.d.ts.map +1 -0
  175. package/out/src/storage/schema/processingFsm.js +132 -0
  176. package/out/src/storage/schema/processingFsm.js.map +1 -0
  177. package/out/src/storage/schema/schemaCutover.d.ts +34 -0
  178. package/out/src/storage/schema/schemaCutover.d.ts.map +1 -0
  179. package/out/src/storage/schema/schemaCutover.js +230 -0
  180. package/out/src/storage/schema/schemaCutover.js.map +1 -0
  181. package/out/src/storage/schema/schemaCutoverIdb.d.ts +26 -0
  182. package/out/src/storage/schema/schemaCutoverIdb.d.ts.map +1 -0
  183. package/out/src/storage/schema/schemaCutoverIdb.js +90 -0
  184. package/out/src/storage/schema/schemaCutoverIdb.js.map +1 -0
  185. package/out/src/storage/schema/spendabilityRefresh.d.ts +49 -0
  186. package/out/src/storage/schema/spendabilityRefresh.d.ts.map +1 -0
  187. package/out/src/storage/schema/spendabilityRefresh.js +120 -0
  188. package/out/src/storage/schema/spendabilityRefresh.js.map +1 -0
  189. package/out/src/storage/schema/spendabilityRule.d.ts +45 -0
  190. package/out/src/storage/schema/spendabilityRule.d.ts.map +1 -0
  191. package/out/src/storage/schema/spendabilityRule.js +52 -0
  192. package/out/src/storage/schema/spendabilityRule.js.map +1 -0
  193. package/out/src/storage/schema/tables/TableAction.d.ts +3 -3
  194. package/out/src/storage/schema/tables/TableAction.d.ts.map +1 -1
  195. package/out/src/storage/schema/tables/TableChainTip.d.ts +1 -1
  196. package/out/src/storage/schema/tables/TableMonitorLease.d.ts +1 -1
  197. package/out/src/storage/schema/tables/TableOutput.d.ts +7 -0
  198. package/out/src/storage/schema/tables/TableOutput.d.ts.map +1 -1
  199. package/out/src/storage/schema/tables/TableOutput.js.map +1 -1
  200. package/out/src/storage/schema/tables/TableTransactionNew.d.ts +50 -0
  201. package/out/src/storage/schema/tables/TableTransactionNew.d.ts.map +1 -0
  202. package/out/src/storage/schema/tables/TableTransactionNew.js +3 -0
  203. package/out/src/storage/schema/tables/TableTransactionNew.js.map +1 -0
  204. package/out/src/storage/schema/tables/TableTxAudit.d.ts +1 -1
  205. package/out/src/storage/schema/tables/index.d.ts +5 -0
  206. package/out/src/storage/schema/tables/index.d.ts.map +1 -1
  207. package/out/src/storage/schema/tables/index.js +5 -0
  208. package/out/src/storage/schema/tables/index.js.map +1 -1
  209. package/out/src/storage/schema/transactionCrud.d.ts +41 -0
  210. package/out/src/storage/schema/transactionCrud.d.ts.map +1 -0
  211. package/out/src/storage/schema/transactionCrud.js +205 -0
  212. package/out/src/storage/schema/transactionCrud.js.map +1 -0
  213. package/out/src/storage/schema/transactionService.d.ts +315 -0
  214. package/out/src/storage/schema/transactionService.d.ts.map +1 -0
  215. package/out/src/storage/schema/transactionService.js +783 -0
  216. package/out/src/storage/schema/transactionService.js.map +1 -0
  217. package/out/src/storage/schema/txAudit.d.ts +33 -0
  218. package/out/src/storage/schema/txAudit.d.ts.map +1 -0
  219. package/out/src/storage/schema/txAudit.js +64 -0
  220. package/out/src/storage/schema/txAudit.js.map +1 -0
  221. package/out/src/storage/schema/v7Backfill.d.ts.map +1 -1
  222. package/out/src/storage/schema/v7Backfill.js +4 -1
  223. package/out/src/storage/schema/v7Backfill.js.map +1 -1
  224. package/out/src/storage/schema/v7Backfill.runner.d.ts.map +1 -1
  225. package/out/src/storage/schema/v7Backfill.runner.js +3 -1
  226. package/out/src/storage/schema/v7Backfill.runner.js.map +1 -1
  227. package/out/src/storage/schema/v7CoinbaseMaturityBackfill.d.ts +25 -0
  228. package/out/src/storage/schema/v7CoinbaseMaturityBackfill.d.ts.map +1 -0
  229. package/out/src/storage/schema/v7CoinbaseMaturityBackfill.js +75 -0
  230. package/out/src/storage/schema/v7CoinbaseMaturityBackfill.js.map +1 -0
  231. package/out/src/storage/schema/v7Crud.d.ts +5 -3
  232. package/out/src/storage/schema/v7Crud.d.ts.map +1 -1
  233. package/out/src/storage/schema/v7Crud.js +11 -9
  234. package/out/src/storage/schema/v7Crud.js.map +1 -1
  235. package/out/src/storage/schema/v7Cutover.d.ts +34 -0
  236. package/out/src/storage/schema/v7Cutover.d.ts.map +1 -0
  237. package/out/src/storage/schema/v7Cutover.js +223 -0
  238. package/out/src/storage/schema/v7Cutover.js.map +1 -0
  239. package/out/src/storage/schema/v7CutoverIdb.d.ts +26 -0
  240. package/out/src/storage/schema/v7CutoverIdb.d.ts.map +1 -0
  241. package/out/src/storage/schema/v7CutoverIdb.js +90 -0
  242. package/out/src/storage/schema/v7CutoverIdb.js.map +1 -0
  243. package/out/src/storage/schema/v7Fsm.d.ts.map +1 -1
  244. package/out/src/storage/schema/v7Fsm.js +22 -6
  245. package/out/src/storage/schema/v7Fsm.js.map +1 -1
  246. package/out/src/storage/schema/v7Service.d.ts +305 -0
  247. package/out/src/storage/schema/v7Service.d.ts.map +1 -0
  248. package/out/src/storage/schema/v7Service.js +757 -0
  249. package/out/src/storage/schema/v7Service.js.map +1 -0
  250. package/out/src/storage/schema/v7SpendabilityRefresh.d.ts +49 -0
  251. package/out/src/storage/schema/v7SpendabilityRefresh.d.ts.map +1 -0
  252. package/out/src/storage/schema/v7SpendabilityRefresh.js +111 -0
  253. package/out/src/storage/schema/v7SpendabilityRefresh.js.map +1 -0
  254. package/out/src/storage/storageProviderHelpers.js +1 -1
  255. package/out/src/storage/storageProviderHelpers.js.map +1 -1
  256. package/out/src/utility/Format.js.map +1 -1
  257. package/package.json +7 -4
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tryClaimLease = tryClaimLease;
4
+ exports.renewLease = renewLease;
5
+ exports.releaseLease = releaseLease;
6
+ /**
7
+ * Try to claim a lease on `taskName`. Succeeds iff:
8
+ * - no row exists for the task, OR
9
+ * - the existing row has `expiresAt <= now`, OR
10
+ * - the existing row's `ownerId` already equals the requested owner.
11
+ *
12
+ * On success the row is upserted with `expiresAt = now + ttlMs` and
13
+ * `renewCount = renewCount + 1` (0 for fresh rows).
14
+ */
15
+ async function tryClaimLease(knex, claim, now = new Date()) {
16
+ const expiresAt = new Date(now.getTime() + claim.ttlMs);
17
+ return await knex.transaction(async (trx) => {
18
+ var _a, _b;
19
+ const existing = await trx('monitor_lease').where({ task_name: claim.taskName }).forUpdate().first();
20
+ const canClaim = existing == null ||
21
+ new Date(existing.expires_at).getTime() <= now.getTime() ||
22
+ existing.owner_id === claim.ownerId;
23
+ if (!canClaim)
24
+ return { acquired: false };
25
+ if (existing == null) {
26
+ await trx('monitor_lease').insert({
27
+ task_name: claim.taskName,
28
+ owner_id: claim.ownerId,
29
+ expires_at: expiresAt,
30
+ renew_count: 0,
31
+ note: (_a = claim.note) !== null && _a !== void 0 ? _a : null,
32
+ created_at: now,
33
+ updated_at: now
34
+ });
35
+ }
36
+ else {
37
+ await trx('monitor_lease')
38
+ .where({ task_name: claim.taskName })
39
+ .update({
40
+ owner_id: claim.ownerId,
41
+ expires_at: expiresAt,
42
+ renew_count: existing.owner_id === claim.ownerId ? existing.renew_count + 1 : 0,
43
+ note: (_b = claim.note) !== null && _b !== void 0 ? _b : existing.note,
44
+ updated_at: now
45
+ });
46
+ }
47
+ const row = await trx('monitor_lease').where({ task_name: claim.taskName }).first();
48
+ return { acquired: true, lease: mapRow(row) };
49
+ });
50
+ }
51
+ /**
52
+ * Extend the current owner's lease. Fails (returns `acquired: false`) when the
53
+ * row does not exist, is owned by someone else, or has already expired.
54
+ */
55
+ async function renewLease(knex, renew, now = new Date()) {
56
+ const expiresAt = new Date(now.getTime() + renew.ttlMs);
57
+ return await knex.transaction(async (trx) => {
58
+ var _a;
59
+ const existing = await trx('monitor_lease').where({ task_name: renew.taskName }).forUpdate().first();
60
+ if (existing == null)
61
+ return { acquired: false };
62
+ if (existing.owner_id !== renew.ownerId)
63
+ return { acquired: false };
64
+ if (new Date(existing.expires_at).getTime() <= now.getTime())
65
+ return { acquired: false };
66
+ await trx('monitor_lease')
67
+ .where({ task_name: renew.taskName })
68
+ .update({
69
+ expires_at: expiresAt,
70
+ renew_count: existing.renew_count + 1,
71
+ note: (_a = renew.note) !== null && _a !== void 0 ? _a : existing.note,
72
+ updated_at: now
73
+ });
74
+ const row = await trx('monitor_lease').where({ task_name: renew.taskName }).first();
75
+ return { acquired: true, lease: mapRow(row) };
76
+ });
77
+ }
78
+ /**
79
+ * Release the lease (no-op when not owned by the caller).
80
+ * The row is deleted so subsequent claimants do not see an inherited
81
+ * `renew_count`.
82
+ */
83
+ async function releaseLease(knex, release) {
84
+ const deleted = await knex('monitor_lease')
85
+ .where({ task_name: release.taskName, owner_id: release.ownerId })
86
+ .delete();
87
+ return deleted > 0;
88
+ }
89
+ function mapRow(row) {
90
+ var _a;
91
+ return {
92
+ created_at: new Date(row.created_at),
93
+ updated_at: new Date(row.updated_at),
94
+ taskName: row.task_name,
95
+ ownerId: row.owner_id,
96
+ expiresAt: new Date(row.expires_at),
97
+ renewCount: row.renew_count,
98
+ note: (_a = row.note) !== null && _a !== void 0 ? _a : undefined
99
+ };
100
+ }
101
+ //# sourceMappingURL=monitorLease.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitorLease.js","sourceRoot":"","sources":["../../../../src/storage/schema/monitorLease.ts"],"names":[],"mappings":";;AAiDA,sCAuCC;AAMD,gCAsBC;AAOD,oCAKC;AAxFD;;;;;;;;GAQG;AACI,KAAK,UAAU,aAAa,CACjC,IAAU,EACV,KAAwB,EACxB,MAAY,IAAI,IAAI,EAAE;IAEtB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;IACvD,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAC,GAAG,EAAC,EAAE;;QACxC,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAA;QACpG,MAAM,QAAQ,GACZ,QAAQ,IAAI,IAAI;YAChB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE;YACxD,QAAQ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E,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,YAAY,CAAE,IAAU,EAAE,OAA4B;IAC1E,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC;SACxC,KAAK,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;SACjE,MAAM,EAAE,CAAA;IACX,OAAO,OAAO,GAAG,CAAC,CAAA;AACpB,CAAC;AAED,SAAS,MAAM,CAAE,GAAQ;;IACvB,OAAO;QACL,UAAU,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;QACpC,UAAU,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;QACpC,QAAQ,EAAE,GAAG,CAAC,SAAS;QACvB,OAAO,EAAE,GAAG,CAAC,QAAQ;QACrB,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;QACnC,UAAU,EAAE,GAAG,CAAC,WAAW;QAC3B,IAAI,EAAE,MAAA,GAAG,CAAC,IAAI,mCAAI,SAAS;KAC5B,CAAA;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ import * as sdk from '../../sdk';
2
+ export interface FsmTransitionResult {
3
+ ok: boolean;
4
+ reason?: string;
5
+ }
6
+ /**
7
+ * Returns true when `from -> to` is a permitted processing transition.
8
+ * Identity transitions (`from === to`) are always allowed — they represent a
9
+ * status refresh without state change.
10
+ */
11
+ export declare function isValidProcessingTransition(from: sdk.ProcessingStatus, to: sdk.ProcessingStatus): boolean;
12
+ /**
13
+ * As `isValidProcessingTransition` but returns a structured result with a
14
+ * human-readable reason for any rejection. Useful for `tx_audit` payloads.
15
+ */
16
+ export declare function validateProcessingTransition(from: sdk.ProcessingStatus, to: sdk.ProcessingStatus): FsmTransitionResult;
17
+ /** Snapshot of the transition table for documentation + tests. */
18
+ export declare function processingTransitionMap(): Readonly<Record<sdk.ProcessingStatus, readonly sdk.ProcessingStatus[]>>;
19
+ /**
20
+ * True when the given state implies the transaction has been seen / accepted
21
+ * by at least one network provider — the precondition for output spendability
22
+ * in §4.
23
+ */
24
+ export declare function isProcessingSpendable(s: sdk.ProcessingStatus): boolean;
25
+ /** True when the state is terminal (no further automatic transitions). */
26
+ export declare function isProcessingTerminal(s: sdk.ProcessingStatus): boolean;
27
+ //# sourceMappingURL=processingFsm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processingFsm.d.ts","sourceRoot":"","sources":["../../../../src/storage/schema/processingFsm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAuDhC,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,GAAG,CAAC,gBAAgB,EAC1B,EAAE,EAAE,GAAG,CAAC,gBAAgB,GACvB,OAAO,CAGT;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,GAAG,CAAC,gBAAgB,EAC1B,EAAE,EAAE,GAAG,CAAC,gBAAgB,GACvB,mBAAmB,CAMrB;AAED,kEAAkE;AAClE,wBAAgB,uBAAuB,IAAK,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,SAAS,GAAG,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAElH;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAE,CAAC,EAAE,GAAG,CAAC,gBAAgB,GAAG,OAAO,CAEvE;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,GAAG,CAAC,gBAAgB,GAAG,OAAO,CAEtE"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.isValidProcessingTransition = isValidProcessingTransition;
37
+ exports.validateProcessingTransition = validateProcessingTransition;
38
+ exports.processingTransitionMap = processingTransitionMap;
39
+ exports.isProcessingSpendable = isProcessingSpendable;
40
+ exports.isProcessingTerminal = isProcessingTerminal;
41
+ const sdk = __importStar(require("../../sdk"));
42
+ /**
43
+ * processing-state machine.
44
+ *
45
+ * Maps each `ProcessingStatus` to the set of states it may legally transition
46
+ * to. Terminal states (`confirmed`, `invalid`, `doubleSpend`) have no outgoing
47
+ * transitions except via the `unfail` operator override.
48
+ *
49
+ * The transition table is intentionally permissive — the goal is to *reject
50
+ * impossible* moves (e.g. `queued -> confirmed` without ever broadcasting) rather
51
+ * than to enumerate the happy path. Stateful preconditions (proof present,
52
+ * provider acknowledged) are enforced at the call site.
53
+ */
54
+ const TRANSITIONS = {
55
+ // `queued -> doubleSpend`: a tx queued locally may be reported as a
56
+ // double-spend by the network before our first send attempt (e.g. another
57
+ // wallet broadcast the same outpoint first). See STORAGE_METHOD_WIRING §4
58
+ // legacy mapping `* -> doubleSpend (rejection)`.
59
+ queued: ['sending', 'sent', 'nosend', 'frozen', 'nonfinal', 'invalid', 'doubleSpend'],
60
+ sending: ['sent', 'seen', 'seen_multi', 'invalid', 'doubleSpend', 'frozen', 'queued'],
61
+ sent: ['seen', 'seen_multi', 'unconfirmed', 'confirmed', 'invalid', 'doubleSpend', 'frozen', 'sending'],
62
+ // `seen -> sending`: provider re-acknowledgment lost; legacy mapping
63
+ // `* -> sending (serviceError retry)` from STORAGE_METHOD_WIRING §4.
64
+ seen: ['seen_multi', 'unconfirmed', 'confirmed', 'invalid', 'doubleSpend', 'reorging', 'frozen', 'sending'],
65
+ // `seen_multi -> sending`: same retry semantics as `seen -> sending`.
66
+ seen_multi: ['unconfirmed', 'confirmed', 'invalid', 'doubleSpend', 'reorging', 'frozen', 'sending'],
67
+ // `unconfirmed -> doubleSpend`: a provider's proof candidate may be retracted
68
+ // when a competing tx is mined. `unconfirmed -> sending`: candidate failed
69
+ // chaintracks validation, restart broadcast attempts. Both per §4.
70
+ unconfirmed: ['confirmed', 'invalid', 'reorging', 'frozen', 'seen', 'seen_multi', 'doubleSpend', 'sending'],
71
+ confirmed: ['reorging'],
72
+ // Reorg rule (bsv_wallet_transaction_requirements v1.0 §5):
73
+ // "A reorg SHALL never cause a transaction to be marked Invalid or
74
+ // DoubleSpend." The reorging state is therefore restricted to recovery
75
+ // edges only — back to a confirmation-class state or to frozen for
76
+ // operator review. Callers that later determine the tx is genuinely
77
+ // invalid or a doubleSpend must first transition through `unconfirmed`
78
+ // (where the standard FSM edges to `invalid`/`doubleSpend` apply) so the
79
+ // rejection is recorded against a non-reorg cause in `tx_audit`.
80
+ reorging: ['confirmed', 'seen', 'seen_multi', 'unconfirmed', 'frozen'],
81
+ invalid: ['unfail'],
82
+ doubleSpend: ['unfail'],
83
+ unfail: ['queued', 'sending', 'sent', 'seen', 'seen_multi', 'unconfirmed', 'confirmed', 'invalid', 'doubleSpend'],
84
+ frozen: ['queued', 'sending', 'sent', 'seen', 'seen_multi', 'unconfirmed', 'invalid', 'doubleSpend'],
85
+ // `nosend -> sending`: operator (or processAction promotion) moves a
86
+ // never-broadcast tx into the active broadcast pipeline. `nosend ->
87
+ // doubleSpend`: an externally-broadcast nosend tx may be reported as a
88
+ // double-spend. Both per §4 legacy mapping.
89
+ nosend: ['queued', 'sending', 'sent', 'seen', 'invalid', 'doubleSpend', 'frozen'],
90
+ // `nonfinal -> doubleSpend`: a live-nLockTime tx may be replaced by a
91
+ // confirmed competing tx and reported as a double-spend.
92
+ nonfinal: ['queued', 'sending', 'sent', 'invalid', 'doubleSpend', 'frozen']
93
+ };
94
+ /**
95
+ * Returns true when `from -> to` is a permitted processing transition.
96
+ * Identity transitions (`from === to`) are always allowed — they represent a
97
+ * status refresh without state change.
98
+ */
99
+ function isValidProcessingTransition(from, to) {
100
+ if (from === to)
101
+ return true;
102
+ return TRANSITIONS[from].includes(to);
103
+ }
104
+ /**
105
+ * As `isValidProcessingTransition` but returns a structured result with a
106
+ * human-readable reason for any rejection. Useful for `tx_audit` payloads.
107
+ */
108
+ function validateProcessingTransition(from, to) {
109
+ if (isValidProcessingTransition(from, to))
110
+ return { ok: true };
111
+ return {
112
+ ok: false,
113
+ reason: `illegal transition ${from} -> ${to}; legal next: ${TRANSITIONS[from].join(', ')}`
114
+ };
115
+ }
116
+ /** Snapshot of the transition table for documentation + tests. */
117
+ function processingTransitionMap() {
118
+ return TRANSITIONS;
119
+ }
120
+ /**
121
+ * True when the given state implies the transaction has been seen / accepted
122
+ * by at least one network provider — the precondition for output spendability
123
+ * in §4.
124
+ */
125
+ function isProcessingSpendable(s) {
126
+ return sdk.ProcessingSpendableStatus.includes(s);
127
+ }
128
+ /** True when the state is terminal (no further automatic transitions). */
129
+ function isProcessingTerminal(s) {
130
+ return sdk.ProcessingTerminalStatus.includes(s);
131
+ }
132
+ //# sourceMappingURL=processingFsm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processingFsm.js","sourceRoot":"","sources":["../../../../src/storage/schema/processingFsm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,kEAMC;AAMD,oEASC;AAGD,0DAEC;AAOD,sDAEC;AAGD,oDAEC;AAzGD,+CAAgC;AAEhC;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,GAAyD;IACxE,oEAAoE;IACpE,0EAA0E;IAC1E,0EAA0E;IAC1E,iDAAiD;IACjD,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,CAAC;IACrF,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC;IACrF,IAAI,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAC;IACvG,qEAAqE;IACrE,qEAAqE;IACrE,IAAI,EAAE,CAAC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,CAAC;IAC3G,sEAAsE;IACtE,UAAU,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,CAAC;IACnG,8EAA8E;IAC9E,2EAA2E;IAC3E,mEAAmE;IACnE,WAAW,EAAE,CAAC,WAAW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B,EAAwB;IAExB,IAAI,2BAA2B,CAAC,IAAI,EAAE,EAAE,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;IAC9D,OAAO;QACL,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,sBAAsB,IAAI,OAAO,EAAE,iBAAiB,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;KAC3F,CAAA;AACH,CAAC;AAED,kEAAkE;AAClE,SAAgB,uBAAuB;IACrC,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAE,CAAuB;IAC5D,OAAO,GAAG,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;AAClD,CAAC;AAED,0EAA0E;AAC1E,SAAgB,oBAAoB,CAAE,CAAuB;IAC3D,OAAO,GAAG,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;AACjD,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Knex } from 'knex';
2
+ /**
3
+ * §3 Step 6 of PROD_REQ_V7_TS.md — destructive cutover.
4
+ *
5
+ * Renames the legacy `transactions`, `proven_tx_reqs`, and `proven_txs` tables
6
+ * to `*_legacy`, swaps the new-schema `transactions_new` table in as the new
7
+ * canonical `transactions`, and remaps every FK value in `outputs`,
8
+ * `commissions`, and `tx_labels_map` so that downstream storage methods
9
+ * continue to read consistent rows.
10
+ *
11
+ * Not registered as a Knex migration because applying it changes the meaning
12
+ * of table names that legacy storage methods still address. Run it only when
13
+ * the calling application is ready to use the new-schema storage path.
14
+ *
15
+ * Safe to call:
16
+ * - on a populated DB that has not yet been cutover (performs full migration)
17
+ * - on a fresh DB (renames empty tables to match the post-cutover layout)
18
+ * - twice in a row (second call is a no-op via the `transactions_legacy`
19
+ * presence guard)
20
+ *
21
+ * The function is intentionally not wrapped in a Knex transaction: on SQLite
22
+ * we need to toggle the per-connection `legacy_alter_table` pragma between
23
+ * statements, which is incompatible with the deferred-commit semantics
24
+ * Knex uses inside `knex.transaction`.
25
+ */
26
+ export declare function runSchemaCutover(knex: Knex): Promise<void>;
27
+ /**
28
+ * Inverse of `runSchemaCutover` for test rollback. Renames `*_legacy` tables back
29
+ * to their canonical names and swaps `transactions` back to `transactions_new`.
30
+ * Does not reverse the FK value remap — call this only when the cutover was
31
+ * applied to seed data that the test no longer needs.
32
+ */
33
+ export declare function rollbackSchemaCutover(knex: Knex): Promise<void>;
34
+ //# sourceMappingURL=schemaCutover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaCutover.d.ts","sourceRoot":"","sources":["../../../../src/storage/schema/schemaCutover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAK3B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,gBAAgB,CAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAyFjE;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBtE"}
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSchemaCutover = runSchemaCutover;
4
+ exports.rollbackSchemaCutover = rollbackSchemaCutover;
5
+ const backfill_knex_1 = require("./backfill.knex");
6
+ const backfill_runner_1 = require("./backfill.runner");
7
+ /**
8
+ * §3 Step 6 of PROD_REQ_V7_TS.md — destructive cutover.
9
+ *
10
+ * Renames the legacy `transactions`, `proven_tx_reqs`, and `proven_txs` tables
11
+ * to `*_legacy`, swaps the new-schema `transactions_new` table in as the new
12
+ * canonical `transactions`, and remaps every FK value in `outputs`,
13
+ * `commissions`, and `tx_labels_map` so that downstream storage methods
14
+ * continue to read consistent rows.
15
+ *
16
+ * Not registered as a Knex migration because applying it changes the meaning
17
+ * of table names that legacy storage methods still address. Run it only when
18
+ * the calling application is ready to use the new-schema storage path.
19
+ *
20
+ * Safe to call:
21
+ * - on a populated DB that has not yet been cutover (performs full migration)
22
+ * - on a fresh DB (renames empty tables to match the post-cutover layout)
23
+ * - twice in a row (second call is a no-op via the `transactions_legacy`
24
+ * presence guard)
25
+ *
26
+ * The function is intentionally not wrapped in a Knex transaction: on SQLite
27
+ * we need to toggle the per-connection `legacy_alter_table` pragma between
28
+ * statements, which is incompatible with the deferred-commit semantics
29
+ * Knex uses inside `knex.transaction`.
30
+ */
31
+ async function runSchemaCutover(knex) {
32
+ var _a, _b;
33
+ const dbtype = await determineDBType(knex);
34
+ const isSqlite = dbtype === 'SQLite';
35
+ // Idempotency guard.
36
+ if (await hasTable(knex, 'transactions_legacy'))
37
+ return;
38
+ // Ensure backfill has populated transactions_new / actions before remapping.
39
+ const txCount = await knex('transactions').count({ c: '*' }).first();
40
+ const newTxCount = await knex('transactions_new').count({ c: '*' }).first();
41
+ const hasLegacyData = ((_a = txCount === null || txCount === void 0 ? void 0 : txCount.c) !== null && _a !== void 0 ? _a : 0) > 0;
42
+ const newTxPopulated = ((_b = newTxCount === null || newTxCount === void 0 ? void 0 : newTxCount.c) !== null && _b !== void 0 ? _b : 0) > 0;
43
+ if (hasLegacyData && !newTxPopulated) {
44
+ const driver = new backfill_knex_1.KnexBackfillDriver(knex);
45
+ await (0, backfill_runner_1.runBackfill)(driver);
46
+ }
47
+ // Build mappings legacy.transactionId -> { newTxId, actionId }.
48
+ const txMapRows = hasLegacyData
49
+ ? await knex('transactions as t')
50
+ .join('transactions_new as v', 'v.txid', 't.txid')
51
+ .select(knex.ref('t.transactionId').as('legacyId'), knex.ref('v.transactionId').as('newTxId'))
52
+ : [];
53
+ const actionMapRows = hasLegacyData
54
+ ? await knex('transactions as t')
55
+ .join('transactions_new as v', 'v.txid', 't.txid')
56
+ .join('actions as a', function joinAction() {
57
+ this.on('a.userId', '=', 't.userId').andOn('a.transactionId', '=', 'v.transactionId');
58
+ })
59
+ .select(knex.ref('t.transactionId').as('legacyId'), knex.ref('a.actionId').as('actionId'))
60
+ : [];
61
+ const legacyToNew = new Map(txMapRows.map(r => [r.legacyId, r.newTxId]));
62
+ const legacyToAction = new Map(actionMapRows.map(r => [r.legacyId, r.actionId]));
63
+ await disableFks(knex, isSqlite);
64
+ try {
65
+ // Remap downstream FK values with a temporary offset to dodge collisions
66
+ // with the existing legacy keyspace during partial updates.
67
+ const OFFSET = 1000000000;
68
+ for (const [legacy, newId] of legacyToNew) {
69
+ const shifted = newId + OFFSET;
70
+ await knex('outputs').where({ transactionId: legacy }).update({ transactionId: shifted });
71
+ await knex('outputs').where({ spentBy: legacy }).update({ spentBy: shifted });
72
+ await knex('commissions').where({ transactionId: legacy }).update({ transactionId: shifted });
73
+ }
74
+ await knex('outputs').where('transactionId', '>=', OFFSET).update({
75
+ transactionId: knex.raw('?? - ?', ['transactionId', OFFSET])
76
+ });
77
+ await knex('outputs').where('spentBy', '>=', OFFSET).update({
78
+ spentBy: knex.raw('?? - ?', ['spentBy', OFFSET])
79
+ });
80
+ await knex('commissions').where('transactionId', '>=', OFFSET).update({
81
+ transactionId: knex.raw('?? - ?', ['transactionId', OFFSET])
82
+ });
83
+ for (const [legacy, actionId] of legacyToAction) {
84
+ const shifted = actionId + OFFSET;
85
+ await knex('tx_labels_map').where({ transactionId: legacy }).update({ transactionId: shifted });
86
+ }
87
+ await knex('tx_labels_map').where('transactionId', '>=', OFFSET).update({
88
+ transactionId: knex.raw('?? - ?', ['transactionId', OFFSET])
89
+ });
90
+ // legacy_alter_table = ON suppresses SQLite's automatic FK rewrite on
91
+ // RENAME. We want it ON for the `transactions` rename only (so that the
92
+ // outputs / commissions / tx_labels_map FKs keep pointing at the bare
93
+ // string "transactions" and resolve to the new table after the swap).
94
+ // For `proven_tx_reqs` and `proven_txs`, we want OFF so SQLite rewrites
95
+ // the FK references inside proven_tx_reqs_legacy / transactions_legacy
96
+ // (which target proven_txs) to follow the rename to proven_txs_legacy.
97
+ // Without that rewrite, inserts into proven_tx_reqs_legacy fail because
98
+ // the resolver looks up the bare "proven_txs" string and finds nothing.
99
+ if (isSqlite)
100
+ await knex.raw('PRAGMA legacy_alter_table = ON');
101
+ await knex.schema.renameTable('transactions', 'transactions_legacy');
102
+ if (isSqlite)
103
+ await knex.raw('PRAGMA legacy_alter_table = OFF');
104
+ await knex.schema.renameTable('proven_tx_reqs', 'proven_tx_reqs_legacy');
105
+ await knex.schema.renameTable('proven_txs', 'proven_txs_legacy');
106
+ // OFF (the default modern mode) ensures the rename of `transactions_new`
107
+ // → `transactions` rewrites any FK reference that pointed at the original
108
+ // new-schema name. tx_audit / actions originally targeted `transactions_new`
109
+ // and follow the rename to `transactions` automatically.
110
+ await knex.schema.renameTable('transactions_new', 'transactions');
111
+ await rebuildTxLabelsMap(knex, dbtype);
112
+ }
113
+ finally {
114
+ await enableFks(knex, isSqlite);
115
+ }
116
+ }
117
+ /**
118
+ * Inverse of `runSchemaCutover` for test rollback. Renames `*_legacy` tables back
119
+ * to their canonical names and swaps `transactions` back to `transactions_new`.
120
+ * Does not reverse the FK value remap — call this only when the cutover was
121
+ * applied to seed data that the test no longer needs.
122
+ */
123
+ async function rollbackSchemaCutover(knex) {
124
+ const dbtype = await determineDBType(knex);
125
+ const isSqlite = dbtype === 'SQLite';
126
+ await disableFks(knex, isSqlite);
127
+ try {
128
+ if (isSqlite)
129
+ await knex.raw('PRAGMA legacy_alter_table = ON');
130
+ if (await hasTable(knex, 'transactions')) {
131
+ await knex.schema.renameTable('transactions', 'transactions_new');
132
+ }
133
+ if (await hasTable(knex, 'transactions_legacy')) {
134
+ await knex.schema.renameTable('transactions_legacy', 'transactions');
135
+ }
136
+ if (await hasTable(knex, 'proven_tx_reqs_legacy')) {
137
+ await knex.schema.renameTable('proven_tx_reqs_legacy', 'proven_tx_reqs');
138
+ }
139
+ if (await hasTable(knex, 'proven_txs_legacy')) {
140
+ await knex.schema.renameTable('proven_txs_legacy', 'proven_txs');
141
+ }
142
+ if (isSqlite)
143
+ await knex.raw('PRAGMA legacy_alter_table = OFF');
144
+ }
145
+ finally {
146
+ await enableFks(knex, isSqlite);
147
+ }
148
+ }
149
+ async function determineDBType(knex) {
150
+ var _a, _b, _c;
151
+ // Avoid pulling KnexMigrations' determineDBType to keep this module
152
+ // free of cyclic imports.
153
+ try {
154
+ const r = await knex.raw("SELECT 'MySQL' AS database_type FROM dual");
155
+ const dbtype = (_c = (Array.isArray(r) ? r[0] : (_b = (_a = r.rows) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : r[0])) === null || _c === void 0 ? void 0 : _c.database_type;
156
+ if (dbtype === 'MySQL')
157
+ return 'MySQL';
158
+ }
159
+ catch (e) {
160
+ // fallthrough — SQLite has no `dual` table
161
+ }
162
+ try {
163
+ await knex.raw('SELECT 1');
164
+ return 'SQLite';
165
+ }
166
+ catch (e) {
167
+ throw new Error('Unsupported database engine for schema cutover');
168
+ }
169
+ }
170
+ async function hasTable(knex, name) {
171
+ return await knex.schema.hasTable(name);
172
+ }
173
+ async function disableFks(knex, isSqlite) {
174
+ if (isSqlite) {
175
+ await knex.raw('PRAGMA foreign_keys = OFF');
176
+ }
177
+ else {
178
+ await knex.raw('SET FOREIGN_KEY_CHECKS=0');
179
+ }
180
+ }
181
+ async function enableFks(knex, isSqlite) {
182
+ if (isSqlite) {
183
+ await knex.raw('PRAGMA foreign_keys = ON');
184
+ }
185
+ else {
186
+ await knex.raw('SET FOREIGN_KEY_CHECKS=1');
187
+ }
188
+ }
189
+ async function rebuildTxLabelsMap(knex, dbtype) {
190
+ var _a, _b;
191
+ if (dbtype === 'SQLite') {
192
+ await knex.schema.createTable('tx_labels_map_new', table => {
193
+ table.timestamp('created_at', { precision: 3 }).defaultTo(knex.fn.now()).notNullable();
194
+ table.timestamp('updated_at', { precision: 3 }).defaultTo(knex.fn.now()).notNullable();
195
+ table.integer('txLabelId').unsigned().references('txLabelId').inTable('tx_labels').notNullable();
196
+ table.integer('transactionId').unsigned().references('actionId').inTable('actions').notNullable();
197
+ table.boolean('isDeleted').notNullable().defaultTo(false);
198
+ table.unique(['txLabelId', 'transactionId']);
199
+ });
200
+ await knex.raw('INSERT INTO tx_labels_map_new (created_at, updated_at, txLabelId, transactionId, isDeleted) ' +
201
+ 'SELECT created_at, updated_at, txLabelId, transactionId, isDeleted FROM tx_labels_map');
202
+ await knex.schema.dropTable('tx_labels_map');
203
+ await knex.schema.renameTable('tx_labels_map_new', 'tx_labels_map');
204
+ await knex.schema.alterTable('tx_labels_map', table => {
205
+ table.index('transactionId');
206
+ table.index(['transactionId', 'isDeleted'], 'idx_tx_labels_map_tx_deleted');
207
+ });
208
+ }
209
+ else {
210
+ const dbRow = (await knex.raw('SELECT DATABASE() AS d'))[0];
211
+ const dbName = Array.isArray(dbRow) ? (_a = dbRow[0]) === null || _a === void 0 ? void 0 : _a.d : dbRow === null || dbRow === void 0 ? void 0 : dbRow.d;
212
+ const fkRows = await knex('information_schema.KEY_COLUMN_USAGE')
213
+ .select('CONSTRAINT_NAME')
214
+ .where({
215
+ TABLE_SCHEMA: dbName,
216
+ TABLE_NAME: 'tx_labels_map',
217
+ COLUMN_NAME: 'transactionId'
218
+ })
219
+ .whereNotNull('REFERENCED_TABLE_NAME');
220
+ for (const row of fkRows !== null && fkRows !== void 0 ? fkRows : []) {
221
+ const constraintName = (_b = row.CONSTRAINT_NAME) !== null && _b !== void 0 ? _b : row.constraint_name;
222
+ if (constraintName != null) {
223
+ await knex.raw('ALTER TABLE tx_labels_map DROP FOREIGN KEY `' + constraintName + '`');
224
+ }
225
+ }
226
+ await knex.raw('ALTER TABLE tx_labels_map ADD CONSTRAINT fk_tx_labels_map_action ' +
227
+ 'FOREIGN KEY (transactionId) REFERENCES actions(actionId)');
228
+ }
229
+ }
230
+ //# sourceMappingURL=schemaCutover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaCutover.js","sourceRoot":"","sources":["../../../../src/storage/schema/schemaCutover.ts"],"names":[],"mappings":";;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 @@
1
+ import { IDBPDatabase } from 'idb';
2
+ import { StorageIdbSchema } from './StorageIdbSchema';
3
+ /**
4
+ * IDB-side schema cutover.
5
+ *
6
+ * IndexedDB has no `RENAME STORE` primitive, and store creation/deletion is
7
+ * only permitted during a version-upgrade transaction. The cutover therefore:
8
+ *
9
+ * 1. Re-opens the database at a higher version, supplying an `upgrade`
10
+ * callback that does the rename via copy-and-delete on the upgrade trx.
11
+ * 2. For each table that needs renaming:
12
+ * a. Read every row from the source store.
13
+ * b. Create the destination store with the same indexes.
14
+ * c. Write rows into the destination store.
15
+ * d. Delete the source store.
16
+ * 3. Returns the upgraded database handle (caller is responsible for
17
+ * closing it).
18
+ *
19
+ * Safe to call twice — the second call sees the post-cutover layout, skips
20
+ * the rename block, and returns without error.
21
+ *
22
+ * `targetVersion` defaults to 2; bump it if the caller already operates on a
23
+ * higher schema version.
24
+ */
25
+ export declare function runIdbSchemaCutover(dbName: string, targetVersion?: number): Promise<IDBPDatabase<StorageIdbSchema>>;
26
+ //# sourceMappingURL=schemaCutoverIdb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaCutoverIdb.d.ts","sourceRoot":"","sources":["../../../../src/storage/schema/schemaCutoverIdb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA2B,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,aAAa,SAAI,GAChB,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAyDzC"}