Skip to content

Commit

Permalink
feat: declare transformed return type
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhoheiser committed May 13, 2024
1 parent bc5d39a commit b9d2dd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 4 additions & 1 deletion localstack/services/events/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import Optional, TypedDict
from typing import Optional, TypeAlias, TypedDict

from localstack.aws.api.core import ServiceException
from localstack.aws.api.events import (
Expand Down Expand Up @@ -116,3 +116,6 @@ class FormattedEvent(TypedDict):
region: str
resources: Optional[EventResourceList]
detail: dict[str, str | dict]


TransformedEvent: TypeAlias = FormattedEvent | dict | str
11 changes: 5 additions & 6 deletions localstack/services/events/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

from localstack.aws.api.events import (
Arn,
PutEventsRequestEntry,
Target,
TargetInputPath,
)
from localstack.aws.connect import connect_to
from localstack.services.events.models import FormattedEvent
from localstack.services.events.models import FormattedEvent, TransformedEvent
from localstack.utils import collections
from localstack.utils.aws.arns import (
extract_service_from_arn,
Expand All @@ -29,9 +28,9 @@

def transform_event_with_target_input_path(
input_path: TargetInputPath, event: FormattedEvent
) -> PutEventsRequestEntry:
formated_event = extract_jsonpath(event, input_path)
return formated_event
) -> TransformedEvent:
formatted_event = extract_jsonpath(event, input_path)
return formatted_event


class TargetSender(ABC):
Expand Down Expand Up @@ -64,7 +63,7 @@ def client(self):
return self._client

@abstractmethod
def send_event(self, event: PutEventsRequestEntry):
def send_event(self, event: FormattedEvent | TransformedEvent):
pass

def process_event(self, event: FormattedEvent):
Expand Down

0 comments on commit b9d2dd3

Please sign in to comment.