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.
64 lines (63 loc) • 3.76 kB
TypeScript
import { type Models } from "node-appwrite";
import type { CollectionImportData } from "../migrations/dataLoader.js";
import type { ConfigCollection } from "appwrite-utils";
export declare const toPascalCase: (str: string) => string;
export declare const toCamelCase: (str: string) => string;
export declare const ensureDirectoryExistence: (filePath: string) => true | undefined;
export declare const writeFileSync: (filePath: string, content: string, options: {
flag: string;
}) => void;
export declare const readFileSync: (filePath: string) => string;
export declare const existsSync: (filePath: string) => boolean;
export declare const mkdirSync: (filePath: string) => void;
export declare const readdirSync: (filePath: string) => string[];
export declare const areCollectionNamesSame: (a: string, b: string) => boolean;
/**
* Generates the view URL for a specific file based on the provided endpoint, project ID, bucket ID, file ID, and optional JWT token.
*
* @param {string} endpoint - the base URL endpoint
* @param {string} projectId - the ID of the project
* @param {string} bucketId - the ID of the bucket
* @param {string} fileId - the ID of the file
* @param {Models.Jwt} [jwt] - optional JWT token generated via the Appwrite SDK
* @return {string} the generated view URL for the file
*/
export declare const getFileViewUrl: (endpoint: string, projectId: string, bucketId: string, fileId: string, jwt?: Models.Jwt) => string;
/**
* Generates a download URL for a file based on the provided endpoint, project ID, bucket ID, file ID, and optionally a JWT.
*
* @param {string} endpoint - The base URL endpoint.
* @param {string} projectId - The ID of the project.
* @param {string} bucketId - The ID of the bucket.
* @param {string} fileId - The ID of the file.
* @param {Models.Jwt} [jwt] - Optional JWT object for authentication with Appwrite.
* @return {string} The complete download URL for the file.
*/
export declare const getFileDownloadUrl: (endpoint: string, projectId: string, bucketId: string, fileId: string, jwt?: Models.Jwt) => string;
export declare const finalizeByAttributeMap: (appwriteFolderPath: string, collection: ConfigCollection, item: CollectionImportData["data"][number]) => Promise<any>;
export declare let numTimesFailedTotal: number;
/**
* Tries to execute the given createFunction and retries up to 5 times if it fails.
* Only retries on transient errors (network failures, 5xx errors). Does NOT retry validation errors (4xx).
*
* @param {() => Promise<any>} createFunction - The function to be executed.
* @param {number} [attemptNum=0] - The number of attempts made so far (default: 0).
* @return {Promise<any>} - A promise that resolves to the result of the createFunction or rejects with an error if it fails after 5 attempts.
*/
export declare const tryAwaitWithRetry: <T>(createFunction: () => Promise<T>, attemptNum?: number, throwError?: boolean) => Promise<T>;
export declare const getAppwriteClient: (endpoint: string, projectId: string, apiKey: string) => import("node-appwrite").Client;
export declare const delay: (ms: number) => Promise<unknown>;
/**
* Calculates exponential backoff delay with configurable base and maximum
*
* @param retryCount - Current retry attempt number (0-indexed)
* @param baseDelay - Base delay in milliseconds (default: 2000)
* @param maxDelay - Maximum delay cap in milliseconds (default: 30000)
* @returns Calculated delay in milliseconds
*
* @example
* calculateExponentialBackoff(0) // Returns 2000
* calculateExponentialBackoff(1) // Returns 4000
* calculateExponentialBackoff(5) // Returns 30000 (capped)
*/
export declare const calculateExponentialBackoff: (retryCount: number, baseDelay?: number, maxDelay?: number) => number;