interface BatchWriterParams { /** * The maximum number of items to hold in memory * before flushing to the database. * @required */ batch_size: number; /** * How long, in milliseconds, data should be kept in memory before * flushing to the database. If this feature is enabled, a flush will * be triggered even if the batch is not full. Disabled by default. * @default disabled */ batch_timeout?: number; /** * How long to wait, in milliseconds, after the last write operation * before flushing the data to the database. This can be used to prevent * items staying in memory for too long if the batch size is not reached * frequently enough. Disabled by default. * @default disabled */ idle_timeout?: number; /** * The insert function to use for inserting data into the batch. * @required */ insertFn: (data: T[]) => Promise; /** * Maximum number of retries for transient insert errors. * @default 3 */ max_retries?: number; /** * Base delay in milliseconds for exponential backoff. * @default 1000 */ retry_base_delay_ms?: number; /** * The title of this BatchWriter instance, * used to identify the source of the logs. * @required */ title: string; } export declare class BatchWriter { private params; private dataBucketAlwaysAvailable; private dataBucketFlushOps; private batchTimeoutTimer; private idleTimeoutTimer; private sessionTimer; private flushInProgress; constructor(params: BatchWriterParams); /** * Flushes the current batch of data. * This method is called internally when the batch size or timeouts are reached, * but can also be called manually if needed. * @param callback Optional callback to execute after the flush is complete, receiving the flushed data as a parameter */ flush(callback?: (data?: T[]) => Promise): Promise; /** * Timer-triggered flush that guarantees the buffer is emptied even when a * flush was already in progress. If the guarded flush() coalesced into a * running flush, data written during that flush would strand on an idle tail * (timers are cleared at flush start and only re-armed by the next write()). * Re-flush while data remains and no timer is pending. */ private drain; private runFlush; /** * Helper method to perform insert operations with retry logic for transient errors. * This method will attempt to insert the data using the provided insert function, * and if an error occurs, it will retry the operation with exponential backoff * until the maximum number of retries is reached. * @param data The data to insert. * @returns A promise that resolves when the insert operation is successful, or rejects if all retries fail. */ private insertWithRetry; /** * Write data to the batch. * @param data The data to write. * @param options Options for the write operation (reserved for future use). * @param writeCallback Callback function to call after the write operation is complete. * @param flushCallback Callback function to call after the flush operation is complete. */ write(data: T | T[], { flushCallback, writeCallback }?: { flushCallback?: (data?: T[]) => Promise; writeCallback?: () => Promise; }): Promise; } export {};