@optimystic/db-core 0.0.1

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 (345) hide show
  1. package/README.md +328 -0
  2. package/dist/index.min.js +18 -0
  3. package/dist/index.min.js.map +7 -0
  4. package/dist/src/blocks/block-store.d.ts +12 -0
  5. package/dist/src/blocks/block-store.d.ts.map +1 -0
  6. package/dist/src/blocks/block-store.js +2 -0
  7. package/dist/src/blocks/block-store.js.map +1 -0
  8. package/dist/src/blocks/block-types.d.ts +3 -0
  9. package/dist/src/blocks/block-types.d.ts.map +1 -0
  10. package/dist/src/blocks/block-types.js +9 -0
  11. package/dist/src/blocks/block-types.js.map +1 -0
  12. package/dist/src/blocks/helpers.d.ts +4 -0
  13. package/dist/src/blocks/helpers.d.ts.map +1 -0
  14. package/dist/src/blocks/helpers.js +12 -0
  15. package/dist/src/blocks/helpers.js.map +1 -0
  16. package/dist/src/blocks/index.d.ts +5 -0
  17. package/dist/src/blocks/index.d.ts.map +1 -0
  18. package/dist/src/blocks/index.js +5 -0
  19. package/dist/src/blocks/index.js.map +1 -0
  20. package/dist/src/blocks/structs.d.ts +14 -0
  21. package/dist/src/blocks/structs.d.ts.map +1 -0
  22. package/dist/src/blocks/structs.js +2 -0
  23. package/dist/src/blocks/structs.js.map +1 -0
  24. package/dist/src/btree/btree.d.ts +135 -0
  25. package/dist/src/btree/btree.d.ts.map +1 -0
  26. package/dist/src/btree/btree.js +727 -0
  27. package/dist/src/btree/btree.js.map +1 -0
  28. package/dist/src/btree/independent-trunk.d.ts +17 -0
  29. package/dist/src/btree/independent-trunk.d.ts.map +1 -0
  30. package/dist/src/btree/independent-trunk.js +41 -0
  31. package/dist/src/btree/independent-trunk.js.map +1 -0
  32. package/dist/src/btree/index.d.ts +6 -0
  33. package/dist/src/btree/index.d.ts.map +1 -0
  34. package/dist/src/btree/index.js +6 -0
  35. package/dist/src/btree/index.js.map +1 -0
  36. package/dist/src/btree/key-range.d.ts +13 -0
  37. package/dist/src/btree/key-range.d.ts.map +1 -0
  38. package/dist/src/btree/key-range.js +20 -0
  39. package/dist/src/btree/key-range.js.map +1 -0
  40. package/dist/src/btree/keyset.d.ts +4 -0
  41. package/dist/src/btree/keyset.d.ts.map +1 -0
  42. package/dist/src/btree/keyset.js +4 -0
  43. package/dist/src/btree/keyset.js.map +1 -0
  44. package/dist/src/btree/nodes.d.ts +16 -0
  45. package/dist/src/btree/nodes.d.ts.map +1 -0
  46. package/dist/src/btree/nodes.js +9 -0
  47. package/dist/src/btree/nodes.js.map +1 -0
  48. package/dist/src/btree/path.d.ts +22 -0
  49. package/dist/src/btree/path.d.ts.map +1 -0
  50. package/dist/src/btree/path.js +39 -0
  51. package/dist/src/btree/path.js.map +1 -0
  52. package/dist/src/btree/tree-block.d.ts +7 -0
  53. package/dist/src/btree/tree-block.d.ts.map +1 -0
  54. package/dist/src/btree/tree-block.js +5 -0
  55. package/dist/src/btree/tree-block.js.map +1 -0
  56. package/dist/src/btree/trunk.d.ts +13 -0
  57. package/dist/src/btree/trunk.d.ts.map +1 -0
  58. package/dist/src/btree/trunk.js +2 -0
  59. package/dist/src/btree/trunk.js.map +1 -0
  60. package/dist/src/chain/chain-nodes.d.ts +18 -0
  61. package/dist/src/chain/chain-nodes.d.ts.map +1 -0
  62. package/dist/src/chain/chain-nodes.js +10 -0
  63. package/dist/src/chain/chain-nodes.js.map +1 -0
  64. package/dist/src/chain/chain.d.ts +75 -0
  65. package/dist/src/chain/chain.d.ts.map +1 -0
  66. package/dist/src/chain/chain.js +268 -0
  67. package/dist/src/chain/chain.js.map +1 -0
  68. package/dist/src/chain/index.d.ts +2 -0
  69. package/dist/src/chain/index.d.ts.map +1 -0
  70. package/dist/src/chain/index.js +2 -0
  71. package/dist/src/chain/index.js.map +1 -0
  72. package/dist/src/cluster/i-cluster.d.ts +5 -0
  73. package/dist/src/cluster/i-cluster.d.ts.map +1 -0
  74. package/dist/src/cluster/i-cluster.js +2 -0
  75. package/dist/src/cluster/i-cluster.js.map +1 -0
  76. package/dist/src/cluster/index.d.ts +3 -0
  77. package/dist/src/cluster/index.d.ts.map +1 -0
  78. package/dist/src/cluster/index.js +3 -0
  79. package/dist/src/cluster/index.js.map +1 -0
  80. package/dist/src/cluster/structs.d.ts +47 -0
  81. package/dist/src/cluster/structs.d.ts.map +1 -0
  82. package/dist/src/cluster/structs.js +2 -0
  83. package/dist/src/cluster/structs.js.map +1 -0
  84. package/dist/src/collection/action.d.ts +26 -0
  85. package/dist/src/collection/action.d.ts.map +1 -0
  86. package/dist/src/collection/action.js +2 -0
  87. package/dist/src/collection/action.js.map +1 -0
  88. package/dist/src/collection/collection.d.ts +48 -0
  89. package/dist/src/collection/collection.d.ts.map +1 -0
  90. package/dist/src/collection/collection.js +175 -0
  91. package/dist/src/collection/collection.js.map +1 -0
  92. package/dist/src/collection/index.d.ts +4 -0
  93. package/dist/src/collection/index.d.ts.map +1 -0
  94. package/dist/src/collection/index.js +4 -0
  95. package/dist/src/collection/index.js.map +1 -0
  96. package/dist/src/collection/struct.d.ts +16 -0
  97. package/dist/src/collection/struct.d.ts.map +1 -0
  98. package/dist/src/collection/struct.js +2 -0
  99. package/dist/src/collection/struct.js.map +1 -0
  100. package/dist/src/collections/diary/diary.d.ts +9 -0
  101. package/dist/src/collections/diary/diary.d.ts.map +1 -0
  102. package/dist/src/collections/diary/diary.js +37 -0
  103. package/dist/src/collections/diary/diary.js.map +1 -0
  104. package/dist/src/collections/diary/index.d.ts +3 -0
  105. package/dist/src/collections/diary/index.d.ts.map +1 -0
  106. package/dist/src/collections/diary/index.js +3 -0
  107. package/dist/src/collections/diary/index.js.map +1 -0
  108. package/dist/src/collections/diary/struct.d.ts +2 -0
  109. package/dist/src/collections/diary/struct.d.ts.map +1 -0
  110. package/dist/src/collections/diary/struct.js +3 -0
  111. package/dist/src/collections/diary/struct.js.map +1 -0
  112. package/dist/src/collections/index.d.ts +3 -0
  113. package/dist/src/collections/index.d.ts.map +1 -0
  114. package/dist/src/collections/index.js +3 -0
  115. package/dist/src/collections/index.js.map +1 -0
  116. package/dist/src/collections/tree/collection-trunk.d.ts +11 -0
  117. package/dist/src/collections/tree/collection-trunk.d.ts.map +1 -0
  118. package/dist/src/collections/tree/collection-trunk.js +22 -0
  119. package/dist/src/collections/tree/collection-trunk.js.map +1 -0
  120. package/dist/src/collections/tree/index.d.ts +3 -0
  121. package/dist/src/collections/tree/index.d.ts.map +1 -0
  122. package/dist/src/collections/tree/index.js +3 -0
  123. package/dist/src/collections/tree/index.js.map +1 -0
  124. package/dist/src/collections/tree/struct.d.ts +12 -0
  125. package/dist/src/collections/tree/struct.d.ts.map +1 -0
  126. package/dist/src/collections/tree/struct.js +4 -0
  127. package/dist/src/collections/tree/struct.js.map +1 -0
  128. package/dist/src/collections/tree/tree.d.ts +34 -0
  129. package/dist/src/collections/tree/tree.d.ts.map +1 -0
  130. package/dist/src/collections/tree/tree.js +100 -0
  131. package/dist/src/collections/tree/tree.js.map +1 -0
  132. package/dist/src/index.d.ts +18 -0
  133. package/dist/src/index.d.ts.map +1 -0
  134. package/dist/src/index.js +18 -0
  135. package/dist/src/index.js.map +1 -0
  136. package/dist/src/log/index.d.ts +3 -0
  137. package/dist/src/log/index.d.ts.map +1 -0
  138. package/dist/src/log/index.js +3 -0
  139. package/dist/src/log/index.js.map +1 -0
  140. package/dist/src/log/log.d.ts +57 -0
  141. package/dist/src/log/log.d.ts.map +1 -0
  142. package/dist/src/log/log.js +131 -0
  143. package/dist/src/log/log.js.map +1 -0
  144. package/dist/src/log/struct.d.ts +36 -0
  145. package/dist/src/log/struct.d.ts.map +1 -0
  146. package/dist/src/log/struct.js +3 -0
  147. package/dist/src/log/struct.js.map +1 -0
  148. package/dist/src/network/i-key-network.d.ts +21 -0
  149. package/dist/src/network/i-key-network.d.ts.map +1 -0
  150. package/dist/src/network/i-key-network.js +2 -0
  151. package/dist/src/network/i-key-network.js.map +1 -0
  152. package/dist/src/network/i-peer-network.d.ts +8 -0
  153. package/dist/src/network/i-peer-network.d.ts.map +1 -0
  154. package/dist/src/network/i-peer-network.js +2 -0
  155. package/dist/src/network/i-peer-network.js.map +1 -0
  156. package/dist/src/network/i-repo.d.ts +17 -0
  157. package/dist/src/network/i-repo.d.ts.map +1 -0
  158. package/dist/src/network/i-repo.js +2 -0
  159. package/dist/src/network/i-repo.js.map +1 -0
  160. package/dist/src/network/index.d.ts +6 -0
  161. package/dist/src/network/index.d.ts.map +1 -0
  162. package/dist/src/network/index.js +6 -0
  163. package/dist/src/network/index.js.map +1 -0
  164. package/dist/src/network/repo-protocol.d.ts +19 -0
  165. package/dist/src/network/repo-protocol.d.ts.map +1 -0
  166. package/dist/src/network/repo-protocol.js +2 -0
  167. package/dist/src/network/repo-protocol.js.map +1 -0
  168. package/dist/src/network/struct.d.ts +115 -0
  169. package/dist/src/network/struct.d.ts.map +1 -0
  170. package/dist/src/network/struct.js +2 -0
  171. package/dist/src/network/struct.js.map +1 -0
  172. package/dist/src/transaction/actions-engine.d.ts +37 -0
  173. package/dist/src/transaction/actions-engine.d.ts.map +1 -0
  174. package/dist/src/transaction/actions-engine.js +67 -0
  175. package/dist/src/transaction/actions-engine.js.map +1 -0
  176. package/dist/src/transaction/context.d.ts +60 -0
  177. package/dist/src/transaction/context.d.ts.map +1 -0
  178. package/dist/src/transaction/context.js +91 -0
  179. package/dist/src/transaction/context.js.map +1 -0
  180. package/dist/src/transaction/coordinator.d.ts +118 -0
  181. package/dist/src/transaction/coordinator.d.ts.map +1 -0
  182. package/dist/src/transaction/coordinator.js +417 -0
  183. package/dist/src/transaction/coordinator.js.map +1 -0
  184. package/dist/src/transaction/index.d.ts +10 -0
  185. package/dist/src/transaction/index.d.ts.map +1 -0
  186. package/dist/src/transaction/index.js +7 -0
  187. package/dist/src/transaction/index.js.map +1 -0
  188. package/dist/src/transaction/session.d.ts +80 -0
  189. package/dist/src/transaction/session.d.ts.map +1 -0
  190. package/dist/src/transaction/session.js +161 -0
  191. package/dist/src/transaction/session.js.map +1 -0
  192. package/dist/src/transaction/transaction.d.ts +156 -0
  193. package/dist/src/transaction/transaction.d.ts.map +1 -0
  194. package/dist/src/transaction/transaction.js +31 -0
  195. package/dist/src/transaction/transaction.js.map +1 -0
  196. package/dist/src/transaction/validator.d.ts +46 -0
  197. package/dist/src/transaction/validator.d.ts.map +1 -0
  198. package/dist/src/transaction/validator.js +97 -0
  199. package/dist/src/transaction/validator.js.map +1 -0
  200. package/dist/src/transactor/index.d.ts +4 -0
  201. package/dist/src/transactor/index.d.ts.map +1 -0
  202. package/dist/src/transactor/index.js +4 -0
  203. package/dist/src/transactor/index.js.map +1 -0
  204. package/dist/src/transactor/network-transactor.d.ts +36 -0
  205. package/dist/src/transactor/network-transactor.d.ts.map +1 -0
  206. package/dist/src/transactor/network-transactor.js +297 -0
  207. package/dist/src/transactor/network-transactor.js.map +1 -0
  208. package/dist/src/transactor/transactor-source.d.ts +24 -0
  209. package/dist/src/transactor/transactor-source.d.ts.map +1 -0
  210. package/dist/src/transactor/transactor-source.js +62 -0
  211. package/dist/src/transactor/transactor-source.js.map +1 -0
  212. package/dist/src/transactor/transactor.d.ts +38 -0
  213. package/dist/src/transactor/transactor.d.ts.map +1 -0
  214. package/dist/src/transactor/transactor.js +2 -0
  215. package/dist/src/transactor/transactor.js.map +1 -0
  216. package/dist/src/transform/atomic.d.ts +8 -0
  217. package/dist/src/transform/atomic.d.ts.map +1 -0
  218. package/dist/src/transform/atomic.js +14 -0
  219. package/dist/src/transform/atomic.js.map +1 -0
  220. package/dist/src/transform/cache-source.d.ts +13 -0
  221. package/dist/src/transform/cache-source.d.ts.map +1 -0
  222. package/dist/src/transform/cache-source.js +52 -0
  223. package/dist/src/transform/cache-source.js.map +1 -0
  224. package/dist/src/transform/helpers.d.ts +25 -0
  225. package/dist/src/transform/helpers.d.ts.map +1 -0
  226. package/dist/src/transform/helpers.js +105 -0
  227. package/dist/src/transform/helpers.js.map +1 -0
  228. package/dist/src/transform/index.d.ts +6 -0
  229. package/dist/src/transform/index.d.ts.map +1 -0
  230. package/dist/src/transform/index.js +6 -0
  231. package/dist/src/transform/index.js.map +1 -0
  232. package/dist/src/transform/struct.d.ts +19 -0
  233. package/dist/src/transform/struct.d.ts.map +1 -0
  234. package/dist/src/transform/struct.js +2 -0
  235. package/dist/src/transform/struct.js.map +1 -0
  236. package/dist/src/transform/tracker.d.ts +22 -0
  237. package/dist/src/transform/tracker.d.ts.map +1 -0
  238. package/dist/src/transform/tracker.js +64 -0
  239. package/dist/src/transform/tracker.js.map +1 -0
  240. package/dist/src/utility/actor.d.ts +11 -0
  241. package/dist/src/utility/actor.d.ts.map +1 -0
  242. package/dist/src/utility/actor.js +39 -0
  243. package/dist/src/utility/actor.js.map +1 -0
  244. package/dist/src/utility/batch-coordinator.d.ts +56 -0
  245. package/dist/src/utility/batch-coordinator.d.ts.map +1 -0
  246. package/dist/src/utility/batch-coordinator.js +127 -0
  247. package/dist/src/utility/batch-coordinator.js.map +1 -0
  248. package/dist/src/utility/block-id-to-bytes.d.ts +3 -0
  249. package/dist/src/utility/block-id-to-bytes.d.ts.map +1 -0
  250. package/dist/src/utility/block-id-to-bytes.js +7 -0
  251. package/dist/src/utility/block-id-to-bytes.js.map +1 -0
  252. package/dist/src/utility/ensured.d.ts +3 -0
  253. package/dist/src/utility/ensured.d.ts.map +1 -0
  254. package/dist/src/utility/ensured.js +24 -0
  255. package/dist/src/utility/ensured.js.map +1 -0
  256. package/dist/src/utility/groupby.d.ts +8 -0
  257. package/dist/src/utility/groupby.d.ts.map +1 -0
  258. package/dist/src/utility/groupby.js +15 -0
  259. package/dist/src/utility/groupby.js.map +1 -0
  260. package/dist/src/utility/is-record-empty.d.ts +3 -0
  261. package/dist/src/utility/is-record-empty.d.ts.map +1 -0
  262. package/dist/src/utility/is-record-empty.js +7 -0
  263. package/dist/src/utility/is-record-empty.js.map +1 -0
  264. package/dist/src/utility/latches.d.ts +11 -0
  265. package/dist/src/utility/latches.d.ts.map +1 -0
  266. package/dist/src/utility/latches.js +36 -0
  267. package/dist/src/utility/latches.js.map +1 -0
  268. package/dist/src/utility/nameof.d.ts +3 -0
  269. package/dist/src/utility/nameof.d.ts.map +1 -0
  270. package/dist/src/utility/nameof.js +5 -0
  271. package/dist/src/utility/nameof.js.map +1 -0
  272. package/dist/src/utility/pending.d.ts +13 -0
  273. package/dist/src/utility/pending.d.ts.map +1 -0
  274. package/dist/src/utility/pending.js +37 -0
  275. package/dist/src/utility/pending.js.map +1 -0
  276. package/package.json +56 -0
  277. package/src/blocks/block-store.ts +13 -0
  278. package/src/blocks/block-types.ts +11 -0
  279. package/src/blocks/helpers.ts +13 -0
  280. package/src/blocks/index.ts +5 -0
  281. package/src/blocks/structs.ts +17 -0
  282. package/src/btree/btree.ts +804 -0
  283. package/src/btree/independent-trunk.ts +54 -0
  284. package/src/btree/index.ts +5 -0
  285. package/src/btree/key-range.ts +15 -0
  286. package/src/btree/keyset.ts +6 -0
  287. package/src/btree/nodes.ts +25 -0
  288. package/src/btree/path.ts +37 -0
  289. package/src/btree/tree-block.ts +11 -0
  290. package/src/btree/trunk.ts +14 -0
  291. package/src/chain/chain-nodes.ts +24 -0
  292. package/src/chain/chain.ts +324 -0
  293. package/src/chain/index.ts +2 -0
  294. package/src/cluster/i-cluster.ts +6 -0
  295. package/src/cluster/index.ts +2 -0
  296. package/src/cluster/structs.ts +46 -0
  297. package/src/collection/action.ts +31 -0
  298. package/src/collection/collection.ts +200 -0
  299. package/src/collection/index.ts +3 -0
  300. package/src/collection/struct.ts +20 -0
  301. package/src/collections/diary/diary.ts +43 -0
  302. package/src/collections/diary/index.ts +2 -0
  303. package/src/collections/diary/struct.ts +3 -0
  304. package/src/collections/index.ts +2 -0
  305. package/src/collections/tree/collection-trunk.ts +25 -0
  306. package/src/collections/tree/index.ts +2 -0
  307. package/src/collections/tree/readme.md +19 -0
  308. package/src/collections/tree/struct.ts +18 -0
  309. package/src/collections/tree/tree.ts +124 -0
  310. package/src/index.ts +17 -0
  311. package/src/log/index.ts +2 -0
  312. package/src/log/log.ts +155 -0
  313. package/src/log/struct.ts +40 -0
  314. package/src/network/i-key-network.ts +24 -0
  315. package/src/network/i-peer-network.ts +8 -0
  316. package/src/network/i-repo.ts +19 -0
  317. package/src/network/index.ts +5 -0
  318. package/src/network/repo-protocol.ts +12 -0
  319. package/src/network/struct.ts +137 -0
  320. package/src/transaction/actions-engine.ts +83 -0
  321. package/src/transaction/context.ts +103 -0
  322. package/src/transaction/coordinator.ts +583 -0
  323. package/src/transaction/index.ts +30 -0
  324. package/src/transaction/session.ts +182 -0
  325. package/src/transaction/transaction.ts +205 -0
  326. package/src/transaction/validator.ts +150 -0
  327. package/src/transactor/index.ts +4 -0
  328. package/src/transactor/network-transactor.ts +435 -0
  329. package/src/transactor/transactor-source.ts +65 -0
  330. package/src/transactor/transactor.ts +44 -0
  331. package/src/transform/atomic.ts +16 -0
  332. package/src/transform/cache-source.ts +57 -0
  333. package/src/transform/helpers.ts +117 -0
  334. package/src/transform/index.ts +5 -0
  335. package/src/transform/struct.ts +22 -0
  336. package/src/transform/tracker.ts +70 -0
  337. package/src/utility/actor.ts +62 -0
  338. package/src/utility/batch-coordinator.ts +174 -0
  339. package/src/utility/block-id-to-bytes.ts +8 -0
  340. package/src/utility/ensured.ts +32 -0
  341. package/src/utility/groupby.ts +18 -0
  342. package/src/utility/is-record-empty.ts +5 -0
  343. package/src/utility/latches.ts +42 -0
  344. package/src/utility/nameof.ts +7 -0
  345. package/src/utility/pending.ts +41 -0
@@ -0,0 +1,297 @@
1
+ import {} from "@libp2p/interface";
2
+ import { peerIdFromString } from "@libp2p/peer-id";
3
+ import { transformForBlockId, groupBy, concatTransforms, concatTransform, transformsFromTransform, blockIdsForTransforms } from "../index.js";
4
+ import { blockIdToBytes } from "../utility/block-id-to-bytes.js";
5
+ import { isRecordEmpty } from "../utility/is-record-empty.js";
6
+ import { makeBatchesByPeer, incompleteBatches, everyBatch, allBatches, mergeBlocks, processBatches, createBatchesForPayload } from "../utility/batch-coordinator.js";
7
+ export class NetworkTransactor {
8
+ keyNetwork;
9
+ timeoutMs;
10
+ abortOrCancelTimeoutMs;
11
+ getRepo;
12
+ constructor(init) {
13
+ this.keyNetwork = init.keyNetwork;
14
+ this.timeoutMs = init.timeoutMs;
15
+ this.abortOrCancelTimeoutMs = init.abortOrCancelTimeoutMs;
16
+ this.getRepo = init.getRepo;
17
+ }
18
+ async get(blockGets) {
19
+ // Group by block id
20
+ const distinctBlockIds = Array.from(new Set(blockGets.blockIds));
21
+ const batches = await this.batchesForPayload(distinctBlockIds, distinctBlockIds, (gets, blockId, mergeWithGets) => [...(mergeWithGets ?? []), ...gets.filter(bid => bid === blockId)], []);
22
+ const expiration = Date.now() + this.timeoutMs;
23
+ let error;
24
+ try {
25
+ await processBatches(batches, (batch) => this.getRepo(batch.peerId).get({ blockIds: batch.payload, context: blockGets.context }, { expiration }), batch => batch.payload, (gets, blockId, mergeWithGets) => [...(mergeWithGets ?? []), ...gets.filter(bid => bid === blockId)], expiration, async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
26
+ }
27
+ catch (e) {
28
+ error = e;
29
+ }
30
+ // Second-chance retry: if batch failed to respond OR responded with "not found"
31
+ // Different cluster members may have different views; retry with other coordinators
32
+ const hasValidResponse = (b) => {
33
+ return b.request?.isResponse === true && b.request.response != null;
34
+ };
35
+ const hasBlockInResponse = (b) => {
36
+ if (!hasValidResponse(b))
37
+ return false;
38
+ const resp = b.request.response;
39
+ return b.payload.some(bid => {
40
+ const entry = resp[bid];
41
+ return entry && typeof entry === 'object' && 'block' in entry && entry.block != null;
42
+ });
43
+ };
44
+ // Retry batches that either failed to respond OR responded with "not found"
45
+ // This provides tolerance for different cluster member views
46
+ const retryable = Array.from(allBatches(batches)).filter(b => !hasValidResponse(b) || !hasBlockInResponse(b));
47
+ if (retryable.length > 0 && Date.now() < expiration) {
48
+ try {
49
+ const excludedByRoot = new Map();
50
+ for (const b of retryable) {
51
+ const excluded = new Set([b.peerId, ...(b.excludedPeers ?? [])]);
52
+ excludedByRoot.set(b, excluded);
53
+ const retries = await createBatchesForPayload(b.payload, b.payload, (gets, blockId, mergeWithGets) => [...(mergeWithGets ?? []), ...gets.filter(id => id === blockId)], Array.from(excluded), async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
54
+ if (retries.length > 0) {
55
+ b.subsumedBy = [...(b.subsumedBy ?? []), ...retries];
56
+ await processBatches(retries, (batch) => this.getRepo(batch.peerId).get({ blockIds: batch.payload, context: blockGets.context }, { expiration }), batch => batch.payload, (gets, blockId, mergeWithGets) => [...(mergeWithGets ?? []), ...gets.filter(id => id === blockId)], expiration, async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
57
+ }
58
+ }
59
+ }
60
+ catch (e) {
61
+ // keep original error if any
62
+ if (!error)
63
+ error = e;
64
+ }
65
+ }
66
+ // Cache the completed batches that had actual responses (not just coordinator not found)
67
+ const completedBatches = Array.from(allBatches(batches, b => b.request?.isResponse && !isRecordEmpty(b.request.response)));
68
+ // Create a lookup map from successful responses only
69
+ const resultEntries = new Map();
70
+ for (const batch of completedBatches) {
71
+ const resp = batch.request.response;
72
+ for (const [bid, res] of Object.entries(resp)) {
73
+ const existing = resultEntries.get(bid);
74
+ // Prefer responses that include a materialized block
75
+ const resHasBlock = res && typeof res === 'object' && 'block' in res && res.block != null;
76
+ const existingHasBlock = existing && typeof existing === 'object' && 'block' in existing && existing.block != null;
77
+ if (!existing || (resHasBlock && !existingHasBlock)) {
78
+ resultEntries.set(bid, res);
79
+ }
80
+ }
81
+ }
82
+ // Ensure we have at least one response per requested block id
83
+ const missingIds = distinctBlockIds.filter(bid => !resultEntries.has(bid));
84
+ if (missingIds.length > 0) {
85
+ const details = this.formatBatchStatuses(batches, b => b.request?.isResponse ?? false, b => {
86
+ const status = b.request == null ? 'no-response' : (b.request.isResponse ? 'response' : 'in-flight');
87
+ return `${b.peerId.toString()}[block:${b.blockId}](${status})`;
88
+ });
89
+ const aggregate = new Error(`Some peers did not complete: ${details}${error ? `; root: ${error.message}` : ''}`);
90
+ aggregate.cause = error;
91
+ throw aggregate;
92
+ }
93
+ return Object.fromEntries(resultEntries);
94
+ }
95
+ async getStatus(blockActions) {
96
+ throw new Error("Method not implemented.");
97
+ }
98
+ async consolidateCoordinators(blockIds, transforms, transformForBlock) {
99
+ const blockCoordinators = await Promise.all(blockIds.map(async (bid) => ({
100
+ blockId: bid,
101
+ coordinator: await this.keyNetwork.findCoordinator(await blockIdToBytes(bid), { excludedPeers: [] })
102
+ })));
103
+ const byCoordinator = new Map();
104
+ for (const { blockId, coordinator } of blockCoordinators) {
105
+ const key = coordinator.toString();
106
+ const blocks = byCoordinator.get(key) ?? [];
107
+ blocks.push(blockId);
108
+ byCoordinator.set(key, blocks);
109
+ }
110
+ const batches = [];
111
+ for (const [coordinatorStr, consolidatedBlocks] of byCoordinator) {
112
+ const coordinator = blockCoordinators.find(bc => bc.coordinator.toString() === coordinatorStr).coordinator;
113
+ let batchTransforms = { inserts: {}, updates: {}, deletes: [] };
114
+ for (const bid of consolidatedBlocks) {
115
+ const blockTransforms = transformForBlock(transforms, bid, batchTransforms);
116
+ batchTransforms = blockTransforms;
117
+ }
118
+ batches.push({
119
+ peerId: coordinator,
120
+ payload: batchTransforms,
121
+ blockId: consolidatedBlocks[0],
122
+ coordinatingBlockIds: consolidatedBlocks,
123
+ excludedPeers: []
124
+ });
125
+ }
126
+ return batches;
127
+ }
128
+ async pend(blockAction) {
129
+ const transformForBlock = (payload, blockId, mergeWithPayload) => {
130
+ const filteredTransform = transformForBlockId(payload, blockId);
131
+ return mergeWithPayload
132
+ ? concatTransform(mergeWithPayload, blockId, filteredTransform)
133
+ : transformsFromTransform(filteredTransform, blockId);
134
+ };
135
+ const blockIds = blockIdsForTransforms(blockAction.transforms);
136
+ const batches = await this.consolidateCoordinators(blockIds, blockAction.transforms, transformForBlock);
137
+ const expiration = Date.now() + this.timeoutMs;
138
+ let error;
139
+ try {
140
+ // Process all batches, noting all outstanding peers
141
+ await processBatches(batches, (batch) => this.getRepo(batch.peerId).pend({ ...blockAction, transforms: batch.payload }, {
142
+ expiration,
143
+ coordinatingBlockIds: batch.coordinatingBlockIds
144
+ }), batch => blockIdsForTransforms(batch.payload), transformForBlock, expiration, async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
145
+ // Cache resolved coordinators for follow-up commit to hit the same peers
146
+ try {
147
+ const pn = this.keyNetwork;
148
+ if (typeof pn?.recordCoordinator === 'function') {
149
+ for (const b of Array.from(allBatches(batches))) {
150
+ pn.recordCoordinator(await blockIdToBytes(b.blockId), b.peerId);
151
+ }
152
+ }
153
+ }
154
+ catch (e) {
155
+ console.warn('Failed to record coordinator hint', e);
156
+ }
157
+ }
158
+ catch (e) {
159
+ error = e;
160
+ }
161
+ if (!everyBatch(batches, b => b.request?.isResponse && b.request.response.success)) {
162
+ const details = this.formatBatchStatuses(batches, b => (b.request?.isResponse && b.request.response?.success) ?? false, b => {
163
+ const status = b.request == null ? 'no-response' : (b.request.isResponse ? 'non-success' : 'in-flight');
164
+ return `${b.peerId.toString()}[block:${b.blockId}](${status})`;
165
+ });
166
+ const aggregate = new Error(`Some peers did not complete: ${details}${error ? `; root: ${error.message}` : ''}`);
167
+ const prior = error;
168
+ aggregate.cause = prior;
169
+ aggregate.errors = prior ? [prior] : [];
170
+ error = aggregate;
171
+ }
172
+ if (error) { // If any failures, cancel all pending actions as background microtask
173
+ Promise.resolve().then(() => this.cancelBatch(batches, { blockIds, actionId: blockAction.actionId }));
174
+ const stale = Array.from(allBatches(batches, b => b.request?.isResponse && !b.request.response.success));
175
+ if (stale.length > 0) { // Any active stale failures should preempt reporting connection or other potential transient errors (we have information)
176
+ return {
177
+ success: false,
178
+ missing: distinctBlockActionTransforms(stale.flatMap(b => b.request.response.missing).filter((x) => x !== undefined)),
179
+ };
180
+ }
181
+ throw error; // No stale failures, report the original error
182
+ }
183
+ // Collect replies back into result structure
184
+ const completed = Array.from(allBatches(batches, b => b.request?.isResponse && b.request.response.success));
185
+ return {
186
+ success: true,
187
+ pending: completed.flatMap(b => b.request.response.pending),
188
+ blockIds: blockIdsForTransforms(blockAction.transforms)
189
+ };
190
+ }
191
+ async cancel(actionRef) {
192
+ const batches = await this.batchesForPayload(actionRef.blockIds, actionRef.blockIds, mergeBlocks, []);
193
+ const expiration = Date.now() + this.abortOrCancelTimeoutMs;
194
+ await processBatches(batches, (batch) => this.getRepo(batch.peerId).cancel({ actionId: actionRef.actionId, blockIds: batch.payload }, { expiration }), batch => batch.payload, mergeBlocks, expiration, async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
195
+ }
196
+ async queryClusterNominees(blockId) {
197
+ const blockIdBytes = await blockIdToBytes(blockId);
198
+ const clusterPeers = await this.keyNetwork.findCluster(blockIdBytes);
199
+ const nominees = Object.keys(clusterPeers).map(idStr => peerIdFromString(idStr));
200
+ return { nominees };
201
+ }
202
+ async commit(request) {
203
+ const allBlockIds = [...new Set([...request.blockIds, request.tailId])];
204
+ // Commit the header block if provided and not already in blockIds
205
+ if (request.headerId && !request.blockIds.includes(request.headerId)) {
206
+ const headerResult = await this.commitBlock(request.headerId, allBlockIds, request.actionId, request.rev);
207
+ if (!headerResult.success) {
208
+ return headerResult;
209
+ }
210
+ }
211
+ // Commit the tail block
212
+ const tailResult = await this.commitBlock(request.tailId, allBlockIds, request.actionId, request.rev);
213
+ if (!tailResult.success) {
214
+ return tailResult;
215
+ }
216
+ // Commit all remaining block ids (excluding tail and header if it was already handled)
217
+ const remainingBlocks = request.blockIds.filter(bid => bid !== request.tailId &&
218
+ !(request.headerId && bid === request.headerId && !request.blockIds.includes(request.headerId)));
219
+ if (remainingBlocks.length > 0) {
220
+ const { batches, error } = await this.commitBlocks({ blockIds: remainingBlocks, actionId: request.actionId, rev: request.rev });
221
+ if (error) {
222
+ // Non-tail block commit failures should not fail the overall action once the tail has committed.
223
+ // Proceed and rely on reconciliation paths (e.g. reads with context) to finalize state on lagging peers.
224
+ try {
225
+ console.warn('[NetworkTransactor] non-tail commit had errors; proceeding after tail commit:', error.message);
226
+ }
227
+ catch { /* ignore */ }
228
+ }
229
+ }
230
+ return { success: true };
231
+ }
232
+ async commitBlock(blockId, blockIds, actionId, rev) {
233
+ const { batches: tailBatches, error: tailError } = await this.commitBlocks({ blockIds: [blockId], actionId, rev });
234
+ if (tailError) {
235
+ // Cancel all pending actions as background microtask
236
+ Promise.resolve().then(() => this.cancel({ blockIds, actionId }));
237
+ // Collect and return any active stale failures
238
+ const stale = Array.from(allBatches(tailBatches, b => b.request?.isResponse && !b.request.response.success));
239
+ if (stale.length > 0) {
240
+ return { missing: distinctBlockActionTransforms(stale.flatMap(b => b.request.response.missing)), success: false };
241
+ }
242
+ throw tailError;
243
+ }
244
+ return { success: true };
245
+ }
246
+ /** Attempts to commit a set of blocks, and handles failures and errors */
247
+ async commitBlocks({ blockIds, actionId, rev }) {
248
+ const expiration = Date.now() + this.timeoutMs;
249
+ const batches = await this.batchesForPayload(blockIds, blockIds, mergeBlocks, []);
250
+ let error;
251
+ try {
252
+ await processBatches(batches, (batch) => this.getRepo(batch.peerId).commit({ actionId, blockIds: batch.payload, rev }, { expiration }), batch => batch.payload, mergeBlocks, expiration, async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
253
+ }
254
+ catch (e) {
255
+ error = e;
256
+ }
257
+ if (!everyBatch(batches, b => b.request?.isResponse && b.request.response.success)) {
258
+ const details = this.formatBatchStatuses(batches, b => (b.request?.isResponse && b.request.response?.success) ?? false, b => {
259
+ const status = b.request == null ? 'no-response' : (b.request.isResponse ? 'non-success' : 'in-flight');
260
+ const resp = b.request?.response;
261
+ const extra = resp && resp.success === false ? (Array.isArray(resp.missing) ? ` missing=${resp.missing.length}` : ' success=false') : '';
262
+ return `${b.peerId.toString()}[blocks:${b.payload instanceof Array ? b.payload.length : 1}](${status})${extra ? ' ' + extra : ''}`;
263
+ });
264
+ const aggregate = new Error(`Some peers did not complete: ${details}${error ? `; root: ${error.message}` : ''}`);
265
+ aggregate.cause = error;
266
+ error = aggregate;
267
+ }
268
+ return { batches, error };
269
+ }
270
+ ;
271
+ /** Creates batches for a given payload, grouped by the coordinating peer for each block id */
272
+ async batchesForPayload(blockIds, payload, getBlockPayload, excludedPeers) {
273
+ return createBatchesForPayload(blockIds, payload, getBlockPayload, excludedPeers, async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
274
+ }
275
+ /** Cancels a pending transaction by canceling all blocks associated with the transaction, including failed peers */
276
+ async cancelBatch(batches, actionRef) {
277
+ const expiration = Date.now() + this.abortOrCancelTimeoutMs;
278
+ const operationBatches = makeBatchesByPeer(Array.from(allBatches(batches)).map(b => [b.blockId, b.peerId]), actionRef.blockIds, mergeBlocks, []);
279
+ await processBatches(operationBatches, (batch) => this.getRepo(batch.peerId).cancel({ actionId: actionRef.actionId, blockIds: batch.payload }, { expiration }), batch => batch.payload, mergeBlocks, expiration, async (blockId, options) => this.keyNetwork.findCoordinator(await blockIdToBytes(blockId), options));
280
+ }
281
+ formatBatchStatuses(batches, isSuccess, formatter) {
282
+ const incompletes = Array.from(incompleteBatches(batches));
283
+ let details = incompletes.map(formatter).join(', ');
284
+ if (details.length === 0) {
285
+ details = Array.from(allBatches(batches)).map(formatter).join(', ');
286
+ }
287
+ return details;
288
+ }
289
+ }
290
+ /**
291
+ * Returns the block actions grouped by action id and concatenated transforms
292
+ */
293
+ export function distinctBlockActionTransforms(blockActions) {
294
+ const grouped = groupBy(blockActions, ({ actionId }) => actionId);
295
+ return Object.entries(grouped).map(([actionId, actions]) => ({ actionId, transforms: concatTransforms(...actions.map(t => t.transforms)) }));
296
+ }
297
+ //# sourceMappingURL=network-transactor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-transactor.js","sourceRoot":"","sources":["../../../src/transactor/network-transactor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAA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
1
+ import type { IBlock, BlockId, BlockHeader, ITransactor, ActionId, StaleFailure, ActionContext, BlockType, BlockSource, Transforms } from "../index.js";
2
+ export declare class TransactorSource<TBlock extends IBlock> implements BlockSource<TBlock> {
3
+ private readonly collectionId;
4
+ private readonly transactor;
5
+ actionContext: ActionContext | undefined;
6
+ constructor(collectionId: BlockId, transactor: ITransactor, actionContext: ActionContext | undefined);
7
+ createBlockHeader(type: BlockType, newId?: BlockId): BlockHeader;
8
+ generateId(): BlockId;
9
+ tryGet(id: BlockId): Promise<TBlock | undefined>;
10
+ /**
11
+ * Attempts to apply the given transforms in a transactional manner.
12
+ * @param transform - The transforms to apply.
13
+ * @param actionId - The action id.
14
+ * @param rev - The revision number.
15
+ * @param headerId - The Id of the collection's header block. If specified, this block's transform is performed first,
16
+ * in the event that there is a race to create the collection itself, or in the event that the tail block is full and
17
+ * is transitioning to a new block. Ignored if the given headerId is not present in the transforms.
18
+ * @param tailId - The Id of the collection's log tail block. If specified, this block's transform is performed next
19
+ * (prior to the rest of the block operations), to resolve the "winner" of a race to commit to the collection.
20
+ * @returns A promise that resolves to undefined if the action is successful, or a StaleFailure if the action is stale.
21
+ */
22
+ transact(transform: Transforms, actionId: ActionId, rev: number, headerId: BlockId, tailId: BlockId): Promise<undefined | StaleFailure>;
23
+ }
24
+ //# sourceMappingURL=transactor-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactor-source.d.ts","sourceRoot":"","sources":["../../../src/transactor/transactor-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAExJ,qBAAa,gBAAgB,CAAC,MAAM,SAAS,MAAM,CAAE,YAAW,WAAW,CAAC,MAAM,CAAC;IAEjF,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU;IACpB,aAAa,EAAE,aAAa,GAAG,SAAS;gBAF9B,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,WAAW,EACjC,aAAa,EAAE,aAAa,GAAG,SAAS;IAGhD,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW;IAQhE,UAAU,IAAI,OAAO;IAKf,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAUtD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC;CAiB7I"}
@@ -0,0 +1,62 @@
1
+ import { randomBytes } from '@libp2p/crypto';
2
+ import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
3
+ export class TransactorSource {
4
+ collectionId;
5
+ transactor;
6
+ actionContext;
7
+ constructor(collectionId, transactor, actionContext) {
8
+ this.collectionId = collectionId;
9
+ this.transactor = transactor;
10
+ this.actionContext = actionContext;
11
+ }
12
+ createBlockHeader(type, newId) {
13
+ return {
14
+ type,
15
+ id: newId ?? this.generateId(),
16
+ collectionId: this.collectionId,
17
+ };
18
+ }
19
+ generateId() {
20
+ // 256-bits to fully utilize DHT address space
21
+ return uint8ArrayToString(randomBytes(32), 'base64url');
22
+ }
23
+ async tryGet(id) {
24
+ const result = await this.transactor.get({ blockIds: [id], context: this.actionContext });
25
+ if (result) {
26
+ const { block, state } = result[id];
27
+ // TODO: if the state reports that there is a pending action, record this so that we are sure to update before syncing
28
+ //state.pendings
29
+ return block;
30
+ }
31
+ }
32
+ /**
33
+ * Attempts to apply the given transforms in a transactional manner.
34
+ * @param transform - The transforms to apply.
35
+ * @param actionId - The action id.
36
+ * @param rev - The revision number.
37
+ * @param headerId - The Id of the collection's header block. If specified, this block's transform is performed first,
38
+ * in the event that there is a race to create the collection itself, or in the event that the tail block is full and
39
+ * is transitioning to a new block. Ignored if the given headerId is not present in the transforms.
40
+ * @param tailId - The Id of the collection's log tail block. If specified, this block's transform is performed next
41
+ * (prior to the rest of the block operations), to resolve the "winner" of a race to commit to the collection.
42
+ * @returns A promise that resolves to undefined if the action is successful, or a StaleFailure if the action is stale.
43
+ */
44
+ async transact(transform, actionId, rev, headerId, tailId) {
45
+ const pendResult = await this.transactor.pend({ transforms: transform, actionId, rev, policy: 'r' });
46
+ if (!pendResult.success) {
47
+ return pendResult;
48
+ }
49
+ const isNew = Object.hasOwn(transform.inserts, headerId);
50
+ const commitResult = await this.transactor.commit({
51
+ headerId: isNew ? headerId : undefined,
52
+ tailId,
53
+ blockIds: pendResult.blockIds,
54
+ actionId,
55
+ rev
56
+ });
57
+ if (!commitResult.success) {
58
+ return commitResult;
59
+ }
60
+ }
61
+ }
62
+ //# sourceMappingURL=transactor-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactor-source.js","sourceRoot":"","sources":["../../../src/transactor/transactor-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGtE,MAAM,OAAO,gBAAgB;IAEV;IACA;IACV;IAHR,YACkB,YAAqB,EACrB,UAAuB,EACjC,aAAwC;QAF9B,iBAAY,GAAZ,YAAY,CAAS;QACrB,eAAU,GAAV,UAAU,CAAa;QACjC,kBAAa,GAAb,aAAa,CAA2B;IAC5C,CAAC;IAEL,iBAAiB,CAAC,IAAe,EAAE,KAAe;QACjD,OAAO;YACN,IAAI;YACJ,EAAE,EAAE,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE;YAC9B,YAAY,EAAE,IAAI,CAAC,YAAY;SAC/B,CAAC;IACH,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AAY,CAAC;QACrB,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,38 @@
1
+ import type { GetBlockResults, ActionBlocks, BlockActionStatus, PendResult, CommitResult, PendRequest, CommitRequest, BlockGets, BlockId } from "../index.js";
2
+ import type { PeerId } from "@libp2p/interface";
3
+ export type ClusterNomineesResult = {
4
+ /** Peer IDs of the cluster members who can participate in consensus */
5
+ nominees: PeerId[];
6
+ };
7
+ export type ITransactor = {
8
+ /** Get blocks by their IDs and versions or a specific action
9
+ - Does not update the version of the block, but the action is available for explicit reading, and for committing
10
+ - If the action targets the correct version, the call succeeds, unless failIfPending and there are any pending actions - the caller may choose to wait for pending actions to clear rather than risk racing with them
11
+ - If the action targets an older version, the call fails, and the caller must resync using the missing actions
12
+ */
13
+ get(blockGets: BlockGets): Promise<GetBlockResults>;
14
+ /** Get statuses of block actions */
15
+ getStatus(actionRefs: ActionBlocks[]): Promise<BlockActionStatus[]>;
16
+ /** Post an action for a set of blocks
17
+ - Does not update the version of the block, but the action is available for explicit reading, and for committing
18
+ - If the action targets the correct version, the call succeeds, unless pending = 'fail' and there are any pending actions - the caller may choose to wait for pending actions to clear rather than risk racing with them
19
+ - If the action targets an older version, the call fails, and the caller must resync using the missing actions
20
+ */
21
+ pend(blockAction: PendRequest): Promise<PendResult>;
22
+ /** Cancel a pending action
23
+ - If the given action ID is pending, it is canceled
24
+ */
25
+ cancel(actionRef: ActionBlocks): Promise<void>;
26
+ /** Commit a pending action
27
+ - If the action references the current version, the pending action is committed
28
+ - If the returned fails, the transforms necessary to update all overlapping blocks are returned
29
+ - If the action mentions other collections, those are assumed conditions - returned conditions only list inherited conditions
30
+ */
31
+ commit(request: CommitRequest): Promise<CommitResult>;
32
+ /** Query cluster nominees for a critical block (used in GATHER phase for multi-collection transactions)
33
+ - Returns the peer IDs of cluster members who can participate in consensus for the given block
34
+ - Used to build the supercluster for multi-collection transaction consensus
35
+ */
36
+ queryClusterNominees?(blockId: BlockId): Promise<ClusterNomineesResult>;
37
+ };
38
+ //# sourceMappingURL=transactor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactor.d.ts","sourceRoot":"","sources":["../../../src/transactor/transactor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC9J,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,qBAAqB,GAAG;IACnC,uEAAuE;IACvE,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACzB;;;;OAIG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEpD,oCAAoC;IACpC,SAAS,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAEpE;;;;OAIG;IACH,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEpD;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEtD;;;OAGG;IACH,oBAAoB,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACxE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transactor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactor.js","sourceRoot":"","sources":["../../../src/transactor/transactor.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { Tracker } from "./tracker.js";
2
+ import type { IBlock, BlockStore } from "../index.js";
3
+ export declare class Atomic<TBlock extends IBlock> extends Tracker<TBlock> {
4
+ readonly store: BlockStore<TBlock>;
5
+ constructor(store: BlockStore<TBlock>);
6
+ commit(): void;
7
+ }
8
+ //# sourceMappingURL=atomic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atomic.d.ts","sourceRoot":"","sources":["../../../src/transform/atomic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGtD,qBAAa,MAAM,CAAC,MAAM,SAAS,MAAM,CAAE,SAAQ,OAAO,CAAC,MAAM,CAAC;aACrC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC;gBAAzB,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC;IAIrD,MAAM;CAMN"}
@@ -0,0 +1,14 @@
1
+ import { Tracker } from "./tracker.js";
2
+ import { applyTransformToStore } from "./helpers.js";
3
+ export class Atomic extends Tracker {
4
+ store;
5
+ constructor(store) {
6
+ super(store);
7
+ this.store = store;
8
+ }
9
+ commit() {
10
+ const transform = this.reset();
11
+ applyTransformToStore(transform, this.store);
12
+ }
13
+ }
14
+ //# sourceMappingURL=atomic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../../src/transform/atomic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,OAAO,MAA8B,SAAQ,OAAe;IACrC;IAA5B,YAA4B,KAAyB;QACpD,KAAK,CAAC,KAAK,CAAC,CAAC;QADc,UAAK,GAAL,KAAK,CAAoB;IAErD,CAAC;IAED,MAAM;QACL,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC/B,qBAAqB,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;CAGD"}
@@ -0,0 +1,13 @@
1
+ import type { IBlock, BlockHeader, BlockId, BlockSource, BlockType, Transforms } from "../index.js";
2
+ export declare class CacheSource<T extends IBlock> implements BlockSource<T> {
3
+ protected readonly source: BlockSource<T>;
4
+ protected cache: Map<string, T>;
5
+ constructor(source: BlockSource<T>);
6
+ tryGet(id: BlockId): Promise<T | undefined>;
7
+ generateId(): BlockId;
8
+ createBlockHeader(type: BlockType, newId?: BlockId): BlockHeader;
9
+ clear(blockIds?: BlockId[] | undefined): void;
10
+ /** Mutates the cache without affecting the source */
11
+ transformCache(transform: Transforms): void;
12
+ }
13
+ //# sourceMappingURL=cache-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-source.d.ts","sourceRoot":"","sources":["../../../src/transform/cache-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGpG,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAIlE,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAH1C,SAAS,CAAC,KAAK,iBAAyB;gBAGpB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAGpC,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAWjD,UAAU,IAAI,OAAO;IAIrB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW;IAIhE,KAAK,CAAC,QAAQ,GAAE,OAAO,EAAE,GAAG,SAAqB;IAUjD,qDAAqD;IACrD,cAAc,CAAC,SAAS,EAAE,UAAU;CAgBpC"}
@@ -0,0 +1,52 @@
1
+ import { applyOperation } from "../index.js";
2
+ export class CacheSource {
3
+ source;
4
+ cache = new Map();
5
+ constructor(source) {
6
+ this.source = source;
7
+ }
8
+ async tryGet(id) {
9
+ let block = this.cache.get(id);
10
+ if (!block) {
11
+ block = await this.source.tryGet(id);
12
+ if (block) {
13
+ this.cache.set(id, block);
14
+ }
15
+ }
16
+ return structuredClone(block);
17
+ }
18
+ generateId() {
19
+ return this.source.generateId();
20
+ }
21
+ createBlockHeader(type, newId) {
22
+ return this.source.createBlockHeader(type, newId);
23
+ }
24
+ clear(blockIds = undefined) {
25
+ if (blockIds) {
26
+ for (const id of blockIds) {
27
+ this.cache.delete(id);
28
+ }
29
+ }
30
+ else {
31
+ this.cache.clear();
32
+ }
33
+ }
34
+ /** Mutates the cache without affecting the source */
35
+ transformCache(transform) {
36
+ for (const blockId of transform.deletes) {
37
+ this.cache.delete(blockId);
38
+ }
39
+ for (const [, block] of Object.entries(transform.inserts)) {
40
+ this.cache.set(block.header.id, structuredClone(block));
41
+ }
42
+ for (const [blockId, operations] of Object.entries(transform.updates)) {
43
+ for (const op of operations) {
44
+ const block = this.cache.get(blockId);
45
+ if (block) {
46
+ applyOperation(block, op);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ //# sourceMappingURL=cache-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-source.js","sourceRoot":"","sources":["../../../src/transform/cache-source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,OAAO,WAAW;IAIH;IAHV,KAAK,GAAG,IAAI,GAAG,EAAc,CAAC;IAExC,YACoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IACtC,CAAC;IAEL,KAAK,CAAC,MAAM,CAAC,EAAW;QACvB,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;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CAAC,OAAO,CAAC,EAAE,CAAC;YACvE,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;gBAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACtC,IAAI,KAAK,EAAE,CAAC;oBACX,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAC3B,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,25 @@
1
+ import type { BlockId, BlockOperation, BlockOperations, BlockStore, IBlock, Transform, Transforms } from "../index.js";
2
+ /** Mutates the given block with a copy of the given operation */
3
+ export declare function applyOperation(block: IBlock, [entity, index, deleteCount, inserted]: BlockOperation): void;
4
+ /** Mutates the given block with the given set of operations */
5
+ export declare function applyOperations(block: IBlock, operations: BlockOperations): void;
6
+ /** Returns a copy of the block with the given operation applied */
7
+ export declare function withOperation(block: IBlock, [entity, index, deleteCount, inserted]: BlockOperation): {
8
+ header: import("../index.js").BlockHeader;
9
+ };
10
+ /** The set of distinct block ids affected by the transform */
11
+ export declare function blockIdsForTransforms(transforms: Transforms | undefined): string[];
12
+ /** Returns an empty transform */
13
+ export declare function emptyTransforms(): Transforms;
14
+ export declare function copyTransforms(transform: Transforms): Transforms;
15
+ export declare function mergeTransforms(a: Transforms, b: Transforms): Transforms;
16
+ export declare function isTransformsEmpty(transform: Transforms): boolean;
17
+ export declare function concatTransforms(...transforms: Transforms[]): Transforms;
18
+ export declare function transformForBlockId(transform: Transforms, blockId: BlockId): Transform;
19
+ export declare function transformsFromTransform(transform: Transform, blockId: BlockId): Transforms;
20
+ export declare function applyTransformToStore<T extends IBlock>(transform: Transforms, store: BlockStore<T>): void;
21
+ /** Applies a transform to the given block */
22
+ export declare function applyTransform(block: IBlock | undefined, transform: Transform): IBlock | undefined;
23
+ /** Concatenates a transform to the given transforms */
24
+ export declare function concatTransform(transforms: Transforms, blockId: BlockId, transform: Transform): Transforms;
25
+ //# s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