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.
76 lines (75 loc) • 3.55 kB
TypeScript
import type { AttributeMappings, AppwriteConfig } from "appwrite-utils";
import type { ImportDataActions } from "../importDataActions.js";
import { RateLimitManager } from "./RateLimitManager.js";
/**
* Service responsible for file handling during import.
* Preserves all existing file handling capabilities including URL support.
* Extracted from DataLoader to provide focused, testable file operations.
*/
export declare class FileHandlerService {
private appwriteFolderPath;
private config;
private importDataActions;
private rateLimitManager;
constructor(appwriteFolderPath: string, config: AppwriteConfig, importDataActions: ImportDataActions, rateLimitManager?: RateLimitManager);
/**
* Generates attribute mappings with post-import actions based on the provided attribute mappings.
* This method checks each mapping for a fileData attribute and adds a post-import action to create a file
* and update the field with the file's ID if necessary.
*
* Preserves existing file handling logic from DataLoader.
*
* @param attributeMappings - The attribute mappings from the import definition.
* @param context - The context object containing information about the database, collection, and document.
* @param item - The item being imported, used for resolving template paths in fileData mappings.
* @returns The attribute mappings updated with any necessary post-import actions.
*/
getAttributeMappingsWithFileActions(attributeMappings: AttributeMappings, context: any, item: any): AttributeMappings;
/**
* Resolves local file path, searching in subdirectories if needed.
* Preserves existing file search logic from DataLoader.
*
* @param mappingFilePath - The relative file path from the mapping
* @returns Resolved absolute file path
*/
private resolveLocalFilePath;
/**
* Executes file-related post-import actions with rate limiting.
* Wraps the existing createFileAndUpdateField action with proper error handling and rate limiting.
*
* @param context - The context containing document and collection information
* @param postImportActions - The post-import actions to execute
*/
executeFileActions(context: any, postImportActions: any[]): Promise<void>;
/**
* Executes a single file action with proper error handling.
*
* @param action - The file action to execute
* @param context - The context for template resolution
*/
private executeFileAction;
/**
* Validates that file paths exist before import begins.
* Provides early validation to catch file issues before processing starts.
*
* @param attributeMappings - The attribute mappings to validate
* @param context - The context for template resolution
* @param item - The item for template resolution
* @returns Array of validation errors (empty if all valid)
*/
validateFilePaths(attributeMappings: AttributeMappings, context: any, item: any): string[];
/**
* Gets file statistics for import planning.
* Helps estimate import time and resource requirements.
*
* @param attributeMappings - The attribute mappings to analyze
* @param items - The items that will be imported
* @returns File statistics object
*/
getFileStatistics(attributeMappings: AttributeMappings, items: any[]): {
totalFiles: number;
urlFiles: number;
localFiles: number;
estimatedSize: number;
};
}