1+ """Event metadata filter models for querying events based on metadata."""
2+
13from enum import Enum
2- from typing import Optional , TypedDict , Union , NotRequired
4+ from typing import Optional , TypedDict , Union
5+
36
47class StringValue (TypedDict ):
58 """Value associated with the `eventMetadata` key."""
9+
610 stringValue : str
7-
11+
812 @staticmethod
9- def build (value : str ) -> ' StringValue' :
10- return {
11- "stringValue" : value
12- }
13+ def build (value : str ) -> " StringValue" :
14+ """Build a StringValue from a string."""
15+ return { "stringValue" : value }
16+
1317
1418MetadataValue = Union [StringValue ]
1519"""
@@ -24,68 +28,75 @@ def build(value: str) -> 'StringValue':
2428Union type representing metadata key.
2529"""
2630
31+
2732class LeftExpression (TypedDict ):
28- """
29- Left operand of the event metadata filter expression.
30- """
33+ """Left operand of the event metadata filter expression."""
34+
3135 metadataKey : MetadataKey
32-
36+
3337 @staticmethod
34- def build (key : str ) -> 'LeftExpression' :
35- """Builds the `metadataKey` for `LeftExpression`"""
36- return {
37- "metadataKey" : key
38- }
38+ def build (key : str ) -> "LeftExpression" :
39+ """Builds the `metadataKey` for `LeftExpression`."""
40+ return {"metadataKey" : key }
41+
3942
4043class OperatorType (Enum ):
41- """
42- Operator applied to the event metadata filter expression.
43-
44+ """Operator applied to the event metadata filter expression.
45+
4446 Currently supports:
4547 - `EQUALS_TO`
4648 - `EXISTS`
4749 - `NOT_EXISTS`
4850 """
51+
4952 EQUALS_TO = "EQUALS_TO"
5053 EXISTS = "EXISTS"
5154 NOT_EXISTS = "NOT_EXISTS"
5255
56+
5357class RightExpression (TypedDict ):
54- """
55- Right operand of the event metadata filter expression.
56-
58+ """Right operand of the event metadata filter expression.
59+
5760 Variants:
5861 - StringValue: {"metadataValue": {"stringValue": str}}
5962 """
63+
6064 metadataValue : MetadataValue
6165
6266 @staticmethod
63- def build (value : str ) -> ' RightExpression' :
64- """Builds the `RightExpression` for `stringValue` type"""
67+ def build (value : str ) -> " RightExpression" :
68+ """Builds the `RightExpression` for `stringValue` type. """
6569 return {"metadataValue" : StringValue .build (value )}
6670
71+
6772class EventMetadataFilter (TypedDict ):
68- """
69- Filter expression for retrieving events based on metadata associated with an event.
70-
73+ """Filter expression for retrieving events based on metadata associated with an event.
74+
7175 Args:
7276 left: `LeftExpression` of the event metadata filter expression.
7377 operator: `OperatorType` applied to the event metadata filter expression.
7478 right: Optional `RightExpression` of the event metadata filter expression.
7579 """
80+
7681 left : LeftExpression
7782 operator : OperatorType
78- right : NotRequired [RightExpression ]
79-
80- def build_expression (left_operand : LeftExpression , operator : OperatorType , right_operand : Optional [RightExpression ] = None ) -> 'EventMetadataFilter' :
81- """
82- This method builds the required event metadata filter expression into the `EventMetadataFilterExpression` type when querying listEvents.
83-
84- Args:
83+ right : Optional [RightExpression ]
84+
85+ def build_expression (
86+ left_operand : LeftExpression ,
87+ operator : OperatorType ,
88+ right_operand : Optional [RightExpression ] = None ,
89+ ) -> "EventMetadataFilter" :
90+ """Build the required event metadata filter expression.
91+
92+ This method builds the required event metadata filter expression into the
93+ `EventMetadataFilterExpression` type when querying listEvents.
94+
95+ Args:
8596 left_operand: Left operand of the event metadata filter expression
8697 operator: Operator applied to the event metadata filter expression
8798 right_operand: Optional right_operand of the event metadata filter expression.
88-
99+
89100 Example:
90101 ```
91102 left_operand = LeftExpression.build_key(key='location')
@@ -108,11 +119,8 @@ def build_expression(left_operand: LeftExpression, operator: OperatorType, right
108119 }
109120 ```
110121 """
111- filter = {
112- 'left' : left_operand ,
113- 'operator' : operator .value
114- }
115-
122+ filter = {"left" : left_operand , "operator" : operator .value }
123+
116124 if right_operand :
117- filter [' right' ] = right_operand
118- return filter
125+ filter [" right" ] = right_operand
126+ return filter
0 commit comments