99 lines
3.3 KiB
Python
99 lines
3.3 KiB
Python
from typing import TypeAlias, cast
|
|
|
|
from guide.app.strings.graphql import (
|
|
ADD_SUPPLIER,
|
|
CREATE_INTAKE_REQUEST,
|
|
GET_INTAKE_REQUEST,
|
|
LIST_SUPPLIERS,
|
|
)
|
|
from guide.app.strings.demo_texts import DemoTexts, EventTexts, IntakeTexts, SupplierTexts
|
|
from guide.app.strings.labels import AuthLabels, IntakeLabels, Labels, SourcingLabels
|
|
from guide.app.strings.selectors import AuthSelectors, IntakeSelectors, NavigationSelectors, Selectors, SourcingSelectors
|
|
|
|
SelectorNamespace: TypeAlias = type[IntakeSelectors] | type[SourcingSelectors] | type[NavigationSelectors] | type[AuthSelectors]
|
|
LabelNamespace: TypeAlias = type[IntakeLabels] | type[SourcingLabels] | type[AuthLabels]
|
|
TextNamespace: TypeAlias = type[IntakeTexts] | type[SupplierTexts] | type[EventTexts]
|
|
TextValue: TypeAlias = str | list[str]
|
|
|
|
_SELECTORS: dict[str, SelectorNamespace] = {
|
|
"INTAKE": Selectors.INTAKE,
|
|
"SOURCING": Selectors.SOURCING,
|
|
"NAVIGATION": Selectors.NAVIGATION,
|
|
"AUTH": Selectors.AUTH,
|
|
}
|
|
|
|
_LABELS: dict[str, LabelNamespace] = {
|
|
"INTAKE": Labels.INTAKE,
|
|
"SOURCING": Labels.SOURCING,
|
|
"AUTH": Labels.AUTH,
|
|
}
|
|
|
|
_TEXTS: dict[str, TextNamespace] = {
|
|
"INTAKE": DemoTexts.INTAKE,
|
|
"SUPPLIERS": DemoTexts.SUPPLIERS,
|
|
"EVENTS": DemoTexts.EVENTS,
|
|
}
|
|
|
|
_GQL = {
|
|
"GET_INTAKE_REQUEST": GET_INTAKE_REQUEST,
|
|
"CREATE_INTAKE_REQUEST": CREATE_INTAKE_REQUEST,
|
|
"LIST_SUPPLIERS": LIST_SUPPLIERS,
|
|
"ADD_SUPPLIER": ADD_SUPPLIER,
|
|
}
|
|
|
|
|
|
class Strings:
|
|
"""Unified accessor for selectors, labels, texts, and GraphQL queries."""
|
|
|
|
@staticmethod
|
|
def selector(domain: str, name: str) -> str:
|
|
ns = _SELECTORS.get(domain.upper())
|
|
if ns is None:
|
|
raise KeyError(f"Unknown selector domain '{domain}'")
|
|
value = cast(str | None, getattr(ns, name, None))
|
|
return _as_str(value, f"selector {domain}.{name}")
|
|
|
|
@staticmethod
|
|
def label(domain: str, name: str) -> str:
|
|
ns = _LABELS.get(domain.upper())
|
|
if ns is None:
|
|
raise KeyError(f"Unknown label domain '{domain}'")
|
|
value = cast(str | None, getattr(ns, name, None))
|
|
return _as_str(value, f"label {domain}.{name}")
|
|
|
|
@staticmethod
|
|
def text(domain: str, name: str) -> TextValue:
|
|
ns = _TEXTS.get(domain.upper())
|
|
if ns is None:
|
|
raise KeyError(f"Unknown text domain '{domain}'")
|
|
value: object | None = getattr(ns, name, None)
|
|
if value is None:
|
|
raise KeyError(f"Unknown text {domain}.{name}")
|
|
if isinstance(value, str):
|
|
return value
|
|
if isinstance(value, list):
|
|
value_list: list[object] = cast(list[object], value)
|
|
str_values: list[str] = []
|
|
for item in value_list:
|
|
if not isinstance(item, str):
|
|
raise TypeError(f"text {domain}.{name} must be a string or list of strings")
|
|
str_values.append(item)
|
|
return str_values
|
|
raise TypeError(f"text {domain}.{name} must be a string or list of strings")
|
|
|
|
@staticmethod
|
|
def gql(name: str) -> str:
|
|
value = _GQL.get(name)
|
|
return _as_str(value, f"graphql string {name}")
|
|
|
|
|
|
def _as_str(value: object, label: str) -> str:
|
|
if not isinstance(value, str): # pragma: no cover
|
|
raise TypeError(f"{label} must be a string")
|
|
return value
|
|
|
|
|
|
strings = Strings()
|
|
|
|
__all__ = ["Strings", "strings"]
|