/** * Command-line interface for converting Prisma schemas to JSON Schema and backfilling MongoDB collections. * * This CLI tool provides three main commands: * 1. `convert` - Convert Prisma schemas to JSON Schema files * 2. `backfill` - Backfill MongoDB collections with default values * 3. `generate-and-backfill` - Combined operation for schema generation and backfilling * * The CLI automatically discovers and parses all `.prisma` files in the specified directory, * combining them into a unified schema for processing. It provides colorized console output * and comprehensive error handling. * * @example * ```bash * # Convert Prisma schemas to JSON Schema files * npx prisma-json-schema convert --schema ./prisma --output ./schemas * * # Backfill MongoDB with default values * npx prisma-json-schema backfill --connection mongodb://localhost:27017 --database myapp * * # Process specific model only * npx prisma-json-schema backfill --model User --database myapp * * # Generate and backfill in one command * npx prisma-json-schema generate-and-backfill --schema ./prisma --database myapp * ``` */ export declare class PrismaMongoMigratorCLI { /** Commander.js program instance for CLI command management */ private program; /** Parsed Prisma schema containing models and enums */ private schema; /** JSON Schema generator instance for converting Prisma models */ private generator; /** * Creates a new CLI instance and sets up all available commands. */ constructor(); /** * Sets up all CLI commands with their options and descriptions. * * Configures three main commands: * - `convert`: Converts Prisma schemas to JSON Schema files * - `backfill`: Backfills MongoDB collections with default values * - `generate-and-backfill`: Combined operation for both tasks * * @private */ private setupCommands; /** * Loads and parses all Prisma schema files from the specified directory. * * This method: * 1. Recursively searches for `.prisma` files in the given path * 2. Excludes the `migrations` directory to avoid parsing migration files * 3. Combines all found schema files into a single schema string * 4. Parses the combined schema using PrismaSchemaParser * 5. Initializes the JSON Schema generator * 6. Provides detailed console output about discovered files and parsed content * * @private * @param schemaPath - Path to the directory containing Prisma schema files * @throws Exits the process with code 1 if no schema files are found or parsing fails * * @example * ```typescript * // For a directory structure: * // prisma/ * // schema.prisma * // models/ * // user.prisma * // post.prisma * // migrations/ (ignored) * // 001_init.sql * * this.loadSchemas("prisma"); * // Console output: * // Found 3 Prisma files: schema.prisma, user.prisma, post.prisma * // Parsed 5 models and 2 enums * ``` */ private loadSchemas; /** * Recursively searches for Prisma schema files in the specified directory. * * This method performs a deep search through the directory tree, collecting all * `.prisma` files while intelligently excluding certain directories like `migrations` * that typically contain SQL migration files rather than schema definitions. * * @private * @param schemaPath - Root directory to search for Prisma files * @returns Array of absolute file paths to discovered `.prisma` files, sorted alphabetically * @throws Exits the process with code 1 if directory reading fails * * @example * ```typescript * const files = this.findPrismaFiles("./prisma"); * // Returns: [ * // "/project/prisma/schema.prisma", * // "/project/prisma/models/user.prisma", * // "/project/prisma/models/post.prisma" * // ] * // Note: "./prisma/migrations/001_init.sql" would be excluded * ``` */ private findPrismaFiles; /** * Handles the `convert` command to generate JSON Schema files from Prisma models. * * This command: * 1. Loads and parses all Prisma schema files * 2. Creates the output directory if it doesn't exist * 3. Generates a JSON Schema file for each Prisma model * 4. Saves files with kebab-case naming convention * 5. Provides progress feedback for each generated file * * @private * @param options - Command options containing schema path and output directory * @returns Promise that resolves when all schemas are generated * * @example * ```bash * # Command usage: * npx prisma-json-schema convert --schema ./prisma --output ./json-schemas * * # Console output: * # Found 2 Prisma files: schema.prisma, models.prisma * # Parsed 3 models and 1 enums * # Converting 3 models to JSON Schema... * # Generated JSON Schema for User → json-schemas/user.json * # Generated JSON Schema for Post → json-schemas/post.json * # Generated JSON Schema for Comment → json-schemas/comment.json * # ✓ All schemas converted successfully! * ``` */ private convertCommand; /** * Handles the `backfill` command to update MongoDB collections with default values. * * This command: * 1. Loads and parses Prisma schemas * 2. Connects to the specified MongoDB database * 3. Generates JSON schemas for the models * 4. Runs backfill operations on MongoDB collections * 5. Supports processing all models or a specific model via the --model option * 6. Automatically derives database name from connection string if not specified * * @private * @param options - Command options containing connection details and model filter * @returns Promise that resolves when backfill operations complete * * @example * ```bash * # Backfill all models: * npx prisma-json-schema backfill --connection mongodb://localhost:27017 --database myapp * * # Backfill specific model only: * npx prisma-json-schema backfill --model User --database myapp * * # Use connection string database (if database="none"): * npx prisma-json-schema backfill --connection mongodb://localhost:27017/myapp --database none * ``` */ private backfillCommand; /** * Handles the `generate-and-backfill` command for combined schema generation and backfilling. * * This command combines the functionality of both `convert` and `backfill` commands, * but generates schemas in memory rather than writing them to files. This is optimized * for scenarios where you want to backfill collections immediately without persisting * the JSON schema files. * * The command: * 1. Loads and parses Prisma schemas * 2. Generates JSON schemas in memory for each model * 3. Immediately uses those schemas to backfill MongoDB collections * 4. Supports model filtering via the --model option * 5. Provides the same database name resolution as the backfill command * * @private * @param options - Command options containing paths, connection details, and filters * @returns Promise that resolves when generation and backfill operations complete * * @example * ```bash * # Generate and backfill all models: * npx prisma-json-schema generate-and-backfill --schema ./prisma --database myapp * * # Process specific model only: * npx prisma-json-schema generate-and-backfill --model User --database myapp * * # Custom connection and schema path: * npx prisma-json-schema generate-and-backfill \ * --schema ./backend/prisma \ * --connection mongodb://user:pass@localhost:27017 \ * --database production * ``` */ private generateAndBackfillCommand; /** * Starts the CLI program and processes command-line arguments. * * This method should be called to begin CLI execution. It parses the command-line * arguments and executes the appropriate command handler based on user input. * * @example * ```typescript * const cli = new PrismaMongoMigratorCLI(); * cli.run(); // Processes process.argv and executes the requested command * ``` */ run(): void; } //# sourceMappingURL=cli.d.ts.map