UNPKG

adonis-odm

Version:

A comprehensive MongoDB ODM for AdonisJS with Lucid-style API, type-safe relationships, embedded documents, and transaction support

202 lines 6.25 kB
import type { MongoDatabaseManager } from '../database_manager.js'; import type { OdmConfig, SeederConfig } from '../types/index.js'; /** * Options for running seeders */ export interface SeederRunOptions { /** Specific files to run */ files?: string[]; /** Connection name to use */ connection?: string; /** Environment to check against */ environment?: string; /** Whether to run in interactive mode */ interactive?: boolean; } /** * Seeder execution result */ export interface SeederResult { /** Name of the seeder */ name: string; /** File path of the seeder */ filePath: string; /** Whether the seeder was executed */ executed: boolean; /** Execution time in milliseconds */ executionTime?: number; /** Error if execution failed */ error?: Error; /** Reason for skipping (if not executed) */ skipReason?: string; } /** * Seeder Manager * * Manages the discovery, loading, and execution of database seeders. * Provides functionality to run seeders individually or in batches, * with support for environment filtering and connection-specific execution. */ export declare class SeederManager { private client; private seederConfig; private config; constructor(config: OdmConfig, client: MongoDatabaseManager); /** * Run seeders based on the provided options * * @param options - Options for running seeders * @returns Array of seeder execution results */ run(options?: SeederRunOptions): Promise<SeederResult[]>; /** * Run a specific seeder file * * @param filePath - Path to the seeder file * @param connection - Connection name to use * @param environment - Environment to check against * @returns Seeder execution result */ runFile(filePath: string, connection?: string, environment?: string): Promise<SeederResult>; /** * Get all seeder files from configured paths * * @returns Array of seeder file paths ordered by execution order and dependencies */ getSeederFiles(): Promise<string[]>; /** * Load a seeder class from a file path * * @param filePath - Path to the seeder file * @returns The seeder class constructor */ private loadSeeder; /** * Check if a seeder should run in the current environment * * @param SeederClass - The seeder class * @param environment - Current environment * @returns True if the seeder should run */ private shouldRunInEnvironment; /** * Discover seeder files in a directory recursively * * @param dirPath - Directory path to search * @returns Array of seeder file paths */ private discoverSeederFiles; /** * Check if a file is a valid seeder file * * @param filePath - File path to check * @returns True if the file is a seeder file */ private isSeederFile; /** * Extract seeder name from file path * * @param filePath - File path * @returns Seeder name */ private getSeederNameFromPath; /** * Validate that a connection name exists in the configuration * * @param connectionName - Name of the connection to validate * @throws Error if connection is not found */ private validateConnection; /** * Verify that a connection is available and established * * @param connectionName - Name of the connection to verify * @throws Error if connection is not available */ private verifyConnectionAvailability; /** * Enhance error messages with connection context * * @param error - Original error * @param connectionName - Connection name being used * @returns Enhanced error with connection context */ private enhanceConnectionError; /** * Get all available connection names * * @returns Array of connection names */ getAvailableConnections(): string[]; /** * Check if a connection name is valid * * @param connectionName - Connection name to check * @returns True if connection exists in configuration */ isValidConnection(connectionName: string): boolean; /** * Get seeder configuration * * @returns Current seeder configuration */ getConfig(): Required<SeederConfig>; /** * Get ordered seeders based on execution order and dependencies * * @param files - Array of seeder file paths * @returns Array of ordered seeder file paths */ private getOrderedSeeders; /** * Get metadata from a seeder class * * @param filePath - Path to the seeder file * @returns Seeder metadata */ private getSeederMetadata; /** * Check if an error is a loading error (syntax, import, etc.) vs validation error * * @param error - The error to check * @returns True if this is a loading error that should be handled gracefully */ private isLoadingError; /** * Check if a file is a main seeder (index.ts or main.ts) * * @param filePath - Path to the seeder file * @returns True if this is a main seeder file */ private isMainSeederFile; /** * Resolve dependency order using topological sorting * * @param seeders - Array of seeders with metadata * @returns Array of ordered seeder file paths */ private resolveDependencyOrder; /** * Validate seeder dependencies * * @param seeders - Array of seeders with metadata * @param seederMap - Map of class names to seeders */ private validateDependencies; /** * Detect circular dependencies in seeders * * @param seeders - Array of seeders with metadata * @param seederMap - Map of class names to seeders */ private detectCircularDependencies; /** * Perform global topological sort considering both order and dependencies * * @param seeders - Array of all seeders to sort * @param seederMap - Map of all seeders for dependency lookup * @returns Array of ordered seeder file paths */ private globalTopologicalSort; } //# sourceMappingURL=seeder_manager.d.ts.map