/** * @file client.ts * @description Centralized Dynamite client with multi-client support and table sync * @autor Miguel Alejandro * @fecha 2025-01-27 */ import { DynamoDBClient, DynamoDBClientConfig } from "@aws-sdk/client-dynamodb"; /** * Configuration for Dynamite client initialization */ export interface DynamiteConfig extends DynamoDBClientConfig { tables: Array any>; } /** * Centralized Dynamite client for managing DynamoDB connections and table synchronization */ export declare class Dynamite { private client; private tables; private connected; private synced; /** * Initialize Dynamite client with configuration * @param config Dynamite client configuration */ constructor(config: DynamiteConfig); /** * @description Configure the DynamoDB client. Does not create tables or GSIs -- use sync() for that. * @description Configura el cliente DynamoDB. No crea tablas ni GSIs -- usar sync() para eso. */ connect(): Promise; /** * @description Synchronize all tables, GSIs and pivot tables with DynamoDB. * @description Sincroniza tablas, GSIs y pivot tables con DynamoDB. */ sync(): Promise; /** * @description Poll DescribeTable until all GSIs on the given tables are ACTIVE. * @description Polling de DescribeTable hasta que todos los GSIs de las tablas dadas estén ACTIVE. */ private waitForActiveGSIs; /** * Ejecutar operaciones en una transacción atómica. * Si cualquier operación falla, todas se revierten automáticamente. * * @param callback Función que recibe el contexto de transacción * @returns Resultado del callback * * @example * await dynamite.tx(async (tx) => { * const user = await User.create({ name: "Juan" }, tx); * await Order.create({ user_id: user.id, total: 100 }, tx); * }); */ tx(callback: (tx: TransactionContext) => Promise): Promise; } /** * Set global client for Table class operations * @param client DynamoDB client instance */ export declare const setGlobalClient: (client: DynamoDBClient) => void; /** * Get global client for Table class operations */ export declare const getGlobalClient: () => DynamoDBClient; /** * Check if global client is available */ export declare const hasGlobalClient: () => boolean; /** * Require global client for Table operations (throws if not available) */ export declare const requireClient: () => DynamoDBClient; /** * @description Transaction context for grouping atomic operations. Max 100 operations (auto-chunked in batches of 25). * @description Contexto de transacción para operaciones atómicas. Máximo 100 operaciones (auto-divididas en lotes de 25). */ export declare class TransactionContext { private operations; private after_commit; private client; constructor(client: DynamoDBClient); addPut(table_name: string, item: Record, condition?: { expression: string; names: Record; }): void; addDelete(table_name: string, key: Record): void; addUpdate(table_name: string, key: Record, expression: string, names: Record, values: Record): void; /** * @description Register a callback (sync or async) to run after successful commit. * @description Registra un callback (síncrono o asíncrono) que se ejecuta después de un commit exitoso. */ onCommit(fn: () => void | Promise): void; commit(): Promise; private guard; }