/*! * Copyright 2025 Cognite AS */ /** * Generic batch loader for accumulating and processing requests in batches. * This prevents overwhelming APIs with thousands of individual requests by grouping them. * * Example use cases: * - Batching DMS queries for multiple 360 image collections * - Batching CDF Events/Files API calls for event-based 360 images * - Batching point cloud data fetching * * @template TIdentifier - Type of the identifier used to request data (e.g., DMInstanceRef, string) * @template TResult - Type of the result returned for each identifier */ export declare abstract class BatchLoader { private readonly _batchSize; private readonly _batchDelayMs; private readonly _pendingBatch; private _batchTimer; private _isProcessing; /** * @param _batchSize - Maximum number of identifiers to process in a single batch * @param _batchDelayMs - Delay in milliseconds to wait for more requests before executing batch */ constructor(_batchSize: number, _batchDelayMs: number); /** * Load data for the given identifier. Requests are automatically batched. * * @param identifier - The identifier to load data for * @returns Promise that resolves with the result for this identifier */ load(identifier: TIdentifier): Promise; /** * Try to execute a batch. If already processing, this will be a no-op. * The next batch will be picked up when the current one finishes. */ private tryExecuteBatch; /** * Execute a batch of requests. */ private executeBatch; /** * Fetch data for a batch of identifiers. This is where the actual API calls happen. * * @param identifiers - Array of identifiers to fetch data for * @returns Map of key to result, where key is generated by getKeyForIdentifier */ protected abstract fetchBatch(identifiers: TIdentifier[]): Promise>; /** * Convert an identifier to a string key for mapping results. * This key is used to match requests with their results. * * @param identifier - The identifier to convert * @returns String key uniquely identifying this identifier */ protected abstract getKeyForIdentifier(identifier: TIdentifier): string; /** * Get the default result when an identifier is not found in the batch results. * This is called when fetchBatch doesn't return a result for a given identifier. * * @param identifier - The identifier that wasn't found * @returns Default result to return */ protected abstract getDefaultResult(identifier: TIdentifier): TResult; }