All files / dicomImageLoader/src/imageLoader/internal getRetrieveValue.ts

0% Statements 0/5
0% Branches 0/2
0% Functions 0/1
0% Lines 0/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                                                           
import metaDataManager from '../wadors/metaDataManager';
 
/**
 * Reads a retrieve option that may be given either as a value or as a callback
 * computing it from the image's metadata.
 *
 * `chunkSize` and `initialChunkSize` are both declared as
 * `number | ((metadata) => number)`, so every reader has to resolve the
 * callback form before using the result as a number - otherwise the function
 * itself flows into the arithmetic and silently produces NaN comparisons.
 */
export default function getRetrieveValue<T>(
  imageId: string,
  // The retrieve option interfaces have no index signature, and the deprecated
  // `minChunkSize` is not declared on them at all, so this reads them loosely
  // rather than making every call site cast.
  src: unknown,
  attr: string
): T {
  const value = (src as Record<string, unknown> | undefined)?.[attr];
 
  if (typeof value !== 'function') {
    return value as T;
  }
 
  const metaData = metaDataManager.get(imageId);
 
  return value(metaData, imageId) as T;
}