UNPKG

appwrite-utils-cli

Version:

Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.

98 lines (97 loc) 3.4 kB
import { type Databases, type Models, type Storage } from "node-appwrite"; import type { AppwriteConfig } from "appwrite-utils"; import { type RateLimitConfig } from "./RateLimitManager.js"; import type { ImportDataActions } from "../importDataActions.js"; import type { SetupOptions } from "../../utilsController.js"; /** * Orchestrator for the entire import process. * Coordinates all services while preserving existing functionality and performance characteristics. * * This replaces the monolithic ImportController and DataLoader with a cleaner, modular architecture. */ export declare class ImportOrchestrator { private config; private database; private storage; private appwriteFolderPath; private setupOptions; private databasesToRun; private dataTransformationService; private fileHandlerService; private userMappingService; private validationService; private relationshipResolver; private rateLimitManager; private importMap; private collectionImportOperations; private hasImportedUsers; private batchLimit; constructor(config: AppwriteConfig, database: Databases, storage: Storage, appwriteFolderPath: string, importDataActions: ImportDataActions, setupOptions: SetupOptions, databasesToRun?: Models.Database[], rateLimitConfig?: Partial<RateLimitConfig>); /** * Main entry point for the import process. * Preserves existing import flow while using the new modular architecture. */ run(specificCollections?: string[]): Promise<void>; /** * Performs the complete import process for a single database. */ private performDatabaseImport; /** * Sets up import maps and operation tracking. * Preserves existing setup logic from DataLoader. */ private setupImportMaps; /** * Loads existing users and initializes user mapping service. */ private loadExistingUsers; /** * Loads and prepares data for all collections. */ private loadAndPrepareData; /** * Prepares data for a regular collection. * Uses the DataTransformationService for all transformations. */ private prepareCollectionData; /** * Prepares data for user collection with deduplication. * Uses the UserMappingService for sophisticated user handling. */ private prepareUserCollectionData; /** * Imports collections with rate limiting and batch processing. * Preserves existing import logic with enhanced error handling. */ private importCollections; /** * Imports a single collection with batching and rate limiting. */ private importSingleCollection; /** * Imports a single item with error handling. */ private importSingleItem; /** * Helper method to generate consistent collection keys. */ private getCollectionKey; /** * Loads data from file based on import definition. */ private loadDataFromFile; /** * Creates batches for processing with the specified batch size. */ private createBatches; /** * Generates a unique ID for documents. */ private generateUniqueId; private findExistingCollection; private updateOperationStatus; private importUsersCollection; private prepareUpdateData; private executePostImportActions; private transferDataBetweenDatabases; }