<commit_before>function defaultFormatQueryString(options) {
  if (!options) {
    return null;
  }

  const queryStringParts = Object.keys(options).map(
    key => `${encodeURI(key)}=${encodeURI(options[key])}`
  );
  return queryStringParts.join('&');
}

export default function generateApi(
  {
    urlFunc,
    formatQueryString = defaultFormatQueryString,
    preprocessors = [],
    postprocessors = []
  }
) {
  const {fetch, methodNames} = this;

  function doFetch(method, {id, data, options}) {
    const urlBase = urlFunc(id || '');
    const queryString = this.formatQueryString(options);
    const url = queryString ? `${urlBase}?${queryString}` : urlBase;

    const processorOptions = {id, ...options};

    let request = {method, body: data};
    preprocessors.forEach(function applyPreprocessor(preprocessor) {
      const newRequest = preprocessor(request, processorOptions);
      if (newRequest !== undefined) {
        request = newRequest;
      }
    });

    let result = this::fetch(url, request);
    postprocessors.forEach(function addPostprocessor(postprocessor) {
      result = result.then(function applyPostprocessor(response) {
        const newResponse = postprocessor(response, processorOptions);
        return newResponse !== undefined ? newResponse : response;
      });
    });

    return result;
  }

  return {
    formatQueryString,

    [methodNames.getMany](options) {
      return this::doFetch('GET', {options});
    },

    [methodNames.getSingle](id, options) {
      return this::doFetch('GET', {id, options});
    },

    [methodNames.postSingle](data, options) {
      return this::doFetch('POST', {data, options});
    },

    [methodNames.putSingle](id, data, options) {
      return this::doFetch('PUT', {id, data, options});
    },

    [methodNames.patchSingle](id, data, options) {
      return this::doFetch('PATCH', {id, data, options});
    },

    [methodNames.deleteSingle](id, options) {
      return this::doFetch('DELETE', {id, options});
    }
  };
}
<commit_msg>Set this object when invoking Fetch processors<commit_after>function defaultFormatQueryString(options) {
  if (!options) {
    return null;
  }

  const queryStringParts = Object.keys(options).map(
    key => `${encodeURI(key)}=${encodeURI(options[key])}`
  );
  return queryStringParts.join('&');
}

export default function generateApi(
  {
    urlFunc,
    formatQueryString = defaultFormatQueryString,
    preprocessors = [],
    postprocessors = []
  }
) {
  const {fetch, methodNames} = this;

  function doFetch(method, {id, data, options}) {
    const urlBase = urlFunc(id || '');
    const queryString = this.formatQueryString(options);
    const url = queryString ? `${urlBase}?${queryString}` : urlBase;

    const processorOptions = {id, ...options};

    let request = {method, body: data};
    preprocessors.forEach(preprocessor => {
      const newRequest = this::preprocessor(request, processorOptions);
      if (newRequest !== undefined) {
        request = newRequest;
      }
    });

    let result = this::fetch(url, request);
    postprocessors.forEach(postprocessor => {
      result = result.then(response => {
        const newResponse = this::postprocessor(response, processorOptions);
        return newResponse !== undefined ? newResponse : response;
      });
    });

    return result;
  }

  return {
    formatQueryString,

    [methodNames.getMany](options) {
      return this::doFetch('GET', {options});
    },

    [methodNames.getSingle](id, options) {
      return this::doFetch('GET', {id, options});
    },

    [methodNames.postSingle](data, options) {
      return this::doFetch('POST', {data, options});
    },

    [methodNames.putSingle](id, data, options) {
      return this::doFetch('PUT', {id, data, options});
    },

    [methodNames.patchSingle](id, data, options) {
      return this::doFetch('PATCH', {id, data, options});
    },

    [methodNames.deleteSingle](id, options) {
      return this::doFetch('DELETE', {id, options});
    }
  };
}

{'fraction_non_alphanumeric': 0.14903129657228018, 'fraction_numerical': 0.0, 'mean_word_length': 3.479421579532814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3453006', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1168, 'n_words': 247}