from collections.abc import Callable from typing import Any import httpx from cross.service import InputService, OutputService from database.connection import DatabasePool input_factories: dict[ str, Callable[[DatabasePool, httpx.Client, dict[str, Any]], InputService] ] = {} output_factories: dict[ str, Callable[[DatabasePool, httpx.Client, dict[str, Any]], OutputService] ] = {} def create_input_service( db: DatabasePool, http: httpx.Client, data: dict[str, Any] ) -> InputService: if "type" not in data: raise ValueError("No 'type' field in input data!") type: str = str(data["type"]) del data["type"] factory = input_factories.get(type) if not factory: raise KeyError(f"No such input service {type}!") return factory(db, http, data) def create_output_service( db: DatabasePool, http: httpx.Client, data: dict[str, Any] ) -> OutputService: if "type" not in data: raise ValueError("No 'type' field in input data!") type: str = str(data["type"]) del data["type"] factory = output_factories.get(type) if not factory: raise KeyError(f"No such output service {type}!") return factory(db, http, data)