add storage foundation contracts
This commit is contained in:
parent
0ca0bac9bf
commit
5381c997e2
6 changed files with 208 additions and 0 deletions
|
|
@ -4,8 +4,10 @@ from types import TracebackType
|
|||
from typing import Protocol, TypeAlias
|
||||
from uuid import UUID
|
||||
|
||||
from domain.chat import Chat, ChatAttachmentName, ChatFile
|
||||
from domain.sandbox import SandboxSession
|
||||
from domain.user import User
|
||||
from domain.workspace import Workspace, WorkspaceUsage
|
||||
|
||||
AttrValue: TypeAlias = str | int | float | bool
|
||||
Attrs: TypeAlias = Mapping[str, AttrValue]
|
||||
|
|
@ -19,6 +21,81 @@ class UserRepository(Protocol):
|
|||
def save(self, user: User) -> None: ...
|
||||
|
||||
|
||||
class WorkspaceRepository(Protocol):
|
||||
def get(self, workspace_id: UUID) -> Workspace | None: ...
|
||||
|
||||
def get_by_user_id(self, user_id: UUID) -> Workspace | None: ...
|
||||
|
||||
def save(self, workspace: Workspace) -> None: ...
|
||||
|
||||
|
||||
class ChatRepository(Protocol):
|
||||
def get(self, chat_id: UUID) -> Chat | None: ...
|
||||
|
||||
def list_by_workspace_id(self, workspace_id: UUID) -> list[Chat]: ...
|
||||
|
||||
def save(self, chat: Chat) -> None: ...
|
||||
|
||||
def delete(self, chat_id: UUID) -> None: ...
|
||||
|
||||
|
||||
class ChatFileRepository(Protocol):
|
||||
def get(self, file_id: UUID) -> ChatFile | None: ...
|
||||
|
||||
def get_by_chat_id_and_name(
|
||||
self,
|
||||
chat_id: UUID,
|
||||
name: ChatAttachmentName,
|
||||
) -> ChatFile | None: ...
|
||||
|
||||
def list_by_chat_id(self, chat_id: UUID) -> list[ChatFile]: ...
|
||||
|
||||
def save(self, chat_file: ChatFile) -> None: ...
|
||||
|
||||
def delete(self, file_id: UUID) -> None: ...
|
||||
|
||||
def delete_by_chat_id(self, chat_id: UUID) -> None: ...
|
||||
|
||||
|
||||
class ChatStorage(Protocol):
|
||||
def ensure_chat(self, chat: Chat) -> None: ...
|
||||
|
||||
def read_history(self, chat: Chat) -> str: ...
|
||||
|
||||
def write_history(self, chat: Chat, content: str) -> None: ...
|
||||
|
||||
def delete_chat(self, chat: Chat) -> None: ...
|
||||
|
||||
def write_attachment(
|
||||
self,
|
||||
chat: Chat,
|
||||
file_name: ChatAttachmentName,
|
||||
content: bytes,
|
||||
) -> int: ...
|
||||
|
||||
def read_attachment(self, chat: Chat, file_name: ChatAttachmentName) -> bytes: ...
|
||||
|
||||
def delete_attachment(
|
||||
self,
|
||||
chat: Chat,
|
||||
file_name: ChatAttachmentName,
|
||||
) -> None: ...
|
||||
|
||||
def clear_attachments(self, chat: Chat) -> None: ...
|
||||
|
||||
|
||||
class StorageUsageReader(Protocol):
|
||||
def get_workspace_usage(
|
||||
self,
|
||||
workspace: Workspace,
|
||||
chats: list[Chat],
|
||||
) -> WorkspaceUsage: ...
|
||||
|
||||
|
||||
class IdGenerator(Protocol):
|
||||
def new(self) -> UUID: ...
|
||||
|
||||
|
||||
class SandboxSessionRepository(Protocol):
|
||||
def get_active_by_chat_id(self, chat_id: UUID) -> SandboxSession | None: ...
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue