<commit_before>'use strict';

const constants = {
  'type': 'type',
  'direction': 'direction',
  'trigger': 'Trigger',
  'inDirection': 'in',
  'outDirection': 'out',
  'settings': 'settings',
  'name': 'name',
  'value': 'value',
  'resource': 'resource',
  'required': 'required',
  'storage': 'storage',
  'connection': 'connection',
  'enum': 'enum',
  'defaultValue': 'defaultValue',
  'webHookType': 'webHookType',
  'httpTrigger': 'httpTrigger',
  'queue': 'queue',
  'queueName': 'queueName',
  'displayName': 'displayName',
  'xAzureSettings': 'x-azure-settings',
  'entryPoint': 'entryPoint'
};

module.exports = {
  'getFunctionMetaData': function (functionName, parsedBindings, serverless) {
    const bindings = [];
    let bindingSettingsNames = [];
    let bindingSettings = [];
    let bindingUserSettings = {};
    let bindingType;
    const functionsJson = {'disabled': false, 'bindings': []};
    const functionObject = serverless.service.getFunction(functionName);
    const handler = functionObject.handler;
    const events = functionObject.events;
    const params = {};

    const bindingTypes = parsedBindings.bindingTypes;
    const bindingDisplayNames = parsedBindings.bindingDisplayNames;

    for (let eventsIndex = 0; eventsIndex < events.length; eventsIndex++) {
      bindingType = Object.keys(functionObject.events[eventsIndex])[0];

      if (eventsIndex === 0) {
        bindingType += constants.trigger;
      }

      const index = bindingTypes.indexOf(bindingType);

      if (index < 0) {
        throw new Error(`Binding  ${bindingType} not supported`);
      }

      serverless.cli.log(`Building binding for function: ${functionName} event: ${bindingType}`);

      bindingUserSettings = {};
      const azureSettings = events[eventsIndex][constants.xAzureSettings];
      let bindingTypeIndex = bindingTypes.indexOf(bindingType);
      const bindingUserSettingsMetaData = this.getBindingUserSettingsMetaData(azureSettings, bindingType, bindingTypeIndex, bindingDisplayNames);

      bindingTypeIndex = bindingUserSettingsMetaData.index;
      bindingUserSettings = bindingUserSettingsMetaData.userSettings;

      if (bindingType.includes(constants.queue) && functionObject.events[eventsIndex].queue) {
        bindingUserSettings[constants.queueName] = functionObject.events[eventsIndex].queue;
      }

      if (bindingTypeIndex < 0) {
        throw new Error('Binding not supported');
      }

      bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];
      bindingSettingsNames = parsedBindings.bindingSettingsNames[bindingTypeIndex];

      if (azureSettings) {
        for (let azureSettingKeyIndex = 0; azureSettingKeyIndex < Object.keys(azureSettings).length; azureSettingKeyIndex++) {
          const key = Object.keys(azureSettings)[azureSettingKeyIndex];

          if (bindingSettingsNames.indexOf(key) >= 0) {
            bindingUserSettings[key] = azureSettings[key];
          }
        }
      }

      bindings.push(this.getBinding(bindingType, bindingSettings, bindingUserSettings, serverless));
    }

    if (bindingType === constants.httpTrigger && bindings.length === 1) {
      bindings.push(this.getHttpOutBinding(bindingUserSettings));
    }

    functionsJson.bindings = bindings;
    params.functionsJson = functionsJson;

    const entryPointAndHandlerPath = this.getEntryPointAndHandlerPath(handler);
    const metaData = {
      'entryPoint': entryPointAndHandlerPath[constants.entryPoint],
      'handlerPath': entryPointAndHandlerPath.handlerPath,
      'params': params
    };

return metaData;
  },

  'getBindingUserSettingsMetaData': function (azureSettings, bindingType, bindingTypeIndex, bindingDisplayNames) {<commit_msg>Bug fix (#25)<commit_after>'use strict';

const constants = {
  'type': 'type',
  'direction': 'direction',
  'trigger': 'Trigger',
  'inDirection': 'in',
  'outDirection': 'out',
  'settings': 'settings',
  'name': 'name',
  'value': 'value',
  'resource': 'resource',
  'required': 'required',
  'storage': 'storage',
  'connection': 'connection',
  'enum': 'enum',
  'defaultValue': 'defaultValue',
  'webHookType': 'webHookType',
  'httpTrigger': 'httpTrigger',
  'queue': 'queue',
  'queueName': 'queueName',
  'displayName': 'displayName',
  'xAzureSettings': 'x-azure-settings',
  'entryPoint': 'entryPoint'
};

module.exports = {
  'getFunctionMetaData': function (functionName, parsedBindings, serverless) {
    const bindings = [];
    let bindingSettingsNames = [];
    let bindingSettings = [];
    let bindingUserSettings = {};
    let bindingType;
    const functionsJson = {'disabled': false, 'bindings': []};
    const functionObject = serverless.service.getFunction(functionName);
    const handler = functionObject.handler;
    const events = functionObject.events;
    const params = {};

    const bindingTypes = parsedBindings.bindingTypes;
    const bindingDisplayNames = parsedBindings.bindingDisplayNames;

    for (let eventsIndex = 0; eventsIndex < events.length; eventsIndex++) {
      bindingType = Object.keys(functionObject.events[eventsIndex])[0];

      if (eventsIndex === 0) {
        bindingType += constants.trigger;
      }

      const index = bindingTypes.indexOf(bindingType);

      if (index < 0) {
        throw new Error(`Binding  ${bindingType} not supported`);
      }

      serverless.cli.log(`Building binding for function: ${functionName} event: ${bindingType}`);

      bindingUserSettings = {};
      const azureSettings = events[eventsIndex][constants.xAzureSettings];
      let bindingTypeIndex = bindingTypes.indexOf(bindingType);
      const bindingUserSettingsMetaData = this.getBindingUserSettingsMetaData(azureSettings, bindingType, bindingTypeIndex, bindingDisplayNames);

      bindingTypeIndex = bindingUserSettingsMetaData.index;
      bindingUserSettings = bindingUserSettingsMetaData.userSettings;

      if (bindingType.includes(constants.queue) && functionObject.events[eventsIndex].queue) {
        bindingUserSettings[constants.queueName] = functionObject.events[eventsIndex].queue;
      }

      if (bindingTypeIndex < 0) {
        throw new Error('Binding not supported');
      }

      bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];
      bindingSettingsNames = parsedBindings.bindingSettingsNames[bindingTypeIndex];

      if (azureSettings) {
        for (let azureSettingKeyIndex = 0; azureSettingKeyIndex < Object.keys(azureSettings).length; azureSettingKeyIndex++) {
          const key = Object.keys(azureSettings)[azureSettingKeyIndex];

          if (bindingSettingsNames.indexOf(key) >= 0) {
            bindingUserSettings[key] = azureSettings[key];
          }
        }
      }

      bindings.push(this.getBinding(bindingType, bindingSettings, bindingUserSettings, serverless));
    }

    if (bindingType === constants.httpTrigger) {
      bindings.push(this.getHttpOutBinding(bindingUserSettings));
    }

    functionsJson.bindings = bindings;
    params.functionsJson = functionsJson;

    const entryPointAndHandlerPath = this.getEntryPointAndHandlerPath(handler);
    const metaData = {
      'entryPoint': entryPointAndHandlerPath[constants.entryPoint],
      'handlerPath': entryPointAndHandlerPath.handlerPath,
      'params': params
    };

return metaData;
  },

  'getBindingUserSettingsMetaData': function (azureSettings, bindingType, bindingTypeIndex, bindingDisplayNames) {
{'fraction_non_alphanumeric': 0.12120803559390589, 'fraction_numerical': 0.002292031818794661, 'mean_word_length': 4.151388888888889, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '2526005', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1995, 'n_words': 402}