import { Schema, Connection } from 'mongoose'; /** * Schema registration entry * Stores schema information for lazy model registration on tenant connections */ export interface SchemaRegistration { name: string; schema: Schema; collection: string | null; } /** * Global registry for schemas that need to be registered on tenant connections * * This solves the "Schema hasn't been registered for model" error that occurs when: * 1. A model (e.g., Account) has a ref to another model (e.g., Employee) * 2. The Account model is created on a tenant connection * 3. The Account schema has pre-hooks that auto-populate the ref * 4. Mongoose can't find the Employee model because it wasn't registered on that connection * * By registering all schemas in this registry, we can ensure that when any model * is created on a connection, all dependent models are also registered. */ declare class ModelRegistryClass { private schemas; private registeredConnections; /** * Register a schema in the global registry * Called by BaseRepository constructor */ register(name: string, schema: Schema, collection: string | null): void; /** * Get all registered schema names */ getRegisteredNames(): string[]; /** * Check if a model name is registered */ isRegistered(name: string): boolean; /** * Get a registered schema by name */ getSchema(name: string): SchemaRegistration | undefined; /** * Ensure all registered schemas are available as models on the given connection * This is called before any query operation that might use populate * * @param connection - The mongoose connection * @param currentModelName - The model initiating the request (to skip re-registering) */ ensureModelsOnConnection(connection: Connection, currentModelName?: string): void; /** * Clear the registration tracking for a connection * Called when a connection is closed or recreated */ clearConnectionTracking(connection: Connection): void; /** * Get count of registered schemas */ get size(): number; /** * Clear all registrations (useful for testing) */ clear(): void; } export declare const ModelRegistry: ModelRegistryClass; export {};