载入中...
搜索中...
未找到
EditorTransactionService.cpp
浏览该文件的文档.
2
3#include <utility>
4
5namespace eve::editor {
6namespace {
7
8TransactionState transactionState(eve::transaction::CoordinatorState state) noexcept {
9 switch (state) {
10 case eve::transaction::CoordinatorState::Committed: return TransactionState::Committed;
11 case eve::transaction::CoordinatorState::Compensated: return TransactionState::RolledBack;
14 case eve::transaction::CoordinatorState::PartiallyCommitted: return TransactionState::Failed;
15 case eve::transaction::CoordinatorState::RolledBack: return TransactionState::RolledBack;
16 }
17 return TransactionState::Failed;
18}
19
20TransactionReceipt projectRecord(const EditorTransactionRecord& record) {
21 TransactionReceipt result;
22 result.id = record.specification.id;
23 result.state = transactionState(record.coordinator.state);
24 if (record.authorityReceipt) {
25 result.beforeRevision = record.authorityReceipt->beforeRevision;
26 result.afterRevision = record.authorityReceipt->afterRevision;
27 result.affectedObjects = record.authorityReceipt->affectedObjects;
28 result.diagnostics = record.authorityReceipt->diagnostics;
29 result.authorityReceipt = record.authorityReceipt->authorityReceipt;
30 }
31 return result;
32}
33
34} // namespace
35
36Result<TransactionId> LocalTransactionBackend::project(eve::Result<TransactionId>&& result) {
37 // Result is eve::Result; no projection envelope exists at this boundary.
38 // Named rvalue-ref parameters are lvalues; move explicitly (not a local NRVO candidate).
39 return std::move(result);
40}
41
42Result<void> LocalTransactionBackend::project(eve::Result<void>&& result) {
43 return std::move(result);
44}
45
46Result<TransactionReceipt> LocalTransactionBackend::project(eve::Result<EditorTransactionRecord>&& result) {
47 if (!result.ok()) return Result<TransactionReceipt>::failure(result.status());
48 EditorTransactionRecord record = std::move(result).takeValue();
49 return eve::editing::applied<TransactionReceipt>(projectRecord(record));
50}
51
52Result<EditorDryRunReport> LocalTransactionBackend::project(eve::Result<EditorDryRunReport>&& result) {
53 return std::move(result);
54}
55
57 return project(consumer_.setAuthority(authority));
58}
59
61 if (specification.id.empty() || specification.target.empty())
62 return eve::editing::failed<TransactionId>(EditorStatus::Rejected,
63 RuleId("editor.transaction.invalid-specification"),
64 "Transaction id and target are required");
65 return project(consumer_.begin(std::move(specification)));
66}
67
71
73
75
76Result<void> LocalTransactionBackend::discard() { return project(consumer_.discard()); }
77
79
81
83
85
86} // namespace eve::editor
ActionParameterOperation operation
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
bool empty() const noexcept
True when no compatibility spelling has been assigned.
Definition Identity.h:374
Final validation and commit boundary for editor mutations.
eve::Result< TransactionId > begin(TransactionSpec specification)
Begins a transaction with an explicit stable editor identifier.
eve::Result< EditorTransactionRecord > undo()
Compensates the latest editor-owned commit and moves it to redo history.
eve::Result< void > append(std::unique_ptr< IEditCommand > command)
Appends a command without publishing its target mutation.
eve::Result< EditorTransactionRecord > retry(std::span< transaction::ITransactionParticipant * > additional={})
Retries a failed commit while retaining its pending work.
eve::Result< void > discard()
Explicitly discards the pending transaction and any preview.
eve::Result< EditorDryRunReport > dryRun() const
Runs structural and authority preflight without publishing state.
eve::Result< EditorTransactionRecord > commit()
Commits the active editor participant set through Coordinator.
eve::Result< void > setAuthority(IEditAuthority *authority)
Changes the borrowed authority when no transaction is active.
eve::Result< EditorTransactionRecord > redo()
Re-executes the latest compensated editor-owned transaction.
Result< TransactionReceipt > commit() override
Preflight and commit all active operations through the authority.
Result< TransactionId > begin(TransactionSpec specification) override
Begin a transaction with a stable id and base revision.
Result< TransactionReceipt > undo() override
Compensate the most recent committed transaction.
Result< void > discard() override
Discard the active, not-yet-committed operation list.
Result< void > rollback()
Compatibility spelling for discard.
Result< EditorDryRunReport > preview() override
Preflight the active operation list without mutating target state.
Result< void > setAuthority(IEditAuthority *authority)
Change the non-owning authority when no transaction is active.
Result< TransactionReceipt > redo() override
Reapply the most recently compensated transaction.
Result< void > append(DomainOperation operation) override
Append an operation to the active transaction without applying it.
Result< TransactionReceipt > retry() override
Retry the retained failed commit.
eve::editing::TransactionState TransactionState
eve::editing::RuleId RuleId
Definition EditorIds.h:32
eve::editing::TransactionReceipt TransactionReceipt
CoordinatorState
Terminal or in-flight outcome of coordinator-managed participants.
Definition Transaction.h:81
DomainOperation public API.
TransactionSpec public API.