refactor: conform standards docs to doc-forge wiki/lib layout; generic build.py; static kind links

This commit is contained in:
2026-10-11 23:04:56 +05:30
parent 1208945e1d
commit 74aaf2f53e
181 changed files with 8649 additions and 1873 deletions

View File

@@ -0,0 +1,42 @@
"""# 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 typing import List, Optional, Type
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 PopulationEngine, PopulateRule
def _repo_factory(
collection: str,
db_model: Type[BaseDocument],
cache_backend: Optional[CacheBackend] = None,
cache_config: Optional[CacheConfig] = None,
engine: Optional[PopulationEngine] = None,
populate_rules: Optional[List[PopulateRule]] = 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)

View File

@@ -0,0 +1,23 @@
"""# Summary
Database setup — connection lifecycle only. No domain imports.
Connect and disconnect the shared Mongo connection manager at application
startup and shutdown.
"""
from mongo_ops import MongoConnectionManager
async def setup_database(uri: str, db_name: str):
"""Connect the shared Mongo connection manager.
Args:
uri (str): Mongo connection URI.
db_name (str): Target database name.
"""
await MongoConnectionManager.connect(uri=uri, db_name=db_name)
async def shutdown_database():
"""Disconnect the shared Mongo connection manager."""
await MongoConnectionManager.disconnect()