- F11 PopulateRule field_name/collection_name corrections - F12 service adaptor update handles PopulatingRepository - F13 nested-references section; F14 authless /users/me guidance - F15 template ruff-clean; F16 stop vendoring .ruff_cache, ship .gitignore - document --template-style in build_recipe/spec_first_routing; refresh collected openapi-first + standards bundle (12 modules, 43 components) - add trial.md and trial_findings.md (F1-F16, re-trial A/B evidence)
41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
"""# Summary
|
|
|
|
Generic MongoDB CRUD repo — single implementation for all domains.
|
|
|
|
Select a concrete mongo-ops repository (base, cached, or populating) from the
|
|
options supplied to the factory.
|
|
"""
|
|
|
|
from mongo_ops import BaseRepository, CachedBaseRepository, PopulatingRepository
|
|
from mongo_ops.cache import CacheBackend, CacheConfig
|
|
from mongo_ops.models import BaseDocument
|
|
from mongo_ops.populate import PopulateRule, PopulationEngine
|
|
|
|
|
|
def _repo_factory(
|
|
collection: str,
|
|
db_model: type[BaseDocument],
|
|
cache_backend: CacheBackend | None = None,
|
|
cache_config: CacheConfig | None = None,
|
|
engine: PopulationEngine | None = None,
|
|
populate_rules: list[PopulateRule] | None = None,
|
|
) -> BaseRepository:
|
|
"""Build the appropriate mongo-ops repository.
|
|
|
|
Args:
|
|
collection (str): Collection name to operate on.
|
|
db_model (Type[BaseDocument]): Document model bound to the collection.
|
|
cache_backend (Optional[CacheBackend]): Cache backend enabling cached reads.
|
|
cache_config (Optional[CacheConfig]): Cache configuration for the backend.
|
|
engine (Optional[PopulationEngine]): Population engine for reference expansion.
|
|
populate_rules (Optional[List[PopulateRule]]): Rules applied by the engine.
|
|
|
|
Returns:
|
|
BaseRepository: Repository instance matching the supplied options.
|
|
"""
|
|
if engine and populate_rules is not None:
|
|
return PopulatingRepository(collection, db_model, engine, populate_rules)
|
|
elif cache_backend is not None:
|
|
return CachedBaseRepository(collection, db_model, cache_backend, cache_config)
|
|
else:
|
|
return BaseRepository(collection, db_model) |