10 if (
node.id.empty() ||
node.type.empty() || nodes_.contains(
node.id))
11 return eve::editing::failed<void>(Status::Conflict,
RuleId(
"editing.graph.invalid-node"),
12 "Graph node id/type is missing or the id already exists");
15 return eve::editing::failed<void>(Status::Rejected,
RuleId(
"editing.graph.invalid-pin"),
16 "Graph pin id is required");
19 return eve::editing::failed<void>(Status::Conflict,
RuleId(
"editing.graph.duplicate-pin"),
20 "Graph pin id already exists");
22 nodes_.emplace(
node.id, std::move(
node));
24 return eve::editing::applied<void>();
28 if (!nodes_.contains(
node))
29 return eve::editing::failed<void>(Status::NotFound,
RuleId(
"editing.graph.node-not-found"),
30 "Graph node does not exist");
31 std::vector<GraphPinId> pins;
33 std::erase_if(edges_, [&](
const auto&
edge) {
34 return std::find(pins.begin(), pins.end(),
edge.second.from) != pins.end() ||
35 std::find(pins.begin(), pins.end(),
edge.second.to) != pins.end();
39 return eve::editing::applied<void>();
45 if (diagnostics.empty())
47 RuleId(
"editing.graph.connection-rejected"),
48 DiagnosticSeverity::Error,
"Connection was rejected"));
52 return eve::editing::failed<void>(Status::Rejected,
RuleId(
"editing.graph.invalid-edge"),
53 "Graph edge id/pins are invalid or duplicated");
54 edges_.emplace(
edge.id, std::move(
edge));
56 return eve::editing::applied<void>();
60 if (!edges_.erase(
edge))
61 return eve::editing::failed<void>(Status::NotFound,
RuleId(
"editing.graph.edge-not-found"),
62 "Graph edge does not exist");
64 return eve::editing::applied<void>();
69 if (
found == nodes_.end())
70 return eve::editing::failed<void>(Status::NotFound,
RuleId(
"editing.graph.node-not-found"),
71 "Graph node does not exist");
73 return eve::editing::failed<void>(Status::Rejected,
RuleId(
"editing.graph.invalid-properties"),
74 "Graph node properties must be an object");
77 return eve::editing::applied<void>();
82 return eve::editing::failed<void>(Status::Rejected,
RuleId(
"editing.graph.invalid-parameters"),
83 "Graph parameters must be an object");
85 return eve::editing::failed<void>(Status::Rejected,
RuleId(
"editing.graph.parameters-too-large"),
86 "Graph parameters exceed editing document limits");
87 parameters_ = std::move(parameters);
89 return eve::editing::applied<void>();
94 result.
domain = std::move(domain);
97 for (
const auto& [
id,
node] : nodes_) {
101 for (
const auto& [
id,
edge] : edges_) {
109 for (
const auto& [
id,
node] : nodes_) {
111 auto found = std::find_if(
node.pins.begin(),
node.pins.end(),
112 [&](
const GraphPinRecord& candidate) { return candidate.id == pin; });
std::map< std::string, PropertyRule > properties
Move-only operation result carrying either a value or Status.
static Result failure(Status status)
Construct a failed result from a structured status.
Structured status and zero or more diagnostics for an operation.
UUID-backed identifier adapter for legacy textual boundaries.
Result< void > connect(GraphEdgeRecord edge, const GraphConnectionDecision &decision)
Connect.
Result< void > setNodeProperties(const GraphNodeId &node, Value properties)
Sets the node properties.
const GraphPinRecord * findPin(const GraphPinId &pin) const
Finds pin.
Result< void > setParameters(Value parameters)
Sets the parameters.
Result< void > disconnect(const StableId &edge)
Disconnect.
GraphDocumentData snapshot(std::string domain) const
Snapshot.
Result< void > deleteNode(const GraphNodeId &node)
Deletes node.
Result< void > createNode(GraphNodeRecord node)
Creates node.
Deterministic owning value tree shared by authoring hosts.
bool isWithinLimits(size_t maxDepth, size_t maxElements, size_t maxStringBytes) const
Validate nesting, element count and approximate string byte limits.
Type type() const
Return the active value type.
StrongId< RuleIdTag > RuleId
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build a common diagnostic carrying an open editing rule identity.
Result of domain-specific connection validation.
std::vector< Diagnostic > diagnostics
Immutable graph document value sent to a domain compiler.
std::vector< GraphNodeRecord > nodes
std::vector< GraphEdgeRecord > edges
Directed connection between an output and input pin.
Generic graph node independent of its domain.
Stable typed pin owned by a graph node.