Files
core/nodes/vork_node_if.py
ivan.dev 78839c5883 revert 12e3c65aa0
revert refactor: name node
2025-09-12 14:17:29 +05:00

63 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from typing import Dict, Any
from core import VorkNode
from model_nodes.node_if_models import (
IfNodeData,
IfNodeLinks,
IfNodeCoreSchema,
IfNodeCoreSchemaData,
IfNodeDescriptor
)
class VorkNodeIf(VorkNode):
@property
def id(self) -> str:
return "vork_node_if"
@classmethod
def form(cls) -> IfNodeDescriptor:
return IfNodeDescriptor()
def validate(self) -> IfNodeCoreSchema:
"""
Валидирует данные и связи узла с помощью Pydantic моделей
и возвращает схему с валидированными данными.
"""
try:
# Валидируем данные
validated_data = self.validate_data()
# Валидируем связи
validated_links = self.validate_links()
# Создаем вложенную схему с данными портов
node_data = IfNodeCoreSchemaData(
then_port_number=0,
else_port_number=1,
)
# Создаем схему с валидированными данными из экземпляра
return IfNodeCoreSchema(
ps_id=validated_data.ps_id,
node_type=validated_data.node_type,
parent_id=validated_links.parent_id,
parent_port_number=validated_links.parent_port_number,
data=node_data,
)
except Exception as e:
print(f"Node validation error if: {e}")
raise
def validate_data(self) -> IfNodeData:
return IfNodeData(**self.data)
def validate_links(self) -> IfNodeLinks:
return IfNodeLinks(**self.links)
def process(self, context: Any) -> bool:
return True