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.

88 lines (87 loc) 3.34 kB
import { Client } from "node-appwrite"; import type { AppwriteConfig } from "appwrite-utils"; import type { DatabaseAdapter } from "../adapters/DatabaseAdapter.js"; /** * Factory for creating authenticated Appwrite clients and database adapters. * * This factory provides a clean separation of concerns by taking pre-configured * AppwriteConfig objects (with authentication already resolved by ConfigManager) * and creating the necessary client and adapter instances. * * Key features: * - Takes pre-authenticated config from ConfigManager * - Creates client with appropriate authentication method * - Creates adapter with automatic version detection * - Leverages AdapterFactory's internal caching for performance * * @example * ```typescript * const configManager = ConfigManager.getInstance(); * const config = await configManager.loadConfig(); * * // Config already has session or API key resolved * const { client, adapter } = await ClientFactory.createFromConfig(config); * ``` */ export declare class ClientFactory { /** * Create authenticated client and database adapter from configuration. * * This method expects the config to have authentication already resolved: * - Either `sessionCookie` is set (from ConfigManager's session loading) * - Or `appwriteKey` is set (from config file or CLI overrides) * * The ConfigManager handles all session discovery and authentication priority, * so this factory simply applies the resolved authentication to the client. * * @param config - AppwriteConfig with resolved authentication * @returns Object containing authenticated client and database adapter * @throws Error if no authentication method is available in config * * @example * ```typescript * const config = await ConfigManager.getInstance().loadConfig(); * const { client, adapter } = await ClientFactory.createFromConfig(config); * * // Client is now authenticated and ready to use * const databases = new Databases(client); * const collections = await adapter.listCollections(databaseId); * ``` */ static createFromConfig(config: AppwriteConfig): Promise<{ client: Client; adapter: DatabaseAdapter; }>; /** * Create client and adapter from individual parameters. * * This is a lower-level method for cases where you don't have a full * AppwriteConfig object. For most use cases, prefer createFromConfig(). * * @param endpoint - Appwrite endpoint URL * @param project - Appwrite project ID * @param options - Authentication and API mode options * @returns Object containing authenticated client and database adapter * @throws Error if no authentication method is provided * * @example * ```typescript * const { client, adapter } = await ClientFactory.create( * "https://cloud.appwrite.io/v1", * "my-project-id", * { * apiKey: "my-api-key", * apiMode: "auto" * } * ); * ``` */ static create(endpoint: string, project: string, options?: { apiKey?: string; sessionCookie?: string; apiMode?: "auto" | "legacy" | "tablesdb"; }): Promise<{ client: Client; adapter: DatabaseAdapter; }>; }