mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 14:24:15 +08:00
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
"""Stable, small-grained contracts for in-repository secondary development."""
|
|
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
from typing import Any, Protocol
|
|
|
|
BACKEND_EXTENSION_API_VERSION = 1
|
|
|
|
|
|
class RepositoryAccess(Protocol):
|
|
"""Read-oriented repository surface exposed to backend extensions."""
|
|
|
|
def get_name_map(self, symbols: list[str] | None = None) -> dict[str, str]: ...
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ExtensionContext:
|
|
api_version: int
|
|
data_dir: Path
|
|
repository: RepositoryAccess
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class NotificationFormatContext:
|
|
api_version: int
|
|
|
|
|
|
class NotificationFormatter(ABC):
|
|
"""Customize notification copy without changing the event schema or semantics."""
|
|
|
|
api_version = BACKEND_EXTENSION_API_VERSION
|
|
|
|
@abstractmethod
|
|
def format_message(
|
|
self,
|
|
event: dict[str, Any],
|
|
context: NotificationFormatContext,
|
|
) -> str:
|
|
"""Return notification copy. The input event must not be mutated."""
|
|
raise NotImplementedError
|
|
|
|
|
|
class DefaultNotificationFormatter(NotificationFormatter):
|
|
def format_message(
|
|
self,
|
|
event: dict[str, Any],
|
|
context: NotificationFormatContext,
|
|
) -> str:
|
|
del context
|
|
return str(event.get("message") or "")
|