<commit_before>import { List, Record, Map } from 'immutable';

import doExecuteRequest from '../gettable/RequestExecutor';
import { awaitingResponse, receiveResponse, receiveError } from './response';
import { readProject } from '../utils/projectUtils';

export const UPSERT_PROJECT = 'UPSERT_PROJECT';
export const CLOSE_PROJECT = 'CLOSE_PROJECT';
export const ADD_REQUEST = 'ADD_REQUEST';
export const UPDATE_REQUEST = 'UPDATE_REQUEST';
export const DELETE_REQUEST = 'DELETE_REQUEST';
export const EXECUTE_REQUEST = 'EXECUTE_REQUEST';

export const Request = Record({
  id: undefined,
  projectId: undefined,
  name: undefined,
  method: undefined,
  url: undefined,
  body: undefined,
  headers: new Map()
});

export const Project = Record({
  id: undefined,
  name: undefined,
  path: undefined,
  requests: new List()
});

function randomId() {
  return Math.random().toString(32).slice(2).substr(0, 5);
}

export function upsertProject(projectPath) {
  return dispatch => {
    readProject(projectPath).then((project) => {
      const requests = project.requests.map(r => {
        r.projectId = project.id;
        return r;
      });

      dispatch({
        type: UPSERT_PROJECT,
        project: {
          path: projectPath,
          id: project.id,
          name: project.name,
          requests: requests
        }
      });
    });
  };
}

export function newProject(path, name) {
  return {
    type: UPSERT_PROJECT,
    project: {
      id: randomId(),
      path: `${path}/${name}.json`,
      name: name,
      requests: []
    }
  }
}

export function closeProject(project) {
  return {
    type: CLOSE_PROJECT,
    project: project
  }
}

export function addRequest(request, projectId) {
  const newRequest = request.set('id', randomId()).set('projectId', projectId);

  return {
    type: ADD_REQUEST,
    projectId: projectId,
    request: newRequest
  }
}

export function updateRequest(request) {
  return {
    type: UPDATE_REQUEST,
    request: request
  }
}

export function deleteRequest(request) {
  return {
    type: DELETE_REQUEST,
    request: request
  }
}

export function executeRequest(method:string, url:string, headers:Object, body:?string) {
  return dispatch => {
    dispatch(awaitingResponse());

    doExecuteRequest(method, url, headers, body).then((response) => {
      dispatch(receiveResponse(response));
    }).catch((error) => {
      dispatch(receiveError(error));
    });
  };
}
<commit_msg>Join paths using path.join for cross platform compatibility<commit_after>import { List, Record, Map } from 'immutable';
const nodePath = require('path');

import doExecuteRequest from '../gettable/RequestExecutor';
import { awaitingResponse, receiveResponse, receiveError } from './response';
import { readProject } from '../utils/projectUtils';

export const UPSERT_PROJECT = 'UPSERT_PROJECT';
export const CLOSE_PROJECT = 'CLOSE_PROJECT';
export const ADD_REQUEST = 'ADD_REQUEST';
export const UPDATE_REQUEST = 'UPDATE_REQUEST';
export const DELETE_REQUEST = 'DELETE_REQUEST';
export const EXECUTE_REQUEST = 'EXECUTE_REQUEST';

export const Request = Record({
  id: undefined,
  projectId: undefined,
  name: undefined,
  method: undefined,
  url: undefined,
  body: undefined,
  headers: new Map()
});

export const Project = Record({
  id: undefined,
  name: undefined,
  path: undefined,
  requests: new List()
});

function randomId() {
  return Math.random().toString(32).slice(2).substr(0, 5);
}

export function upsertProject(projectPath) {
  return dispatch => {
    readProject(projectPath).then((project) => {
      const requests = project.requests.map(r => {
        r.projectId = project.id;
        return r;
      });

      dispatch({
        type: UPSERT_PROJECT,
        project: {
          path: projectPath,
          id: project.id,
          name: project.name,
          requests: requests
        }
      });
    });
  };
}

export function newProject(path, name) {
  return {
    type: UPSERT_PROJECT,
    project: {
      id: randomId(),
      path: nodePath.join(path, `${name}.json`),
      name: name,
      requests: []
    }
  }
}

export function closeProject(project) {
  return {
    type: CLOSE_PROJECT,
    project: project
  }
}

export function addRequest(request, projectId) {
  const newRequest = request.set('id', randomId()).set('projectId', projectId);

  return {
    type: ADD_REQUEST,
    projectId: projectId,
    request: newRequest
  }
}

export function updateRequest(request) {
  return {
    type: UPDATE_REQUEST,
    request: request
  }
}

export function deleteRequest(request) {
  return {
    type: DELETE_REQUEST,
    request: request
  }
}

export function executeRequest(method:string, url:string, headers:Object, body:?string) {
  return dispatch => {
    dispatch(awaitingResponse());

    doExecuteRequest(method, url, headers, body).then((response) => {
      dispatch(receiveResponse(response));
    }).catch((error) => {
      dispatch(receiveError(error));
    });
  };
}

{'fraction_non_alphanumeric': 0.1264275696253256, 'fraction_numerical': 0.002003606491685033, 'mean_word_length': 3.4571428571428573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5862836', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1483, 'n_words': 365}