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.

130 lines (129 loc) 5.01 kB
import type { AppwriteConfig, Collection } from "appwrite-utils"; import { type YamlSessionOptions } from "../yamlConfig.js"; /** * Options for loading collections or tables */ export interface CollectionLoadOptions { /** * Whether to mark loaded items as coming from tables directory */ markAsTablesDir?: boolean; /** * Set of existing collection names to check for conflicts */ existingNames?: Set<string>; } /** * Service for loading and parsing Appwrite configuration files. * * Supports: * - YAML configuration files (.appwrite/config.yaml) * - TypeScript configuration files (appwriteConfig.ts) * - JSON project configuration files (appwrite.json) * - Collection and table YAML/TypeScript definitions * * Features: * - Auto-detects configuration file type * - Converts between different configuration formats * - Loads collections and tables from directories * - Handles session preservation * - Validates and normalizes configuration data */ export declare class ConfigLoaderService { /** * Normalizes function dirPath to absolute path * @param func Function configuration object * @param configDir Directory containing the config file * @returns Function with normalized dirPath */ private normalizeFunctionPath; /** * Loads configuration from a discovered path, auto-detecting the type * @param configPath Path to the configuration file * @param sessionOptions Optional session preservation options * @returns Parsed AppwriteConfig */ loadFromPath(configPath: string, sessionOptions?: YamlSessionOptions): Promise<AppwriteConfig>; /** * Loads a YAML configuration file * @param yamlPath Path to the YAML config file * @param sessionOptions Optional session preservation options * @returns Parsed AppwriteConfig */ loadYaml(yamlPath: string, sessionOptions?: YamlSessionOptions): Promise<AppwriteConfig>; /** * Loads a TypeScript configuration file * @param tsPath Path to the TypeScript config file * @returns Parsed AppwriteConfig */ loadTypeScript(tsPath: string): Promise<AppwriteConfig>; /** * Loads an appwrite.json project configuration file * Converts projectId → appwriteProject and detects API mode * @param jsonPath Path to the JSON config file * @returns Partial AppwriteConfig (requires merging with defaults) */ loadProjectConfig(jsonPath: string): Promise<Partial<AppwriteConfig>>; /** * Loads all collections from a collections/ directory * Supports both YAML (.yaml, .yml) and TypeScript (.ts) files * @param collectionsDir Path to the collections directory * @param options Loading options * @returns Array of loaded Collection objects */ loadCollections(collectionsDir: string, options?: CollectionLoadOptions): Promise<Collection[]>; /** * Loads all tables from a tables/ directory * Supports both YAML (.yaml, .yml) and TypeScript (.ts) files * @param tablesDir Path to the tables directory * @param options Loading options * @returns Array of loaded table objects */ loadTables(tablesDir: string, options?: CollectionLoadOptions): Promise<any[]>; /** * Loads collections and tables with conflict detection * Collections take priority over tables when names conflict * @param collectionsDir Path to collections directory * @param tablesDir Path to tables directory * @returns Object containing combined arrays and conflict information */ loadCollectionsAndTables(collectionsDir: string, tablesDir: string): Promise<{ items: Collection[]; fromCollections: number; fromTables: number; conflicts: Array<{ name: string; source1: string; source2: string; }>; }>; /** * Loads tables first (higher priority), then collections (backward compatibility) * Used for TablesDB projects (>= 1.8.0) * @param tablesDir Path to the tables directory * @param collectionsDir Path to the collections directory * @returns Loading result with items, counts, and conflicts */ loadTablesFirst(tablesDir: string, collectionsDir: string): Promise<{ items: Collection[]; fromCollections: number; fromTables: number; conflicts: Array<{ name: string; source1: string; source2: string; }>; }>; /** * Validates that a configuration file can be loaded * @param configPath Path to the configuration file * @returns True if the file can be loaded, false otherwise */ canLoadConfig(configPath: string): boolean; /** * Gets the type of a configuration file * @param configPath Path to the configuration file * @returns Configuration type or null if unknown */ getConfigType(configPath: string): "yaml" | "typescript" | "json" | null; }