Rename planner and document rewrite: rewrite_documents moves qualified names of the renamed flow in every flow (ports, inputs, outputs) and dashboard binding (one key table, WIDGET_BINDINGS, shared with the WidgetDef accessors, legacy pages included), published and draft, as plain JSON with both variants above either version; plan_rename reports documents, counts, fingerprint, warnings and refusals; superuser plan routes for flows and dashboards; key residue classifies state as the mapper does; duplicate retargets inputs and outputs too; queue reports its Redis version and other consumers
This commit is contained in:
@@ -34,6 +34,7 @@ from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Literal
|
||||
|
||||
from fluksio.flow.namespace import FLOW_FIELDS, Rename, rebind
|
||||
from fluksio.flow.schemas import FlowDef, NodeDef, _validate_name
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -971,7 +972,9 @@ class FlowStore:
|
||||
)
|
||||
copy = self._claim(copy, create=True)
|
||||
# Its own messages named with its own key are the copy's now.
|
||||
self._retarget(copy, f"{source.name}.", f"{new_name}.")
|
||||
document = copy.model_dump(mode="json")
|
||||
rebind(document, FLOW_FIELDS, Rename(source.name, new_name).binding)
|
||||
copy = FlowDef.model_validate(document)
|
||||
path = self._draft_file(copy.id)
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text(copy.model_dump_json(indent=2) + "\n")
|
||||
@@ -993,21 +996,6 @@ class FlowStore:
|
||||
)
|
||||
return copy
|
||||
|
||||
@staticmethod
|
||||
def _retarget(flow: FlowDef, old_prefix: str, new_prefix: str) -> bool:
|
||||
"""Point this flow's cross-flow message names at a renamed flow."""
|
||||
changed = False
|
||||
for node in flow.nodes:
|
||||
for specs in (node.requires, node.provides):
|
||||
for position, spec in enumerate(specs):
|
||||
if spec.name.startswith(old_prefix):
|
||||
tail = spec.name[len(old_prefix) :]
|
||||
specs[position] = spec.model_copy(
|
||||
update={"name": new_prefix + tail}
|
||||
)
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Node source
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user