All files / core/src/utilities imageRetrieveMetadataProvider.ts

64.28% Statements 9/14
100% Branches 2/2
50% Functions 4/8
64.28% Lines 9/14

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50    428x   428x         428x                   18x                                 31341x 8282x 16678x 16678x         428x          
import { addProvider } from '../metaData';
 
const retrieveConfigurationState = new Map<string, unknown>();
 
const IMAGE_RETRIEVE_CONFIGURATION = 'imageRetrieveConfiguration';
 
/**
 * Simple metadataProvider object to store metadata for the image retrieval.
 */
const imageRetrieveMetadataProvider = {
  IMAGE_RETRIEVE_CONFIGURATION,
 
  /** Empty the metadata state */
  clear: () => {
    retrieveConfigurationState.clear();
  },
 
  /* Adding a new entry to the state object. */
  add: (key: string, payload): void => {
    retrieveConfigurationState.set(key, payload);
  },
 
  /** Get a copy of the current configuration state */
  clone: (): Map<string, unknown> => {
    return new Map(retrieveConfigurationState);
  },
 
  /** Restore the configuration state from a previously cloned state */
  restore: (state: Map<string, unknown>): void => {
    retrieveConfigurationState.clear();
    state.forEach((value, key) => {
      retrieveConfigurationState.set(key, value);
    });
  },
 
  get: (type: string, ...queries: string[]) => {
    if (type === IMAGE_RETRIEVE_CONFIGURATION) {
      return queries
        .map((query) => retrieveConfigurationState.get(query))
        .find((it) => it !== undefined);
    }
  },
};
 
addProvider(
  imageRetrieveMetadataProvider.get.bind(imageRetrieveMetadataProvider)
);
 
export default imageRetrieveMetadataProvider;