Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
model_edit.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/line_edit.hpp>
6#include <portals/model_position.hpp>
7
8#include <functional>
9#include <string>
10
11namespace portals {
13class EditFieldKey {
14public:
15 EditFieldKey() = default;
16
20 static std::expected<EditFieldKey, TreeError> create(std::string_view value);
21
23 std::string_view name() const noexcept;
24
26 bool persistent() const noexcept;
27
29 bool operator==(const EditFieldKey &other) const noexcept;
30
34 static EditFieldKey local(std::uint64_t identity) noexcept;
35
36private:
37 std::shared_ptr<const std::string> name_;
38 std::uint64_t local_{};
39};
40
42struct EditTarget {
47 std::uint64_t baseVersion{};
48 std::uint64_t sequence{};
50
52 bool operator==(const EditTarget &other) const noexcept = default;
53};
54
68
73 std::uint64_t acceptedVersion{};
74 std::optional<TreeError> error;
75};
76
81bool editReceiptMatches(const EditTarget &target, const EditReceipt &receipt) noexcept;
82
85 bool writable{};
86 bool conditional{};
87 bool ordered{};
88 bool atomicFields{};
90};
91
95 std::size_t maxRetainedFields{128};
96 std::size_t maxRetainedBytes{
97 4 * 1024 *
98 1024};
99};
100
104template <class T> struct EditRecord {
105 std::shared_ptr<const T> value;
106 std::uint64_t version{};
107};
108
112template <class T> struct EditRequest {
114 std::shared_ptr<const T> value;
115};
116
124template <class T> class EditEndpoint {
125public:
126 virtual ~EditEndpoint() = default;
127
129 virtual EditCapabilities capabilities() const noexcept = 0;
130
134 virtual std::expected<EditRecord<T>, TreeError> read(ModelResource resource, RowId row) = 0;
135
143 virtual std::expected<EditReceipt, TreeError> submit(EditRequest<T> request) = 0;
144
149 virtual std::expected<std::size_t, TreeError> ownedBytes(const T &value) const = 0;
150};
151
154 std::vector<EditReceipt> fields;
155 bool atomic{};
156};
157} // namespace portals
Source capability adapter; calls must return promptly without UI I/O. External work is submitted thro...
Definition model_edit.hpp:124
virtual std::expected< EditRecord< T >, TreeError > read(ModelResource resource, RowId row)=0
virtual std::expected< EditReceipt, TreeError > submit(EditRequest< T > request)=0
virtual EditCapabilities capabilities() const noexcept=0
virtual std::expected< std::size_t, TreeError > ownedBytes(const T &value) const =0
Owning field identity; local shorthand is deliberately not persistent.
Definition model_edit.hpp:13
bool persistent() const noexcept
static std::expected< EditFieldKey, TreeError > create(std::string_view value)
std::string_view name() const noexcept
static EditFieldKey local(std::uint64_t identity) noexcept
Public Portals API.
Definition action.hpp:8
@ PENDING
Complete or abandon the owning session before submitting another frame.
Definition diff.hpp:108
@ INVALID
The checked candidate was rejected; the editor retains its draft.
Definition form_field.hpp:19
@ CLOSED
Owner, node scope, scheduler or completion endpoint is closed.
Definition async.hpp:28
@ CONFLICT
The model revision changed since this draft began.
Definition line_edit.hpp:86
bool editReceiptMatches(const EditTarget &target, const EditReceipt &receipt) noexcept
Exact qualification; this does not prove a backend applied its precondition.
EditStatus
Submission and acceptance are separate protocol states.
Definition model_edit.hpp:56
@ READ_ONLY
Source permits reads but does not expose writes.
Definition model_edit.hpp:64
@ TARGET_MISSING
Original record is absent; retained draft is orphaned.
Definition model_edit.hpp:63
@ DIRTY
Owning unpublished input.
Definition model_edit.hpp:58
@ REJECTED
Backend rejected the request without applying it.
Definition model_edit.hpp:66
@ ACCEPTED
Endpoint applied this exact qualified write.
Definition model_edit.hpp:60
@ CLEAN
Current accepted value, without a draft.
Definition model_edit.hpp:57
@ PENDING
Admitted work; no backend acceptance has been reported.
Definition model_edit.hpp:59
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
EditMode
When an accepted editing candidate is validated and published to its model.
Definition line_edit.hpp:27
@ IMMEDIATE
Publish each semantic-valid text change; invalid intermediate text remains visible.
Definition line_edit.hpp:28
Explicit source guarantees; unsupported atomicity is never inferred.
Definition model_edit.hpp:84
bool writable
False preserves a readable field/navigation interface.
Definition model_edit.hpp:85
bool recordVersion
True when fields share one record version; false means field-local versions.
Definition model_edit.hpp:89
bool ordered
Backend rejects stale sequences for the same target.
Definition model_edit.hpp:87
bool atomicFields
Backend capability only; this session still submits fields separately.
Definition model_edit.hpp:88
bool conditional
Target/version checked atomically with applying the write.
Definition model_edit.hpp:86
Explicit per-field result of a non-atomic submit.
Definition model_edit.hpp:153
std::vector< EditReceipt > fields
Each applied/rejected/pending field remains visible.
Definition model_edit.hpp:154
bool atomic
True only when one endpoint transaction provided it.
Definition model_edit.hpp:155
Bounded retained editing, independent of collection extent.
Definition model_edit.hpp:93
std::size_t maxRetainedBytes
Logical owning payload admission budget; excludes allocator bookkeeping and temporary staging.
Definition model_edit.hpp:96
EditMode mode
Existing editor publication policy.
Definition model_edit.hpp:94
std::size_t maxRetainedFields
Dirty fields are never silently evicted.
Definition model_edit.hpp:95
Owning acknowledgement qualified independently of current navigation.
Definition model_edit.hpp:70
std::uint64_t acceptedVersion
Positive new record version only for acceptance.
Definition model_edit.hpp:73
EditStatus status
Admission is not acceptance.
Definition model_edit.hpp:72
std::optional< TreeError > error
Optional backend/delivery failure.
Definition model_edit.hpp:74
EditTarget target
Original target and expected version.
Definition model_edit.hpp:71
One bounded immutable field-value read, never a whole-provider materialization.
Definition model_edit.hpp:104
std::uint64_t version
Positive monotonic record or field version, according to capabilities().
Definition model_edit.hpp:106
std::shared_ptr< const T > value
Independent owning field snapshot.
Definition model_edit.hpp:105
Owning bounded write request usable on the existing worker path.
Definition model_edit.hpp:112
EditTarget target
Exact destination and precondition.
Definition model_edit.hpp:113
std::shared_ptr< const T > value
Owning candidate; no UI/widget references.
Definition model_edit.hpp:114
Frozen write destination; ordinal hints and nearest positions are excluded.
Definition model_edit.hpp:42
std::uint64_t baseVersion
Expected version checked together with the backend write.
Definition model_edit.hpp:47
SourceStamp sourceSession
UI source incarnation; the endpoint also guards its own backend incarnation.
Definition model_edit.hpp:49
RowId row
Complete stable record identity.
Definition model_edit.hpp:45
std::uint64_t sequence
Positive request generation within this edit session.
Definition model_edit.hpp:48
SourceStamp session
Unique edit request namespace, independent of source delivery.
Definition model_edit.hpp:44
EditFieldKey field
Owning schema key or explicitly local shorthand.
Definition model_edit.hpp:46
bool operator==(const EditTarget &other) const noexcept=default
ModelResource resource
Source identity and compatible lineage.
Definition model_edit.hpp:43
Logical resource namespace, distinct from its current delivery session. Reuse an existing SourceStamp...
Definition model_position.hpp:21
Provider-assigned row identity, independent of position; increment generation on reuse.
Definition row_id.hpp:9
Immutable source namespace; replacement sessions must share their old budget root.
Definition window_source.hpp:27