Rename the trigger node type to debounce, migrating stored flows
The store rewrites `"type": "trigger"` to `debounce` in every published and draft flow when it opens, bumps the version and commits once. No alias stays behind, so `trigger` is now an unknown type.
This commit is contained in:
@@ -40,6 +40,7 @@ from fluksio.flow.messages import MessageSpec, flow_of, qualify
|
||||
from fluksio.flow.nodes import (
|
||||
RESERVED_SETTINGS,
|
||||
ChangeNode,
|
||||
DebounceNode,
|
||||
DelayNode,
|
||||
ExecNode,
|
||||
FileNode,
|
||||
@@ -53,7 +54,6 @@ from fluksio.flow.nodes import (
|
||||
NtfyNode,
|
||||
RbeNode,
|
||||
SwitchNode,
|
||||
TriggerNode,
|
||||
WebSocketNode,
|
||||
WrenNode,
|
||||
)
|
||||
@@ -408,11 +408,11 @@ NODE_TYPES: dict[str, NodeType] = {
|
||||
cls=JoinNode,
|
||||
params_schema=_schema_of(JoinNode),
|
||||
),
|
||||
"trigger": NodeType(
|
||||
title="Trigger",
|
||||
"debounce": NodeType(
|
||||
title="Debounce",
|
||||
description="Send one value now and another once things go quiet.",
|
||||
cls=TriggerNode,
|
||||
params_schema=_schema_of(TriggerNode),
|
||||
cls=DebounceNode,
|
||||
params_schema=_schema_of(DebounceNode),
|
||||
),
|
||||
"exec": NodeType(
|
||||
title="Command",
|
||||
|
||||
@@ -5,6 +5,7 @@ Split by the outside world each one talks to. Importing from
|
||||
"""
|
||||
|
||||
from fluksio.flow.nodes.base import RESERVED_SETTINGS, Node
|
||||
from fluksio.flow.nodes.debounce import DebounceNode
|
||||
from fluksio.flow.nodes.delay import DelayNode
|
||||
from fluksio.flow.nodes.exec import ExecNode
|
||||
from fluksio.flow.nodes.file import FileNode
|
||||
@@ -15,12 +16,12 @@ from fluksio.flow.nodes.logic import ChangeNode, JoinNode, RbeNode, SwitchNode
|
||||
from fluksio.flow.nodes.mlp import MLPNode
|
||||
from fluksio.flow.nodes.mqtt import MqttNode
|
||||
from fluksio.flow.nodes.ntfy import NtfyNode
|
||||
from fluksio.flow.nodes.trigger import TriggerNode
|
||||
from fluksio.flow.nodes.websocket import WebSocketNode
|
||||
from fluksio.flow.nodes.wren import WrenNode
|
||||
|
||||
__all__ = [
|
||||
"ChangeNode",
|
||||
"DebounceNode",
|
||||
"DelayNode",
|
||||
"ExecNode",
|
||||
"FileNode",
|
||||
@@ -35,7 +36,6 @@ __all__ = [
|
||||
"RESERVED_SETTINGS",
|
||||
"RbeNode",
|
||||
"SwitchNode",
|
||||
"TriggerNode",
|
||||
"WebSocketNode",
|
||||
"WrenNode",
|
||||
]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""Trigger: send one thing now, another if nothing follows.
|
||||
"""Debounce: send one thing now, another if nothing follows.
|
||||
|
||||
Node-RED's *trigger*. The shape it exists for is "the door opened — turn the
|
||||
light on, and off again in two minutes unless it opens again", which is
|
||||
awkward to express any other way.
|
||||
Node-RED calls this node *trigger*. The shape it exists for is "the door
|
||||
opened — turn the light on, and off again in two minutes unless it opens
|
||||
again", which is awkward to express any other way.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -19,7 +19,7 @@ from fluksio.flow.nodes.base import Node
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TriggerNode(Node):
|
||||
class DebounceNode(Node):
|
||||
"""Emit ``first`` on arrival, then ``then`` once the wait runs out.
|
||||
|
||||
A value arriving during the wait extends it, so the second emission only
|
||||
@@ -67,17 +67,17 @@ class TriggerNode(Node):
|
||||
):
|
||||
self.cfg = self.Params.model_validate(params or {})
|
||||
super().__init__(
|
||||
f=self._trigger,
|
||||
f=self._debounce,
|
||||
requires=requires,
|
||||
provides=provides,
|
||||
params=params,
|
||||
name=name or "trigger",
|
||||
name=name or "debounce",
|
||||
)
|
||||
|
||||
def _outputs(self, value: Any) -> dict[str, Any]:
|
||||
return {spec.port: value for spec in self.output_ports}
|
||||
|
||||
def _trigger(self, params: dict[str, Any], **kwargs: Any) -> dict[str, Any] | None:
|
||||
def _debounce(self, params: dict[str, Any], **kwargs: Any) -> dict[str, Any] | None:
|
||||
if not kwargs or not self.output_ports:
|
||||
return None
|
||||
|
||||
@@ -166,6 +166,40 @@ class FlowStore:
|
||||
if not (self.root / ".git").exists():
|
||||
self._git("init", "-q")
|
||||
self._commit("Initialise flow store", allow_empty=True)
|
||||
self._migrate()
|
||||
|
||||
def _migrate(self) -> None:
|
||||
"""Rewrite node types stored under a name they no longer have.
|
||||
|
||||
The node type ``trigger`` became ``debounce`` on 2026-10-15, with no
|
||||
alias left for the old name. Each published and draft document is read
|
||||
as plain JSON and only the ``type`` of a matching node changes, so a
|
||||
field this version does not model survives, and the old document stays
|
||||
in git. The version goes up by one, so an editor still holding the old
|
||||
document gets a conflict on its next save instead of writing the old
|
||||
name back. A store with nothing to rename is left alone.
|
||||
"""
|
||||
changed = []
|
||||
paths = [*self.root.glob("*/flow.json"), *self.root.glob("*/flow.draft.json")]
|
||||
for path in sorted(paths):
|
||||
try:
|
||||
data = json.loads(path.read_text())
|
||||
nodes = [n for n in data["nodes"] if n.get("type") == "trigger"]
|
||||
except Exception:
|
||||
# Unreadable to the engine too, which reports it when it loads.
|
||||
continue
|
||||
if not nodes:
|
||||
continue
|
||||
for node in nodes:
|
||||
node["type"] = "debounce"
|
||||
data["version"] = data.get("version", 1) + 1
|
||||
path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n")
|
||||
changed.append(f"{path.parent.name}/{path.name}")
|
||||
if changed:
|
||||
logger.warning(
|
||||
"Renamed node type 'trigger' to 'debounce' in %s", ", ".join(changed)
|
||||
)
|
||||
self._commit("Rename node type 'trigger' to 'debounce'")
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# git
|
||||
|
||||
Reference in New Issue
Block a user