forked from INTERSECT-SDK/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_metadata.py
More file actions
68 lines (58 loc) · 2.1 KB
/
event_metadata.py
File metadata and controls
68 lines (58 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from __future__ import annotations
from typing import TYPE_CHECKING, Any, NamedTuple
if TYPE_CHECKING:
from pydantic import TypeAdapter
from ..core_definitions import IntersectDataHandler, IntersectMimeType
from ..service_definitions import IntersectEventDefinition
class EventMetadata(NamedTuple):
"""Internal cache of metadata associated with an event.
NOTE: both this class and all properties in it should remain immutable after creation
"""
operations: set[str]
"""
A hash set of operations which advertise this event
"""
type: type
"""
The actual type of the event
"""
type_adapter: TypeAdapter[Any]
"""
The type adapter used for deserializing and validating events
"""
data_transfer_handler: IntersectDataHandler
"""
The data transfer type
"""
content_type: IntersectMimeType
"""
The content type
"""
def definition_metadata_differences(
definition: IntersectEventDefinition, metadata: EventMetadata
) -> list[tuple[str, str, str]]:
"""Return a list of differences between 'definition' and 'metadata'.
First tuple value = definition key
Second tuple value = second value
Third tuple value = already cached value
"""
differences = []
if definition.event_type != metadata.type:
differences.append(('event_type', str(definition.event_type), str(metadata.type)))
if definition.content_type != metadata.content_type:
differences.append(
(
'content_type',
f'{definition.content_type.__class__.__name__}.{definition.content_type.name}',
f'{metadata.content_type.__class__.__name__}.{metadata.content_type.name}',
)
)
if definition.data_handler != metadata.data_transfer_handler:
differences.append(
(
'data_handler',
f'{definition.data_handler.__class__.__name__}.{definition.data_handler.name}',
f'{metadata.data_transfer_handler.__class__.__name__}.{metadata.data_transfer_handler.name}',
)
)
return differences