{ "module": "mongo_ops.registry", "content": { "path": "mongo_ops.registry", "docstring": "Model registration for multi-service initialization.", "objects": { "Dict": { "name": "Dict", "kind": "alias", "path": "mongo_ops.registry.Dict", "signature": "", "docstring": null }, "List": { "name": "List", "kind": "alias", "path": "mongo_ops.registry.List", "signature": "", "docstring": null }, "Optional": { "name": "Optional", "kind": "alias", "path": "mongo_ops.registry.Optional", "signature": "", "docstring": null }, "Type": { "name": "Type", "kind": "alias", "path": "mongo_ops.registry.Type", "signature": "", "docstring": null }, "AsyncIOMotorDatabase": { "name": "AsyncIOMotorDatabase", "kind": "alias", "path": "mongo_ops.registry.AsyncIOMotorDatabase", "signature": "", "docstring": null }, "CacheBackend": { "name": "CacheBackend", "kind": "class", "path": "mongo_ops.registry.CacheBackend", "signature": "", "docstring": null, "members": { "get": { "name": "get", "kind": "function", "path": "mongo_ops.registry.CacheBackend.get", "signature": "", "docstring": null }, "set": { "name": "set", "kind": "function", "path": "mongo_ops.registry.CacheBackend.set", "signature": "", "docstring": null }, "delete": { "name": "delete", "kind": "function", "path": "mongo_ops.registry.CacheBackend.delete", "signature": "", "docstring": null }, "exists": { "name": "exists", "kind": "function", "path": "mongo_ops.registry.CacheBackend.exists", "signature": "", "docstring": null }, "clear_pattern": { "name": "clear_pattern", "kind": "function", "path": "mongo_ops.registry.CacheBackend.clear_pattern", "signature": "", "docstring": null }, "get_stats": { "name": "get_stats", "kind": "function", "path": "mongo_ops.registry.CacheBackend.get_stats", "signature": "", "docstring": null }, "initialize": { "name": "initialize", "kind": "function", "path": "mongo_ops.registry.CacheBackend.initialize", "signature": "", "docstring": null }, "shutdown": { "name": "shutdown", "kind": "function", "path": "mongo_ops.registry.CacheBackend.shutdown", "signature": "", "docstring": null } } }, "MongoConnectionManager": { "name": "MongoConnectionManager", "kind": "class", "path": "mongo_ops.registry.MongoConnectionManager", "signature": "", "docstring": "Manages MongoDB connections with async lifecycle.\n\nThis class provides a singleton-like manager for the MongoDB client and \ndatabase instances, ensuring they are properly initialized and closed \nacross the application lifecycle.", "members": { "connect": { "name": "connect", "kind": "function", "path": "mongo_ops.registry.MongoConnectionManager.connect", "signature": "", "docstring": "Connect to MongoDB and initialize the shared client.\n\nArgs:\n uri: MongoDB connection URI (e.g., \"mongodb://localhost:27017\").\n db_name: Name of the database to use.\n **kwargs: Additional Motor client options (e.g., maxPoolSize).\n\nReturns:\n AsyncIOMotorDatabase: The initialized database instance." }, "disconnect": { "name": "disconnect", "kind": "function", "path": "mongo_ops.registry.MongoConnectionManager.disconnect", "signature": "", "docstring": "Close the active MongoDB connection and cleanup resources." }, "get_database": { "name": "get_database", "kind": "function", "path": "mongo_ops.registry.MongoConnectionManager.get_database", "signature": "", "docstring": "Retrieve the current database instance.\n\nReturns:\n AsyncIOMotorDatabase: The active database instance.\n\nRaises:\n RuntimeError: If connect() has not been called yet." }, "get_client": { "name": "get_client", "kind": "function", "path": "mongo_ops.registry.MongoConnectionManager.get_client", "signature": "", "docstring": "Retrieve the current client instance.\n\nReturns:\n AsyncIOMotorClient: The active Motor client instance.\n\nRaises:\n RuntimeError: If connect() has not been called yet." }, "lifespan": { "name": "lifespan", "kind": "function", "path": "mongo_ops.registry.MongoConnectionManager.lifespan", "signature": "", "docstring": "Async context manager for managing connection lifecycle.\n\nDesigned for use with FastAPI or other frameworks supporting \nlifespan management.\n\nArgs:\n uri: MongoDB connection URI.\n db_name: Name of the database.\n **kwargs: Additional Motor client options.\n\nYields:\n AsyncIOMotorDatabase: The active database instance.\n\nUsage:\n @asynccontextmanager\n async def lifespan(app: FastAPI):\n async with MongoConnectionManager.lifespan(uri, db_name):\n yield" } } }, "BaseDocument": { "name": "BaseDocument", "kind": "class", "path": "mongo_ops.registry.BaseDocument", "signature": "", "docstring": "Base document class with common MongoDB fields.\n\nInherit from this class to create Pydantic models that represent \nMongoDB documents. It includes automatic handling of the `_id` field \nand timestamps.\n\nAttributes:\n id: The MongoDB document ID (aliased to `_id`).\n created_at: Timestamp when the document was created.\n updated_at: Timestamp when the document was last updated.", "members": { "id": { "name": "id", "kind": "attribute", "path": "mongo_ops.registry.BaseDocument.id", "signature": "", "docstring": null }, "created_at": { "name": "created_at", "kind": "attribute", "path": "mongo_ops.registry.BaseDocument.created_at", "signature": "", "docstring": null }, "updated_at": { "name": "updated_at", "kind": "attribute", "path": "mongo_ops.registry.BaseDocument.updated_at", "signature": "", "docstring": null }, "Config": { "name": "Config", "kind": "class", "path": "mongo_ops.registry.BaseDocument.Config", "signature": "", "docstring": null, "members": { "populate_by_name": { "name": "populate_by_name", "kind": "attribute", "path": "mongo_ops.registry.BaseDocument.Config.populate_by_name", "signature": "", "docstring": null }, "arbitrary_types_allowed": { "name": "arbitrary_types_allowed", "kind": "attribute", "path": "mongo_ops.registry.BaseDocument.Config.arbitrary_types_allowed", "signature": "", "docstring": null }, "json_encoders": { "name": "json_encoders", "kind": "attribute", "path": "mongo_ops.registry.BaseDocument.Config.json_encoders", "signature": "", "docstring": null }, "json_schema_extra": { "name": "json_schema_extra", "kind": "attribute", "path": "mongo_ops.registry.BaseDocument.Config.json_schema_extra", "signature": "", "docstring": null } } } } }, "ModelRegistry": { "name": "ModelRegistry", "kind": "class", "path": "mongo_ops.registry.ModelRegistry", "signature": "", "docstring": "Registry for managing multiple models and their collections.\n\nThis registry allows central management of collections and their \nassociated indexes, making it easier to perform mass initialization \nat application startup.", "members": { "register": { "name": "register", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.register", "signature": "", "docstring": "Register a model with its collection and indexes.\n\nArgs:\n collection_name: Name of the MongoDB collection.\n model: Document model class (subclass of BaseDocument).\n indexes: List of index specifications (e.g., [(\"email\", 1)]).\n\nUsage:\n ModelRegistry.register(\n \"users\",\n UserDocument,\n indexes=[(\"email\", 1), (\"created_at\", -1)]\n )" }, "initialize_all": { "name": "initialize_all", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.initialize_all", "signature": "", "docstring": "Initialize all registered collections and create indexes.\n\nThis method should be called during application startup to ensure \nall necessary indexes exist in the database.\n\nArgs:\n db: Database instance. If not provided, uses the global database \n from MongoConnectionManager." }, "get_model": { "name": "get_model", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.get_model", "signature": "", "docstring": "Retrieve a registered model by its collection name.\n\nArgs:\n collection_name: The name of the collection.\n\nReturns:\n Type[BaseDocument]: The registered model class.\n\nRaises:\n KeyError: If the model for the given collection is not registered." }, "list_collections": { "name": "list_collections", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.list_collections", "signature": "", "docstring": "List all registered collection names.\n\nReturns:\n List[str]: A list of collection names." }, "get_cache_backend": { "name": "get_cache_backend", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.get_cache_backend", "signature": "", "docstring": "Get the registered cache backend instance.\n\nReturns:\n Optional[CacheBackend]: The cache backend, if registered." }, "set_cache_backend": { "name": "set_cache_backend", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.set_cache_backend", "signature": "", "docstring": "Register a cache backend for all cache-enabled repositories.\n\nShould be called after MongoDB connection is established,\nbefore cache-backed repositories are used.\n\nArgs:\n backend: A CacheBackend instance (InMemoryCacheBackend\n or RedisCacheBackend)." }, "initialize_cache": { "name": "initialize_cache", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.initialize_cache", "signature": "", "docstring": "Initialize the registered cache backend.\n\nMust be called after set_cache_backend() and before any\ncache-backed repository operations. Typically called right\nafter MongoDB connection is established.\n\nRaises:\n RuntimeError: If no cache backend has been registered." }, "shutdown_cache": { "name": "shutdown_cache", "kind": "function", "path": "mongo_ops.registry.ModelRegistry.shutdown_cache", "signature": "", "docstring": "Shutdown the registered cache backend gracefully.\n\nShould be called during application shutdown to clean up\nbackground tasks (e.g., in-memory TTL cleanup)." } } } } } }