<commit_before>import { findNestedPropertyInObject } from "#SRC/js/utils/Util";
import { ADD_ITEM, SET } from "#SRC/js/constants/TransactionTypes";
import Transaction from "#SRC/js/structs/Transaction";
import { PROTOCOLS } from "../../constants/PortDefinitionConstants";
import VipLabelUtil from "../../utils/VipLabelUtil";

module.exports = {
  /**
   * This parser must take precedence over PortDefinition parser, as it assumes
   * some data available from it
   * @param {Object} state current appConfig
   * @returns {Transaction[]} A list of transactions resulting _portDefinition_
   * settings. NOT portMappings! The source of truth is portDefinitions, but
   * portMapping takes precedence.
   */
  JSONParser(state) {
    const portMappings =
      findNestedPropertyInObject(state, "container.portMappings") || [];
    const portDefinitionsLength =
      findNestedPropertyInObject(state, "portDefinitions.length") || 0;

    // Add additional fields if we have more definitions in portMappings
    // than in portDefinitions
    const length = portMappings.length - portDefinitionsLength;
    const addTransactions = [];
    Array.from({ length }).forEach(() => {
      addTransactions.push(
        new Transaction(["portDefinitions"], null, ADD_ITEM)
      );
    });

    // Look at portMappings and add accepted fields
    // but translate them into portDefinitions
    return portMappings.reduce(function(memo, item, index) {
      if (item.name != null) {
        memo.push(
          new Transaction(["portDefinitions", index, "name"], item.name, SET)
        );
      }<commit_msg>fix(PortMappings): check type<commit_after>import { findNestedPropertyInObject } from "#SRC/js/utils/Util";
import { ADD_ITEM, SET } from "#SRC/js/constants/TransactionTypes";
import Transaction from "#SRC/js/structs/Transaction";
import { PROTOCOLS } from "../../constants/PortDefinitionConstants";
import VipLabelUtil from "../../utils/VipLabelUtil";

module.exports = {
  /**
   * This parser must take precedence over PortDefinition parser, as it assumes
   * some data available from it
   * @param {Object} state current appConfig
   * @returns {Transaction[]} A list of transactions resulting _portDefinition_
   * settings. NOT portMappings! The source of truth is portDefinitions, but
   * portMapping takes precedence.
   */
  JSONParser(state) {
    const portMappings =
      findNestedPropertyInObject(state, "container.portMappings") || [];
    const portDefinitionsLength =
      findNestedPropertyInObject(state, "portDefinitions.length") || 0;

    // Add additional fields if we have more definitions in portMappings
    // than in portDefinitions
    const length = portMappings.length - portDefinitionsLength;
    const addTransactions = [];
    Array.from({ length }).forEach(() => {
      addTransactions.push(
        new Transaction(["portDefinitions"], null, ADD_ITEM)
      );
    });

    if (!Array.isArray(portMappings)) {
      return [];
    }
    // Look at portMappings and add accepted fields
    // but translate them into portDefinitions
    return portMappings.reduce(function(memo, item, index) {
      if (item.name != null) {
        memo.push(
          new Transaction(["portDefinitions", index, "name"], item.name, SET)
        );
      }
{'fraction_non_alphanumeric': 0.11209259823332318, 'fraction_numerical': 0.0006091989034419738, 'mean_word_length': 3.4863387978142075, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7588088', 'n_tokens_mistral': 888, 'n_tokens_neox': 873, 'n_words': 259}