Skip to content

Commit

Permalink
feat(workflow): Support sub condition in if else node.
Browse files Browse the repository at this point in the history
  • Loading branch information
laipz8200 committed Sep 22, 2024
1 parent 71989de commit 997defa
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 128 deletions.
4 changes: 3 additions & 1 deletion api/core/file/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .enums import FileBelongsTo, FileTransferMethod, FileType
from .enums import ArrayFileAttribute, FileAttribute, FileBelongsTo, FileTransferMethod, FileType
from .models import (
File,
FileExtraConfig,
Expand All @@ -12,4 +12,6 @@
"FileBelongsTo",
"File",
"ImageConfig",
"FileAttribute",
"ArrayFileAttribute",
]
13 changes: 13 additions & 0 deletions api/core/file/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ def value_of(value):
if member.value == value:
return member
raise ValueError(f"No matching enum found for value '{value}'")


class FileAttribute(str, Enum):
TYPE = "type"
SIZE = "size"
NAME = "name"
MIMETYPE = "mimetype"
TRANSFER_METHOD = "transfer_method"
URL = "url"


class ArrayFileAttribute(str, Enum):
LENGTH = "length"
60 changes: 35 additions & 25 deletions api/core/workflow/utils/condition/entities.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
from typing import Literal, Optional

from pydantic import BaseModel
from pydantic import BaseModel, Field

SupportedComparisonOperator = Literal[
# for string or array
"contains",
"not contains",
"start with",
"end with",
"is",
"is not",
"empty",
"not empty",
# for number
"=",
"≠",
">",
"<",
"≥",
"≤",
"null",
"not null",
]


class SubCondition(BaseModel):
key: str
comparison_operator: SupportedComparisonOperator
value: Optional[str] = None

class Condition(BaseModel):
"""
Condition entity
"""

class SubVariable(BaseModel):
logical_operator: Literal["and", "or"]
conditions: list[SubCondition] = Field(default=list)


class Condition(BaseModel):
variable_selector: list[str]
comparison_operator: Literal[
# for string or array
"contains",
"not contains",
"start with",
"end with",
"is",
"is not",
"empty",
"not empty",
# for number
"=",
"≠",
">",
"<",
"≥",
"≤",
"null",
"not null",
]
comparison_operator: SupportedComparisonOperator
value: Optional[str] = None
sub_variable: SubVariable | None = None
Loading

0 comments on commit 997defa

Please sign in to comment.