<commit_before>import queryString from 'qs';
import * as apiActions from '../modules/api';

function getDefaultHeaders() {
  return {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  };
}

function handleErrors(response) {
  if (!response.ok) {
    const error = new Error(response.statusText);
    error.status = response.status;
    throw error;
  }

  return response;
}

function handleResponse(response) {
  return response.json().then(({ data, included, meta }) => {
    return {
      resources: [data, ...included],
      result: Array.isArray(data) ? data.map((r) => r.id) : data.id,
      meta,
    };
  });
}

function createMiddleware(host, defaultHeaders = getDefaultHeaders()) {
  const getURL = (resource, params) => {
    let urlParts = [host];

    if (resource.type) urlParts = [urlParts, '/', resource.type];
    if (resource.id) urlParts = [urlParts, '/', resource.id];
    if (params) urlParts = [urlParts, '?', queryString.stringify(params)];

    return parts.join('');
  };

  const requestAction = (method, { resource, params, headers }) => {
    const url = getURL(resource, params);

    return fetch(url, {
      method,
      body: serialize(resource),
      headers: {
        ...defaultHeaders,
        ...headers,
      },
    }).then((response) => (
      handleErrors(response)
    )).then((response) => (
      handleResponse(response)
    ));
  };

  const requestActions = {
    [apiActions.GET]: (options) => requestAction('GET', options),
    [apiActions.POST]: (options) => requestAction('POST', options),
    [apiActions.PUT]: (options) => requestAction('PUT', options),
    [apiActions.PATCH]: (options) => requestAction('PATCH', options),
    [apiActions.DELETE]: (options) => requestAction('DELETE', options),
  };

  return (store) => (next) => (action) => {<commit_msg>Fix bug with parts not being defined<commit_after>import queryString from 'qs';
import * as apiActions from '../modules/api';

function getDefaultHeaders() {
  return {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  };
}

function handleErrors(response) {
  if (!response.ok) {
    const error = new Error(response.statusText);
    error.status = response.status;
    throw error;
  }

  return response;
}

function handleResponse(response) {
  return response.json().then(({ data, included, meta }) => {
    return {
      resources: [data, ...included],
      result: Array.isArray(data) ? data.map((r) => r.id) : data.id,
      meta,
    };
  });
}

function createMiddleware(host, defaultHeaders = getDefaultHeaders()) {
  const getURL = (resource, params) => {
    let urlParts = [host];

    if (resource.type) urlParts = [urlParts, '/', resource.type];
    if (resource.id) urlParts = [urlParts, '/', resource.id];
    if (params) urlParts = [urlParts, '?', queryString.stringify(params)];

    return urlParts.join('');
  };

  const requestAction = (method, { resource, params, headers }) => {
    const url = getURL(resource, params);

    return fetch(url, {
      method,
      body: serialize(resource),
      headers: {
        ...defaultHeaders,
        ...headers,
      },
    }).then((response) => (
      handleErrors(response)
    )).then((response) => (
      handleResponse(response)
    ));
  };

  const requestActions = {
    [apiActions.GET]: (options) => requestAction('GET', options),
    [apiActions.POST]: (options) => requestAction('POST', options),
    [apiActions.PUT]: (options) => requestAction('PUT', options),
    [apiActions.PATCH]: (options) => requestAction('PATCH', options),
    [apiActions.DELETE]: (options) => requestAction('DELETE', options),
  };

  return (store) => (next) => (action) => {
{'fraction_non_alphanumeric': 0.17358490566037735, 'fraction_numerical': 0.0, 'mean_word_length': 3.3607520564042304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '4515279', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1105, 'n_words': 252}