<commit_before>import _ from 'lodash';
import Promise from 'promise';
import {
  RequestSoapError,
} from './RequestErrors';

const parseString = Promise.denodeify(require('xml2js').parseString);

// common func for all XML keyed
// air:*List types (FlightDetailsList, AirSegmentList, FareInfoList, RouteList, AirPricePointList)
// TODO: for branded fares, air:Brand is referred by BrandID
//  or BrandFound=false and keys are useless
function getItemEmbKey(item) {
  if (item.$ && item.$.Key) {
    return item.$.Key;
  }
  return false;
}

function mergeLeaf(item) {
  const leaf = item.$;
  delete (item.$);
    // item.renameProperty('_', 'text'); //TODO decide if _ is the best name
  return _.extend(item, leaf);
}


/*
 * Default parsing algorithm configuration (for all responses)
 */

function defaultConfig(ver) {
  // do not collapse arrays with single objects or objects with single keys if they have this name
  const noCollapseList = ['air:BookingInfo', 'air:FareRule',
        // there's one SSR per each airline (per each passenger), they are usually identical
        'common_' + ver + ':SSR',
        'air:AirReservation',
        'air:PassengerType',
        'air:TicketInfo',
        'common_' + ver + ':ResponseMessage',
        'air:BaggageAllowanceInfo',
        'air:CarryOnAllowanceInfo',
    ];

  // Non-single field objects don't get collapsed
  //  from single item arrays into objects automatically, e.g.<commit_msg>Added specific tags to no collapse list for hotel module.<commit_after>import _ from 'lodash';
import Promise from 'promise';
import {
  RequestSoapError,
} from './RequestErrors';

const parseString = Promise.denodeify(require('xml2js').parseString);

// common func for all XML keyed
// air:*List types (FlightDetailsList, AirSegmentList, FareInfoList, RouteList, AirPricePointList)
// TODO: for branded fares, air:Brand is referred by BrandID
//  or BrandFound=false and keys are useless
function getItemEmbKey(item) {
  if (item.$ && item.$.Key) {
    return item.$.Key;
  }
  return false;
}

function mergeLeaf(item) {
  const leaf = item.$;
  delete (item.$);
    // item.renameProperty('_', 'text'); //TODO decide if _ is the best name
  return _.extend(item, leaf);
}


/*
 * Default parsing algorithm configuration (for all responses)
 */

function defaultConfig(ver) {
  // do not collapse arrays with single objects or objects with single keys if they have this name
  const noCollapseList = ['air:BookingInfo', 'air:FareRule',
        // there's one SSR per each airline (per each passenger), they are usually identical
        'common_' + ver + ':SSR',
        'air:AirReservation',
        'air:PassengerType',
        'air:TicketInfo',
        'common_' + ver + ':ResponseMessage',
        'air:BaggageAllowanceInfo',
        'air:CarryOnAllowanceInfo',
        'hotel:RateInfo',
        'hotel:HotelSearchResult',
        // 'hotel:Amenities',
        'hotel:Amenity',
        'hotel:HotelDetailItem',
        'hotel:AggregatorHotelDetails',
        'common_' + ver + ':MediaItem',
    ];

  // Non-single field objects don't get collapsed
  //  from single item arrays into objects automatically, e.g.
{'fraction_non_alphanumeric': 0.12037914691943127, 'fraction_numerical': 0.000631911532385466, 'mean_word_length': 3.44039270687237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6170730', 'n_tokens_mistral': 959, 'n_tokens_neox': 934, 'n_words': 293}