entities.py 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from collections.abc import Sequence
  2. from typing import Literal
  3. from pydantic import BaseModel, Field
  4. SupportedComparisonOperator = Literal[
  5. # for string or array
  6. "contains",
  7. "not contains",
  8. "start with",
  9. "end with",
  10. "is",
  11. "is not",
  12. "empty",
  13. "not empty",
  14. "in",
  15. "not in",
  16. "all of",
  17. # for number
  18. "=",
  19. "≠",
  20. ">",
  21. "<",
  22. "≥",
  23. "≤",
  24. "null",
  25. "not null",
  26. # for file
  27. "exists",
  28. "not exists",
  29. ]
  30. class SubCondition(BaseModel):
  31. key: str
  32. comparison_operator: SupportedComparisonOperator
  33. value: str | Sequence[str] | None = None
  34. class SubVariableCondition(BaseModel):
  35. logical_operator: Literal["and", "or"]
  36. conditions: list[SubCondition] = Field(default=list)
  37. class Condition(BaseModel):
  38. variable_selector: list[str]
  39. comparison_operator: SupportedComparisonOperator
  40. value: str | Sequence[str] | None = None
  41. sub_variable_condition: SubVariableCondition | None = None