<commit_before>export const dedup = () => ({ apiFnName, apiFn }) => {
  if (apiFn.operation !== 'READ') {
    return apiFn;
  }
}<commit_msg>Implement dedup<commit_after>const toKey = (args) => JSON.stringify(args);

export const dedup = () => ({ apiFn }) => {
  if (apiFn.operation !== 'READ') { return apiFn; }
  const cache = {};

  return (...args) => {
    const key = toKey(args);
    const cached = cache[key];
    if (cached) { return cached; }

    const promise = apiFn(...args);
    cache[key] = promise;
    return promise.then((res) => {
      delete cache[key];
      return res;
    });
  };
};
{'fraction_non_alphanumeric': 0.1921182266009852, 'fraction_numerical': 0.0, 'mean_word_length': 2.935483870967742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1412735', 'n_tokens_mistral': 205, 'n_tokens_neox': 202, 'n_words': 49}