Skip to content

Commit 8a74bc9

Browse files
committed
Move common types
1 parent edaefa6 commit 8a74bc9

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1+
import chalicelib.util.type_util as type_util
12
import pydantic
23

3-
ReceiverType = str
4-
AllowedBasicValueTypes = str | int | float | bool | None
5-
AllowedValueTypes = AllowedBasicValueTypes | list[AllowedBasicValueTypes] | dict[str, AllowedBasicValueTypes] | None
6-
ContextType = dict[str, AllowedValueTypes]
7-
84

95
class NotificationSendRequestSharedContext(pydantic.BaseModel):
106
from_: str
117

128

139
class NotificationSendRequest(pydantic.BaseModel):
1410
template_code: str
15-
shared_context: ContextType
16-
personalized_context: dict[ReceiverType, ContextType]
11+
shared_context: type_util.ContextType
12+
personalized_context: dict[str, type_util.ContextType]

runtime/chalicelib/sender/aws_ses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import botocore.exceptions
44
import chalicelib.aws_resource
55
import chalicelib.sender.__interface__ as sender_interface
6+
import chalicelib.util.type_util as type_util
67
import jinja2
78
import pydantic
89

@@ -53,7 +54,7 @@ class AWSSESSendRequest(sender_interface.NotificationSendRequest):
5354

5455
@pydantic.field_validator("shared_context", mode="before")
5556
@classmethod
56-
def validate_shared_context(cls, v: sender_interface.ContextType) -> sender_interface.ContextType:
57+
def validate_shared_context(cls, v: type_util.ContextType) -> type_util.ContextType:
5758
if all(k not in v for k in cls.REQUIRED_SHARED_FIELDS):
5859
raise ValueError("shared_context missing required fields")
5960
return v

runtime/chalicelib/util/type_util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
RouteInfoType = tuple[str, list[HttpMethodType], typing.Callable]
77
RouteCollectionType = list[RouteInfoType]
88

9+
AllowedBasicValueTypes = str | int | float | bool | None
10+
AllowedValueTypes = AllowedBasicValueTypes | list[AllowedBasicValueTypes] | dict[str, AllowedBasicValueTypes] | None
11+
ContextType = dict[str, AllowedValueTypes]
12+
TemplateType = dict[str, AllowedValueTypes]
13+
914

1015
class NotiCoSQSMessage(pydantic.BaseModel):
1116
worker_action: str

0 commit comments

Comments
 (0)