@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.
- package/README.md +328 -0
- package/dist/index.min.js +18 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/blocks/block-store.d.ts +12 -0
- package/dist/src/blocks/block-store.d.ts.map +1 -0
- package/dist/src/blocks/block-store.js +2 -0
- package/dist/src/blocks/block-store.js.map +1 -0
- package/dist/src/blocks/block-types.d.ts +3 -0
- package/dist/src/blocks/block-types.d.ts.map +1 -0
- package/dist/src/blocks/block-types.js +9 -0
- package/dist/src/blocks/block-types.js.map +1 -0
- package/dist/src/blocks/helpers.d.ts +4 -0
- package/dist/src/blocks/helpers.d.ts.map +1 -0
- package/dist/src/blocks/helpers.js +12 -0
- package/dist/src/blocks/helpers.js.map +1 -0
- package/dist/src/blocks/index.d.ts +5 -0
- package/dist/src/blocks/index.d.ts.map +1 -0
- package/dist/src/blocks/index.js +5 -0
- package/dist/src/blocks/index.js.map +1 -0
- package/dist/src/blocks/structs.d.ts +14 -0
- package/dist/src/blocks/structs.d.ts.map +1 -0
- package/dist/src/blocks/structs.js +2 -0
- package/dist/src/blocks/structs.js.map +1 -0
- package/dist/src/btree/btree.d.ts +135 -0
- package/dist/src/btree/btree.d.ts.map +1 -0
- package/dist/src/btree/btree.js +727 -0
- package/dist/src/btree/btree.js.map +1 -0
- package/dist/src/btree/independent-trunk.d.ts +17 -0
- package/dist/src/btree/independent-trunk.d.ts.map +1 -0
- package/dist/src/btree/independent-trunk.js +41 -0
- package/dist/src/btree/independent-trunk.js.map +1 -0
- package/dist/src/btree/index.d.ts +6 -0
- package/dist/src/btree/index.d.ts.map +1 -0
- package/dist/src/btree/index.js +6 -0
- package/dist/src/btree/index.js.map +1 -0
- package/dist/src/btree/key-range.d.ts +13 -0
- package/dist/src/btree/key-range.d.ts.map +1 -0
- package/dist/src/btree/key-range.js +20 -0
- package/dist/src/btree/key-range.js.map +1 -0
- package/dist/src/btree/keyset.d.ts +4 -0
- package/dist/src/btree/keyset.d.ts.map +1 -0
- package/dist/src/btree/keyset.js +4 -0
- package/dist/src/btree/keyset.js.map +1 -0
- package/dist/src/btree/nodes.d.ts +16 -0
- package/dist/src/btree/nodes.d.ts.map +1 -0
- package/dist/src/btree/nodes.js +9 -0
- package/dist/src/btree/nodes.js.map +1 -0
- package/dist/src/btree/path.d.ts +22 -0
- package/dist/src/btree/path.d.ts.map +1 -0
- package/dist/src/btree/path.js +39 -0
- package/dist/src/btree/path.js.map +1 -0
- package/dist/src/btree/tree-block.d.ts +7 -0
- package/dist/src/btree/tree-block.d.ts.map +1 -0
- package/dist/src/btree/tree-block.js +5 -0
- package/dist/src/btree/tree-block.js.map +1 -0
- package/dist/src/btree/trunk.d.ts +13 -0
- package/dist/src/btree/trunk.d.ts.map +1 -0
- package/dist/src/btree/trunk.js +2 -0
- package/dist/src/btree/trunk.js.map +1 -0
- package/dist/src/chain/chain-nodes.d.ts +18 -0
- package/dist/src/chain/chain-nodes.d.ts.map +1 -0
- package/dist/src/chain/chain-nodes.js +10 -0
- package/dist/src/chain/chain-nodes.js.map +1 -0
- package/dist/src/chain/chain.d.ts +75 -0
- package/dist/src/chain/chain.d.ts.map +1 -0
- package/dist/src/chain/chain.js +268 -0
- package/dist/src/chain/chain.js.map +1 -0
- package/dist/src/chain/index.d.ts +2 -0
- package/dist/src/chain/index.d.ts.map +1 -0
- package/dist/src/chain/index.js +2 -0
- package/dist/src/chain/index.js.map +1 -0
- package/dist/src/cluster/i-cluster.d.ts +5 -0
- package/dist/src/cluster/i-cluster.d.ts.map +1 -0
- package/dist/src/cluster/i-cluster.js +2 -0
- package/dist/src/cluster/i-cluster.js.map +1 -0
- package/dist/src/cluster/index.d.ts +3 -0
- package/dist/src/cluster/index.d.ts.map +1 -0
- package/dist/src/cluster/index.js +3 -0
- package/dist/src/cluster/index.js.map +1 -0
- package/dist/src/cluster/structs.d.ts +47 -0
- package/dist/src/cluster/structs.d.ts.map +1 -0
- package/dist/src/cluster/structs.js +2 -0
- package/dist/src/cluster/structs.js.map +1 -0
- package/dist/src/collection/action.d.ts +26 -0
- package/dist/src/collection/action.d.ts.map +1 -0
- package/dist/src/collection/action.js +2 -0
- package/dist/src/collection/action.js.map +1 -0
- package/dist/src/collection/collection.d.ts +48 -0
- package/dist/src/collection/collection.d.ts.map +1 -0
- package/dist/src/collection/collection.js +175 -0
- package/dist/src/collection/collection.js.map +1 -0
- package/dist/src/collection/index.d.ts +4 -0
- package/dist/src/collection/index.d.ts.map +1 -0
- package/dist/src/collection/index.js +4 -0
- package/dist/src/collection/index.js.map +1 -0
- package/dist/src/collection/struct.d.ts +16 -0
- package/dist/src/collection/struct.d.ts.map +1 -0
- package/dist/src/collection/struct.js +2 -0
- package/dist/src/collection/struct.js.map +1 -0
- package/dist/src/collections/diary/diary.d.ts +9 -0
- package/dist/src/collections/diary/diary.d.ts.map +1 -0
- package/dist/src/collections/diary/diary.js +37 -0
- package/dist/src/collections/diary/diary.js.map +1 -0
- package/dist/src/collections/diary/index.d.ts +3 -0
- package/dist/src/collections/diary/index.d.ts.map +1 -0
- package/dist/src/collections/diary/index.js +3 -0
- package/dist/src/collections/diary/index.js.map +1 -0
- package/dist/src/collections/diary/struct.d.ts +2 -0
- package/dist/src/collections/diary/struct.d.ts.map +1 -0
- package/dist/src/collections/diary/struct.js +3 -0
- package/dist/src/collections/diary/struct.js.map +1 -0
- package/dist/src/collections/index.d.ts +3 -0
- package/dist/src/collections/index.d.ts.map +1 -0
- package/dist/src/collections/index.js +3 -0
- package/dist/src/collections/index.js.map +1 -0
- package/dist/src/collections/tree/collection-trunk.d.ts +11 -0
- package/dist/src/collections/tree/collection-trunk.d.ts.map +1 -0
- package/dist/src/collections/tree/collection-trunk.js +22 -0
- package/dist/src/collections/tree/collection-trunk.js.map +1 -0
- package/dist/src/collections/tree/index.d.ts +3 -0
- package/dist/src/collections/tree/index.d.ts.map +1 -0
- package/dist/src/collections/tree/index.js +3 -0
- package/dist/src/collections/tree/index.js.map +1 -0
- package/dist/src/collections/tree/struct.d.ts +12 -0
- package/dist/src/collections/tree/struct.d.ts.map +1 -0
- package/dist/src/collections/tree/struct.js +4 -0
- package/dist/src/collections/tree/struct.js.map +1 -0
- package/dist/src/collections/tree/tree.d.ts +34 -0
- package/dist/src/collections/tree/tree.d.ts.map +1 -0
- package/dist/src/collections/tree/tree.js +100 -0
- package/dist/src/collections/tree/tree.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +18 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/log/index.d.ts +3 -0
- package/dist/src/log/index.d.ts.map +1 -0
- package/dist/src/log/index.js +3 -0
- package/dist/src/log/index.js.map +1 -0
- package/dist/src/log/log.d.ts +57 -0
- package/dist/src/log/log.d.ts.map +1 -0
- package/dist/src/log/log.js +131 -0
- package/dist/src/log/log.js.map +1 -0
- package/dist/src/log/struct.d.ts +36 -0
- package/dist/src/log/struct.d.ts.map +1 -0
- package/dist/src/log/struct.js +3 -0
- package/dist/src/log/struct.js.map +1 -0
- package/dist/src/network/i-key-network.d.ts +21 -0
- package/dist/src/network/i-key-network.d.ts.map +1 -0
- package/dist/src/network/i-key-network.js +2 -0
- package/dist/src/network/i-key-network.js.map +1 -0
- package/dist/src/network/i-peer-network.d.ts +8 -0
- package/dist/src/network/i-peer-network.d.ts.map +1 -0
- package/dist/src/network/i-peer-network.js +2 -0
- package/dist/src/network/i-peer-network.js.map +1 -0
- package/dist/src/network/i-repo.d.ts +17 -0
- package/dist/src/network/i-repo.d.ts.map +1 -0
- package/dist/src/network/i-repo.js +2 -0
- package/dist/src/network/i-repo.js.map +1 -0
- package/dist/src/network/index.d.ts +6 -0
- package/dist/src/network/index.d.ts.map +1 -0
- package/dist/src/network/index.js +6 -0
- package/dist/src/network/index.js.map +1 -0
- package/dist/src/network/repo-protocol.d.ts +19 -0
- package/dist/src/network/repo-protocol.d.ts.map +1 -0
- package/dist/src/network/repo-protocol.js +2 -0
- package/dist/src/network/repo-protocol.js.map +1 -0
- package/dist/src/network/struct.d.ts +115 -0
- package/dist/src/network/struct.d.ts.map +1 -0
- package/dist/src/network/struct.js +2 -0
- package/dist/src/network/struct.js.map +1 -0
- package/dist/src/transaction/actions-engine.d.ts +37 -0
- package/dist/src/transaction/actions-engine.d.ts.map +1 -0
- package/dist/src/transaction/actions-engine.js +67 -0
- package/dist/src/transaction/actions-engine.js.map +1 -0
- package/dist/src/transaction/context.d.ts +60 -0
- package/dist/src/transaction/context.d.ts.map +1 -0
- package/dist/src/transaction/context.js +91 -0
- package/dist/src/transaction/context.js.map +1 -0
- package/dist/src/transaction/coordinator.d.ts +118 -0
- package/dist/src/transaction/coordinator.d.ts.map +1 -0
- package/dist/src/transaction/coordinator.js +417 -0
- package/dist/src/transaction/coordinator.js.map +1 -0
- package/dist/src/transaction/index.d.ts +10 -0
- package/dist/src/transaction/index.d.ts.map +1 -0
- package/dist/src/transaction/index.js +7 -0
- package/dist/src/transaction/index.js.map +1 -0
- package/dist/src/transaction/session.d.ts +80 -0
- package/dist/src/transaction/session.d.ts.map +1 -0
- package/dist/src/transaction/session.js +161 -0
- package/dist/src/transaction/session.js.map +1 -0
- package/dist/src/transaction/transaction.d.ts +156 -0
- package/dist/src/transaction/transaction.d.ts.map +1 -0
- package/dist/src/transaction/transaction.js +31 -0
- package/dist/src/transaction/transaction.js.map +1 -0
- package/dist/src/transaction/validator.d.ts +46 -0
- package/dist/src/transaction/validator.d.ts.map +1 -0
- package/dist/src/transaction/validator.js +97 -0
- package/dist/src/transaction/validator.js.map +1 -0
- package/dist/src/transactor/index.d.ts +4 -0
- package/dist/src/transactor/index.d.ts.map +1 -0
- package/dist/src/transactor/index.js +4 -0
- package/dist/src/transactor/index.js.map +1 -0
- package/dist/src/transactor/network-transactor.d.ts +36 -0
- package/dist/src/transactor/network-transactor.d.ts.map +1 -0
- package/dist/src/transactor/network-transactor.js +297 -0
- package/dist/src/transactor/network-transactor.js.map +1 -0
- package/dist/src/transactor/transactor-source.d.ts +24 -0
- package/dist/src/transactor/transactor-source.d.ts.map +1 -0
- package/dist/src/transactor/transactor-source.js +62 -0
- package/dist/src/transactor/transactor-source.js.map +1 -0
- package/dist/src/transactor/transactor.d.ts +38 -0
- package/dist/src/transactor/transactor.d.ts.map +1 -0
- package/dist/src/transactor/transactor.js +2 -0
- package/dist/src/transactor/transactor.js.map +1 -0
- package/dist/src/transform/atomic.d.ts +8 -0
- package/dist/src/transform/atomic.d.ts.map +1 -0
- package/dist/src/transform/atomic.js +14 -0
- package/dist/src/transform/atomic.js.map +1 -0
- package/dist/src/transform/cache-source.d.ts +13 -0
- package/dist/src/transform/cache-source.d.ts.map +1 -0
- package/dist/src/transform/cache-source.js +52 -0
- package/dist/src/transform/cache-source.js.map +1 -0
- package/dist/src/transform/helpers.d.ts +25 -0
- package/dist/src/transform/helpers.d.ts.map +1 -0
- package/dist/src/transform/helpers.js +105 -0
- package/dist/src/transform/helpers.js.map +1 -0
- package/dist/src/transform/index.d.ts +6 -0
- package/dist/src/transform/index.d.ts.map +1 -0
- package/dist/src/transform/index.js +6 -0
- package/dist/src/transform/index.js.map +1 -0
- package/dist/src/transform/struct.d.ts +19 -0
- package/dist/src/transform/struct.d.ts.map +1 -0
- package/dist/src/transform/struct.js +2 -0
- package/dist/src/transform/struct.js.map +1 -0
- package/dist/src/transform/tracker.d.ts +22 -0
- package/dist/src/transform/tracker.d.ts.map +1 -0
- package/dist/src/transform/tracker.js +64 -0
- package/dist/src/transform/tracker.js.map +1 -0
- package/dist/src/utility/actor.d.ts +11 -0
- package/dist/src/utility/actor.d.ts.map +1 -0
- package/dist/src/utility/actor.js +39 -0
- package/dist/src/utility/actor.js.map +1 -0
- package/dist/src/utility/batch-coordinator.d.ts +56 -0
- package/dist/src/utility/batch-coordinator.d.ts.map +1 -0
- package/dist/src/utility/batch-coordinator.js +127 -0
- package/dist/src/utility/batch-coordinator.js.map +1 -0
- package/dist/src/utility/block-id-to-bytes.d.ts +3 -0
- package/dist/src/utility/block-id-to-bytes.d.ts.map +1 -0
- package/dist/src/utility/block-id-to-bytes.js +7 -0
- package/dist/src/utility/block-id-to-bytes.js.map +1 -0
- package/dist/src/utility/ensured.d.ts +3 -0
- package/dist/src/utility/ensured.d.ts.map +1 -0
- package/dist/src/utility/ensured.js +24 -0
- package/dist/src/utility/ensured.js.map +1 -0
- package/dist/src/utility/groupby.d.ts +8 -0
- package/dist/src/utility/groupby.d.ts.map +1 -0
- package/dist/src/utility/groupby.js +15 -0
- package/dist/src/utility/groupby.js.map +1 -0
- package/dist/src/utility/is-record-empty.d.ts +3 -0
- package/dist/src/utility/is-record-empty.d.ts.map +1 -0
- package/dist/src/utility/is-record-empty.js +7 -0
- package/dist/src/utility/is-record-empty.js.map +1 -0
- package/dist/src/utility/latches.d.ts +11 -0
- package/dist/src/utility/latches.d.ts.map +1 -0
- package/dist/src/utility/latches.js +36 -0
- package/dist/src/utility/latches.js.map +1 -0
- package/dist/src/utility/nameof.d.ts +3 -0
- package/dist/src/utility/nameof.d.ts.map +1 -0
- package/dist/src/utility/nameof.js +5 -0
- package/dist/src/utility/nameof.js.map +1 -0
- package/dist/src/utility/pending.d.ts +13 -0
- package/dist/src/utility/pending.d.ts.map +1 -0
- package/dist/src/utility/pending.js +37 -0
- package/dist/src/utility/pending.js.map +1 -0
- package/package.json +56 -0
- package/src/blocks/block-store.ts +13 -0
- package/src/blocks/block-types.ts +11 -0
- package/src/blocks/helpers.ts +13 -0
- package/src/blocks/index.ts +5 -0
- package/src/blocks/structs.ts +17 -0
- package/src/btree/btree.ts +804 -0
- package/src/btree/independent-trunk.ts +54 -0
- package/src/btree/index.ts +5 -0
- package/src/btree/key-range.ts +15 -0
- package/src/btree/keyset.ts +6 -0
- package/src/btree/nodes.ts +25 -0
- package/src/btree/path.ts +37 -0
- package/src/btree/tree-block.ts +11 -0
- package/src/btree/trunk.ts +14 -0
- package/src/chain/chain-nodes.ts +24 -0
- package/src/chain/chain.ts +324 -0
- package/src/chain/index.ts +2 -0
- package/src/cluster/i-cluster.ts +6 -0
- package/src/cluster/index.ts +2 -0
- package/src/cluster/structs.ts +46 -0
- package/src/collection/action.ts +31 -0
- package/src/collection/collection.ts +200 -0
- package/src/collection/index.ts +3 -0
- package/src/collection/struct.ts +20 -0
- package/src/collections/diary/diary.ts +43 -0
- package/src/collections/diary/index.ts +2 -0
- package/src/collections/diary/struct.ts +3 -0
- package/src/collections/index.ts +2 -0
- package/src/collections/tree/collection-trunk.ts +25 -0
- package/src/collections/tree/index.ts +2 -0
- package/src/collections/tree/readme.md +19 -0
- package/src/collections/tree/struct.ts +18 -0
- package/src/collections/tree/tree.ts +124 -0
- package/src/index.ts +17 -0
- package/src/log/index.ts +2 -0
- package/src/log/log.ts +155 -0
- package/src/log/struct.ts +40 -0
- package/src/network/i-key-network.ts +24 -0
- package/src/network/i-peer-network.ts +8 -0
- package/src/network/i-repo.ts +19 -0
- package/src/network/index.ts +5 -0
- package/src/network/repo-protocol.ts +12 -0
- package/src/network/struct.ts +137 -0
- package/src/transaction/actions-engine.ts +83 -0
- package/src/transaction/context.ts +103 -0
- package/src/transaction/coordinator.ts +583 -0
- package/src/transaction/index.ts +30 -0
- package/src/transaction/session.ts +182 -0
- package/src/transaction/transaction.ts +205 -0
- package/src/transaction/validator.ts +150 -0
- package/src/transactor/index.ts +4 -0
- package/src/transactor/network-transactor.ts +435 -0
- package/src/transactor/transactor-source.ts +65 -0
- package/src/transactor/transactor.ts +44 -0
- package/src/transform/atomic.ts +16 -0
- package/src/transform/cache-source.ts +57 -0
- package/src/transform/helpers.ts +117 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/struct.ts +22 -0
- package/src/transform/tracker.ts +70 -0
- package/src/utility/actor.ts +62 -0
- package/src/utility/batch-coordinator.ts +174 -0
- package/src/utility/block-id-to-bytes.ts +8 -0
- package/src/utility/ensured.ts +32 -0
- package/src/utility/groupby.ts +18 -0
- package/src/utility/is-record-empty.ts +5 -0
- package/src/utility/latches.ts +42 -0
- package/src/utility/nameof.ts +7 -0
- package/src/utility/pending.ts +41 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { TransactionContext } from "./context.js";
|
|
2
|
+
import { createActionsStatements } from "./actions-engine.js";
|
|
3
|
+
import { createTransactionStamp, createTransactionId } from "./transaction.js";
|
|
4
|
+
import { Log, blockIdsForTransforms, transformsFromTransform } from "../index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Coordinates multi-collection transactions.
|
|
7
|
+
*
|
|
8
|
+
* This is the ONLY interface for all mutations (single or multi-collection).
|
|
9
|
+
*
|
|
10
|
+
* Responsibilities:
|
|
11
|
+
* - Manage collections (create as needed)
|
|
12
|
+
* - Apply actions to collections (run handlers, write to logs)
|
|
13
|
+
* - Commit transactions by running consensus phases (GATHER, PEND, COMMIT)
|
|
14
|
+
*/
|
|
15
|
+
export class TransactionCoordinator {
|
|
16
|
+
transactor;
|
|
17
|
+
collections;
|
|
18
|
+
constructor(transactor, collections) {
|
|
19
|
+
this.transactor = transactor;
|
|
20
|
+
this.collections = collections;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Apply actions to collections (called by engines during statement execution).
|
|
24
|
+
*
|
|
25
|
+
* This is the core method that engines call to apply actions to collections.
|
|
26
|
+
* Actions are tagged with the stamp ID and executed immediately through collections
|
|
27
|
+
* to update the local snapshot.
|
|
28
|
+
*
|
|
29
|
+
* @param actions - The actions to apply (per collection)
|
|
30
|
+
* @param stampId - The transaction stamp ID to tag actions with
|
|
31
|
+
*/
|
|
32
|
+
async applyActions(actions, stampId) {
|
|
33
|
+
for (const { collectionId, actions: collectionActions } of actions) {
|
|
34
|
+
// Get collection
|
|
35
|
+
const collection = this.collections.get(collectionId);
|
|
36
|
+
if (!collection) {
|
|
37
|
+
throw new Error(`Collection not found: ${collectionId}`);
|
|
38
|
+
}
|
|
39
|
+
// Apply each action (tagged with stampId)
|
|
40
|
+
for (const action of collectionActions) {
|
|
41
|
+
const taggedAction = { ...action, transaction: stampId };
|
|
42
|
+
await collection.act(taggedAction);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Commit a transaction (actions already applied, orchestrate PEND/COMMIT).
|
|
48
|
+
*
|
|
49
|
+
* This is called by TransactionSession.commit() after all statements have been executed.
|
|
50
|
+
* Actions have already been applied to collections via applyActions(), so this method
|
|
51
|
+
* just orchestrates the distributed consensus.
|
|
52
|
+
*
|
|
53
|
+
* @param transaction - The transaction to commit
|
|
54
|
+
*/
|
|
55
|
+
async commit(transaction) {
|
|
56
|
+
// Collect transforms and determine critical blocks for each affected collection
|
|
57
|
+
const collectionData = Array.from(this.collections.entries())
|
|
58
|
+
.map(([collectionId, collection]) => ({
|
|
59
|
+
collectionId,
|
|
60
|
+
collection,
|
|
61
|
+
transforms: collection.tracker.transforms
|
|
62
|
+
}))
|
|
63
|
+
.filter(({ transforms }) => Object.keys(transforms.inserts).length +
|
|
64
|
+
Object.keys(transforms.updates).length +
|
|
65
|
+
transforms.deletes.length > 0);
|
|
66
|
+
if (collectionData.length === 0) {
|
|
67
|
+
return; // Nothing to commit
|
|
68
|
+
}
|
|
69
|
+
// Get critical block IDs (log tail) for each affected collection
|
|
70
|
+
// The critical block is the current log tail that must participate in consensus
|
|
71
|
+
const collectionTransforms = new Map();
|
|
72
|
+
const criticalBlocks = new Map();
|
|
73
|
+
for (const { collectionId, collection, transforms } of collectionData) {
|
|
74
|
+
collectionTransforms.set(collectionId, transforms);
|
|
75
|
+
// Get the current log tail block ID (critical block)
|
|
76
|
+
const log = await Log.open(collection.tracker, collectionId);
|
|
77
|
+
if (!log) {
|
|
78
|
+
throw new Error(`Log not found for collection ${collectionId}`);
|
|
79
|
+
}
|
|
80
|
+
const tailPath = await log.chain.getTail();
|
|
81
|
+
if (tailPath) {
|
|
82
|
+
criticalBlocks.set(collectionId, tailPath.block.header.id);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Compute hash of ALL operations across ALL collections
|
|
86
|
+
// This hash is used for validation - validators re-execute the transaction
|
|
87
|
+
// and compare their computed operations hash with this one
|
|
88
|
+
const allOperations = collectionData.flatMap(({ collectionId, transforms }) => [
|
|
89
|
+
...Object.entries(transforms.inserts).map(([blockId, block]) => ({ type: 'insert', collectionId, blockId, block })),
|
|
90
|
+
...Object.entries(transforms.updates).map(([blockId, operations]) => ({ type: 'update', collectionId, blockId, operations })),
|
|
91
|
+
...transforms.deletes.map(blockId => ({ type: 'delete', collectionId, blockId }))
|
|
92
|
+
]);
|
|
93
|
+
const operationsHash = this.hashOperations(allOperations);
|
|
94
|
+
// Execute consensus phases (GATHER, PEND, COMMIT)
|
|
95
|
+
const coordResult = await this.coordinateTransaction(transaction, operationsHash, collectionTransforms, criticalBlocks);
|
|
96
|
+
if (!coordResult.success) {
|
|
97
|
+
throw new Error(`Transaction commit failed: ${coordResult.error}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Rollback a transaction (undo applied actions).
|
|
102
|
+
*
|
|
103
|
+
* This is called by TransactionSession.rollback() to undo all actions
|
|
104
|
+
* that were applied via applyActions().
|
|
105
|
+
*
|
|
106
|
+
* @param _stampId - The transaction stamp ID to rollback (currently unused - we clear all trackers)
|
|
107
|
+
*/
|
|
108
|
+
async rollback(_stampId) {
|
|
109
|
+
// Clear trackers for all collections
|
|
110
|
+
// This discards all pending changes that were applied via applyActions()
|
|
111
|
+
// TODO: In the future, we may want to track which collections were affected by
|
|
112
|
+
// a specific stampId and only reset those trackers
|
|
113
|
+
for (const collection of this.collections.values()) {
|
|
114
|
+
// Reset the tracker to discard all pending transforms
|
|
115
|
+
collection.tracker.reset();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Compute hash of all operations in a transaction.
|
|
120
|
+
* This hash is used for validation - validators re-execute the transaction
|
|
121
|
+
* and compare their computed operations hash with this one.
|
|
122
|
+
*/
|
|
123
|
+
hashOperations(operations) {
|
|
124
|
+
const operationsData = JSON.stringify(operations);
|
|
125
|
+
const hash = Array.from(operationsData).reduce((acc, char) => {
|
|
126
|
+
const charCode = char.charCodeAt(0);
|
|
127
|
+
return ((acc << 5) - acc + charCode) & acc;
|
|
128
|
+
}, 0);
|
|
129
|
+
return `ops:${Math.abs(hash).toString(36)}`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Commit a transaction context.
|
|
133
|
+
*
|
|
134
|
+
* @deprecated Use TransactionSession instead of TransactionContext
|
|
135
|
+
* This is called by TransactionContext.commit().
|
|
136
|
+
*
|
|
137
|
+
* @param context - The transaction context to commit
|
|
138
|
+
* @returns Execution result with actions and results
|
|
139
|
+
*/
|
|
140
|
+
async commitTransaction(context) {
|
|
141
|
+
const collectionActions = Array.from(context.getCollectionActions().entries()).map(([collectionId, actions]) => ({ collectionId, actions }));
|
|
142
|
+
if (collectionActions.length === 0) {
|
|
143
|
+
return { success: true }; // Nothing to commit
|
|
144
|
+
}
|
|
145
|
+
// Create transaction statements
|
|
146
|
+
const statements = createActionsStatements(collectionActions);
|
|
147
|
+
const reads = context.getReads();
|
|
148
|
+
// Create stamp from context
|
|
149
|
+
const stamp = createTransactionStamp('local', // TODO: Get from context or coordinator
|
|
150
|
+
Date.now(), '', // TODO: Get from engine
|
|
151
|
+
context.engine);
|
|
152
|
+
const transaction = {
|
|
153
|
+
stamp,
|
|
154
|
+
statements,
|
|
155
|
+
reads,
|
|
156
|
+
id: createTransactionId(stamp.id, statements, reads)
|
|
157
|
+
};
|
|
158
|
+
// Create ActionsEngine for execution (TransactionContext only supports actions)
|
|
159
|
+
const { ActionsEngine } = await import('./actions-engine.js');
|
|
160
|
+
const engine = new ActionsEngine(this);
|
|
161
|
+
// Execute through standard path
|
|
162
|
+
return await this.execute(transaction, engine);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Execute a fully-formed transaction.
|
|
166
|
+
*
|
|
167
|
+
* This can be called directly with a complete transaction (e.g., from Quereus),
|
|
168
|
+
* or indirectly via commitTransaction().
|
|
169
|
+
*
|
|
170
|
+
* @param transaction - The transaction to execute
|
|
171
|
+
* @param engine - The engine to use for executing the transaction
|
|
172
|
+
* @returns Execution result with actions and results
|
|
173
|
+
*/
|
|
174
|
+
async execute(transaction, engine) {
|
|
175
|
+
// 1. Validate engine matches transaction
|
|
176
|
+
// Note: We don't enforce this strictly since the engine is passed in explicitly
|
|
177
|
+
// The caller is responsible for ensuring the correct engine is used
|
|
178
|
+
const result = await engine.execute(transaction);
|
|
179
|
+
if (!result.success) {
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
if (!result.actions || result.actions.length === 0) {
|
|
183
|
+
return { success: true }; // Nothing to do
|
|
184
|
+
}
|
|
185
|
+
// 2. Apply actions to collections and collect transforms
|
|
186
|
+
const collectionTransforms = new Map();
|
|
187
|
+
const criticalBlocks = new Map();
|
|
188
|
+
const actionResults = new Map();
|
|
189
|
+
const allCollectionIds = result.actions.map(ca => ca.collectionId);
|
|
190
|
+
for (const collectionActions of result.actions) {
|
|
191
|
+
const applyResult = await this.applyActionsToCollection(collectionActions, transaction, allCollectionIds);
|
|
192
|
+
if (!applyResult.success) {
|
|
193
|
+
return { success: false, error: applyResult.error };
|
|
194
|
+
}
|
|
195
|
+
collectionTransforms.set(collectionActions.collectionId, applyResult.transforms);
|
|
196
|
+
criticalBlocks.set(collectionActions.collectionId, applyResult.logTailBlockId);
|
|
197
|
+
actionResults.set(collectionActions.collectionId, applyResult.results);
|
|
198
|
+
}
|
|
199
|
+
// 3. Compute operations hash for validation
|
|
200
|
+
const allOperations = Array.from(collectionTransforms.entries()).flatMap(([collectionId, transforms]) => [
|
|
201
|
+
...Object.entries(transforms.inserts).map(([blockId, block]) => ({ type: 'insert', collectionId, blockId, block })),
|
|
202
|
+
...Object.entries(transforms.updates).map(([blockId, operations]) => ({ type: 'update', collectionId, blockId, operations })),
|
|
203
|
+
...transforms.deletes.map(blockId => ({ type: 'delete', collectionId, blockId }))
|
|
204
|
+
]);
|
|
205
|
+
const operationsHash = this.hashOperations(allOperations);
|
|
206
|
+
// 4. Coordinate (GATHER if multi-collection)
|
|
207
|
+
const coordResult = await this.coordinateTransaction(transaction, operationsHash, collectionTransforms, criticalBlocks);
|
|
208
|
+
if (!coordResult.success) {
|
|
209
|
+
return coordResult;
|
|
210
|
+
}
|
|
211
|
+
// 4. Return results from actions
|
|
212
|
+
return {
|
|
213
|
+
success: true,
|
|
214
|
+
actions: result.actions,
|
|
215
|
+
results: actionResults
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Apply actions to a collection.
|
|
220
|
+
*
|
|
221
|
+
* This runs the action handlers, writes to the log, and collects transforms.
|
|
222
|
+
*/
|
|
223
|
+
async applyActionsToCollection(collectionActions, transaction, allCollectionIds) {
|
|
224
|
+
const collection = this.collections.get(collectionActions.collectionId);
|
|
225
|
+
if (!collection) {
|
|
226
|
+
return {
|
|
227
|
+
success: false,
|
|
228
|
+
error: `Collection not found: ${collectionActions.collectionId}`
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// At this point, actions have already been executed through collection.act()
|
|
232
|
+
// when they were added to the TransactionContext. The collection's tracker
|
|
233
|
+
// already has the transforms, and the actions are in the pending buffer.
|
|
234
|
+
// Get transforms from the collection's tracker
|
|
235
|
+
const transforms = collection.tracker.transforms;
|
|
236
|
+
// Write actions to the collection's log to get the log tail block ID
|
|
237
|
+
const log = await Log.open(collection.tracker, collectionActions.collectionId);
|
|
238
|
+
if (!log) {
|
|
239
|
+
return {
|
|
240
|
+
success: false,
|
|
241
|
+
error: `Log not found for collection ${collectionActions.collectionId}`
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
// Generate action ID from transaction ID
|
|
245
|
+
const actionId = transaction.id;
|
|
246
|
+
const newRev = (collection['source'].actionContext?.rev ?? 0) + 1;
|
|
247
|
+
// Add actions to log (this updates the tracker with log block changes)
|
|
248
|
+
const addResult = await log.addActions(collectionActions.actions, actionId, newRev, () => blockIdsForTransforms(transforms), allCollectionIds);
|
|
249
|
+
// Return the transforms and log tail block ID
|
|
250
|
+
return {
|
|
251
|
+
success: true,
|
|
252
|
+
transforms,
|
|
253
|
+
logTailBlockId: addResult.tailPath.block.header.id,
|
|
254
|
+
results: [] // TODO: Collect results from action handlers when we support read operations
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Coordinate a transaction across multiple collections.
|
|
259
|
+
*
|
|
260
|
+
* @param transaction - The transaction to coordinate
|
|
261
|
+
* @param operationsHash - Hash of all operations for validation
|
|
262
|
+
* @param collectionTransforms - Map of collectionId to its transforms
|
|
263
|
+
* @param criticalBlocks - Map of collectionId to its log tail blockId
|
|
264
|
+
*/
|
|
265
|
+
async coordinateTransaction(transaction, operationsHash, collectionTransforms, criticalBlocks) {
|
|
266
|
+
// 1. GATHER phase: collect critical cluster nominees (skip if single collection)
|
|
267
|
+
const criticalBlockIds = Array.from(criticalBlocks.values());
|
|
268
|
+
const superclusterNominees = await this.gatherPhase(criticalBlockIds);
|
|
269
|
+
// 2. PEND phase: distribute to all block clusters
|
|
270
|
+
const pendResult = await this.pendPhase(transaction, operationsHash, collectionTransforms, superclusterNominees);
|
|
271
|
+
if (!pendResult.success) {
|
|
272
|
+
return pendResult;
|
|
273
|
+
}
|
|
274
|
+
// 3. COMMIT phase: commit to all critical blocks
|
|
275
|
+
const commitResult = await this.commitPhase(transaction.id, criticalBlockIds, pendResult.pendedBlockIds);
|
|
276
|
+
if (!commitResult.success) {
|
|
277
|
+
// Cancel pending actions on failure
|
|
278
|
+
await this.cancelPhase(transaction.id, collectionTransforms);
|
|
279
|
+
return commitResult;
|
|
280
|
+
}
|
|
281
|
+
// 4. PROPAGATE and CHECKPOINT phases are handled by clusters automatically
|
|
282
|
+
// (as per user's note: "managed by each cluster, the client doesn't have to worry about them")
|
|
283
|
+
return { success: true };
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* GATHER phase: Collect nominees from critical clusters.
|
|
287
|
+
*
|
|
288
|
+
* Skip if only one collection affected (single-collection consensus).
|
|
289
|
+
*
|
|
290
|
+
* @param criticalBlockIds - Block IDs of all log tails
|
|
291
|
+
* @returns Set of peer IDs to use for consensus, or null for single-collection
|
|
292
|
+
*/
|
|
293
|
+
async gatherPhase(criticalBlockIds) {
|
|
294
|
+
// Skip GATHER if only one collection affected
|
|
295
|
+
if (criticalBlockIds.length === 1) {
|
|
296
|
+
return null; // Use normal single-collection consensus
|
|
297
|
+
}
|
|
298
|
+
// Check if transactor supports cluster queries (optional method)
|
|
299
|
+
if (!this.transactor.queryClusterNominees) {
|
|
300
|
+
// Transactor doesn't support cluster queries - proceed without supercluster
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
// Query each critical cluster for their nominees and merge into supercluster
|
|
304
|
+
const nomineePromises = criticalBlockIds.map(blockId => this.transactor.queryClusterNominees(blockId));
|
|
305
|
+
const results = await Promise.all(nomineePromises);
|
|
306
|
+
// Merge all nominees into a single set
|
|
307
|
+
const supercluster = results.reduce((acc, result) => {
|
|
308
|
+
result.nominees.forEach(nominee => acc.add(nominee));
|
|
309
|
+
return acc;
|
|
310
|
+
}, new Set());
|
|
311
|
+
return supercluster;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* PEND phase: Distribute transaction to all affected block clusters.
|
|
315
|
+
*
|
|
316
|
+
* @param transaction - The full transaction for replay/validation
|
|
317
|
+
* @param operationsHash - Hash of all operations for validation
|
|
318
|
+
* @param collectionTransforms - Map of collectionId to its transforms
|
|
319
|
+
* @param superclusterNominees - Nominees for multi-collection consensus (null for single-collection)
|
|
320
|
+
*/
|
|
321
|
+
async pendPhase(transaction, operationsHash, collectionTransforms, superclusterNominees) {
|
|
322
|
+
if (collectionTransforms.size === 0) {
|
|
323
|
+
return { success: false, error: 'No transforms to pend' };
|
|
324
|
+
}
|
|
325
|
+
const pendedBlockIds = new Map();
|
|
326
|
+
const actionId = transaction.id;
|
|
327
|
+
const nominees = superclusterNominees ? Array.from(superclusterNominees) : undefined;
|
|
328
|
+
// Pend each collection's transforms
|
|
329
|
+
for (const [collectionId, transforms] of collectionTransforms.entries()) {
|
|
330
|
+
const collection = this.collections.get(collectionId);
|
|
331
|
+
if (!collection) {
|
|
332
|
+
return { success: false, error: `Collection not found: ${collectionId}` };
|
|
333
|
+
}
|
|
334
|
+
// Get revision from the collection's source
|
|
335
|
+
const rev = (collection['source'].actionContext?.rev ?? 0) + 1;
|
|
336
|
+
// Create pend request with transaction and operations hash for validation
|
|
337
|
+
const pendRequest = {
|
|
338
|
+
actionId,
|
|
339
|
+
rev,
|
|
340
|
+
transforms,
|
|
341
|
+
policy: 'r', // Return policy: fail but return pending actions
|
|
342
|
+
transaction,
|
|
343
|
+
operationsHash,
|
|
344
|
+
superclusterNominees: nominees
|
|
345
|
+
};
|
|
346
|
+
// Pend the transaction
|
|
347
|
+
const pendResult = await this.transactor.pend(pendRequest);
|
|
348
|
+
if (!pendResult.success) {
|
|
349
|
+
return {
|
|
350
|
+
success: false,
|
|
351
|
+
error: `Pend failed for collection ${collectionId}: ${pendResult.reason}`
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
// Store the pended block IDs for commit phase
|
|
355
|
+
pendedBlockIds.set(collectionId, pendResult.blockIds);
|
|
356
|
+
}
|
|
357
|
+
return { success: true, pendedBlockIds };
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* COMMIT phase: Commit to all critical blocks.
|
|
361
|
+
*/
|
|
362
|
+
async commitPhase(actionId, criticalBlockIds, pendedBlockIds) {
|
|
363
|
+
// Commit each collection's transaction
|
|
364
|
+
for (const [collectionId, blockIds] of pendedBlockIds.entries()) {
|
|
365
|
+
const collection = this.collections.get(collectionId);
|
|
366
|
+
if (!collection) {
|
|
367
|
+
return { success: false, error: `Collection not found: ${collectionId}` };
|
|
368
|
+
}
|
|
369
|
+
// Get revision
|
|
370
|
+
const rev = (collection['source'].actionContext?.rev ?? 0) + 1;
|
|
371
|
+
// Find the critical block (log tail) for this collection
|
|
372
|
+
const logTailBlockId = criticalBlockIds.find(blockId => blockIds.includes(blockId));
|
|
373
|
+
if (!logTailBlockId) {
|
|
374
|
+
return {
|
|
375
|
+
success: false,
|
|
376
|
+
error: `Log tail block not found for collection ${collectionId}`
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
// Create commit request
|
|
380
|
+
const commitRequest = {
|
|
381
|
+
actionId,
|
|
382
|
+
blockIds,
|
|
383
|
+
tailId: logTailBlockId,
|
|
384
|
+
rev
|
|
385
|
+
};
|
|
386
|
+
// Commit the transaction
|
|
387
|
+
const commitResult = await this.transactor.commit(commitRequest);
|
|
388
|
+
if (!commitResult.success) {
|
|
389
|
+
return {
|
|
390
|
+
success: false,
|
|
391
|
+
error: `Commit failed for collection ${collectionId}`
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return { success: true };
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* CANCEL phase: Cancel pending actions on all affected blocks.
|
|
399
|
+
*/
|
|
400
|
+
async cancelPhase(actionId, collectionTransforms) {
|
|
401
|
+
// Cancel each collection's pending transaction
|
|
402
|
+
for (const [collectionId, transforms] of collectionTransforms.entries()) {
|
|
403
|
+
const collection = this.collections.get(collectionId);
|
|
404
|
+
if (!collection) {
|
|
405
|
+
continue; // Skip if collection not found
|
|
406
|
+
}
|
|
407
|
+
// Get the block IDs from transforms
|
|
408
|
+
const blockIds = blockIdsForTransforms(transforms);
|
|
409
|
+
// Cancel the transaction
|
|
410
|
+
await this.transactor.cancel({
|
|
411
|
+
actionId,
|
|
412
|
+
blockIds
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
//# sourceMappingURL=coordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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,CAAC,CAAC;YACjE,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;gBAC3B,OAAO;oBACN,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,gCAAgC,YAAY,EAAE;iBACrD,CAAC;YACH,CAAC;QACF,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,WAAW,CACxB,QAAkB,EAClB,oBAAmD;QAEnD,+CAA+C;QAC/C,KAAK,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,oBAAoB,CAAC,OAAO,EAAE,EAAE,CAAC;YACzE,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACtD,IAAI,CAAC,UAAU,EAAE,CAAC;gBACjB,SAAS,CAAC,+BAA+B;YAC1C,CAAC;YAED,oCAAoC;YACpC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;YAEnD,yBAAyB;YACzB,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;gBAC5B,QAAQ;gBACR,QAAQ;aACR,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CAED"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { Transaction, TransactionStamp, ReadDependency, TransactionRef, ITransactionEngine, ExecutionResult, CollectionActions, ValidationResult, ITransactionValidator } from './transaction.js';
|
|
2
|
+
export { createTransactionStamp, createTransactionId } from './transaction.js';
|
|
3
|
+
export { ActionsEngine, ACTIONS_ENGINE_ID, createActionsStatements } from './actions-engine.js';
|
|
4
|
+
export type { ActionsStatement } from './actions-engine.js';
|
|
5
|
+
export { TransactionCoordinator } from './coordinator.js';
|
|
6
|
+
export { TransactionContext } from './context.js';
|
|
7
|
+
export { TransactionSession } from './session.js';
|
|
8
|
+
export { TransactionValidator } from './validator.js';
|
|
9
|
+
export type { EngineRegistration, ValidationCoordinatorFactory } from './validator.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transaction/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,sBAAsB,EACtB,mBAAmB,EACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,uBAAuB,EACvB,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createTransactionStamp, createTransactionId } from './transaction.js';
|
|
2
|
+
export { ActionsEngine, ACTIONS_ENGINE_ID, createActionsStatements } from './actions-engine.js';
|
|
3
|
+
export { TransactionCoordinator } from './coordinator.js';
|
|
4
|
+
export { TransactionContext } from './context.js';
|
|
5
|
+
export { TransactionSession } from './session.js';
|
|
6
|
+
export { TransactionValidator } from './validator.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transaction/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACN,sBAAsB,EACtB,mBAAmB,EACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,uBAAuB,EACvB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { TransactionCoordinator } from "./coordinator.js";
|
|
2
|
+
import type { ExecutionResult, ITransactionEngine, TransactionStamp, CollectionActions } from "./transaction.js";
|
|
3
|
+
/**
|
|
4
|
+
* TransactionSession manages incremental transaction building.
|
|
5
|
+
*
|
|
6
|
+
* This is the high-level API for building transactions incrementally:
|
|
7
|
+
* - Stamp is created at BEGIN (stable throughout transaction)
|
|
8
|
+
* - Execute statements one at a time
|
|
9
|
+
* - Engine translates statements to actions (if not already provided)
|
|
10
|
+
* - Actions are immediately applied to collections via coordinator.applyActions()
|
|
11
|
+
* - On commit, all statements are compiled into a complete Transaction
|
|
12
|
+
* - The Transaction is then committed through coordinator.commit() for PEND/COMMIT orchestration
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const session = new TransactionSession(coordinator, engine);
|
|
16
|
+
* await session.execute('INSERT INTO users (id, name) VALUES (?, ?)', [1, 'Alice']);
|
|
17
|
+
* await session.execute('SELECT * FROM orders WHERE user_id = ?', [1]);
|
|
18
|
+
* const result = await session.commit();
|
|
19
|
+
*
|
|
20
|
+
* For validation/replay, use engine.execute() directly with a complete Transaction.
|
|
21
|
+
*/
|
|
22
|
+
export declare class TransactionSession {
|
|
23
|
+
private readonly coordinator;
|
|
24
|
+
private readonly engine;
|
|
25
|
+
private readonly statements;
|
|
26
|
+
private readonly stamp;
|
|
27
|
+
private committed;
|
|
28
|
+
private rolledBack;
|
|
29
|
+
constructor(coordinator: TransactionCoordinator, engine: ITransactionEngine, peerId?: string, // TODO: Get from coordinator or config
|
|
30
|
+
schemaHash?: string);
|
|
31
|
+
/**
|
|
32
|
+
* Execute a statement.
|
|
33
|
+
*
|
|
34
|
+
* If actions are provided, they are applied directly.
|
|
35
|
+
* Otherwise, the engine translates the statement to actions.
|
|
36
|
+
*
|
|
37
|
+
* @param statement - The statement to execute (engine-specific, e.g., SQL statement)
|
|
38
|
+
* @param actions - Optional pre-computed actions (for Quereus module case)
|
|
39
|
+
* @returns Execution result with any returned values
|
|
40
|
+
*/
|
|
41
|
+
execute(statement: string, actions?: CollectionActions[]): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
error?: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Commit the transaction.
|
|
47
|
+
*
|
|
48
|
+
* Compiles all statements into a complete Transaction and commits through coordinator.
|
|
49
|
+
*/
|
|
50
|
+
commit(): Promise<ExecutionResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Rollback the transaction (discard local state).
|
|
53
|
+
*
|
|
54
|
+
* Note: Actions have already been applied to collections' trackers.
|
|
55
|
+
* Rollback just prevents commit and clears session state.
|
|
56
|
+
* Collections will discard tracker state when they sync or update.
|
|
57
|
+
*/
|
|
58
|
+
rollback(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Get the transaction stamp ID (stable throughout transaction).
|
|
61
|
+
*/
|
|
62
|
+
getStampId(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Get the transaction stamp (full metadata).
|
|
65
|
+
*/
|
|
66
|
+
getStamp(): TransactionStamp;
|
|
67
|
+
/**
|
|
68
|
+
* Get the list of accumulated statements.
|
|
69
|
+
*/
|
|
70
|
+
getStatements(): readonly string[];
|
|
71
|
+
/**
|
|
72
|
+
* Check if the transaction has been committed.
|
|
73
|
+
*/
|
|
74
|
+
isCommitted(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Check if the transaction has been rolled back.
|
|
77
|
+
*/
|
|
78
|
+
isRolledBack(): boolean;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/transaction/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAe,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG9H;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAkB;IAO7B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;gBAGT,WAAW,EAAE,sBAAsB,EACnC,MAAM,EAAE,kBAAkB,EAC3C,MAAM,GAAE,MAAgB,EAAE,uCAAuC;IACjE,UAAU,GAAE,MAAW;IAWxB;;;;;;;;;OASG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IA2C9G;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC;IAuBxC;;;;;;OAMG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAc/B;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,QAAQ,IAAI,gBAAgB;IAI5B;;OAEG;IACH,aAAa,IAAI,SAAS,MAAM,EAAE;IAIlC;;OAEG;IACH,WAAW,IAAI,OA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