{"version":3,"file":"transformDataForGraphFromFile-DjiTv_SK.cjs","names":[],"sources":["../src/Utils/transformData/transformDataForGraphFromFile.ts"],"sourcesContent":["import type {\r\n  ColumnConfigurationDataType,\r\n  FileSettingsDataType,\r\n  GraphConfigurationDataType,\r\n  GraphType,\r\n} from '@/Types';\r\nimport {\r\n  fetchAndParseCSV,\r\n  fetchAndParseJSON,\r\n  fetchAndParseMultipleDataSources,\r\n  fetchAndTransformDataFromAPI,\r\n} from '../fetchAndParseData';\r\nimport { transformDataForGraph } from './transformDataForGraph';\r\n/**\r\n * Fetches data from a given URL or multiple data sources, processes it according to the specified graph configuration,\r\n * and formats it for use in a graph.\r\n *\r\n * This function supports different file types (CSV, JSON, and API), and can handle multiple data sources. It applies\r\n * any necessary data transformations and column formatting, then prepares the data for visualization in the specified graph.\r\n *\r\n * @param dataURL - The URL or array of data sources to fetch data from. If it's a string, it represents the URL to fetch data from.\r\n *                  If it's an array, it represents multiple data sources with different types (CSV, JSON, API).\r\n * @param dataConfiguration - The graph configuration data used to determine how the data should be formatted for the graph.\r\n * @param graph - The type of graph to be used (e.g., lineChart, barChart).\r\n * @param fileType - The type of the file being fetched. Can be 'csv', 'json', or 'api'. This parameter is ignored if `dataURL` is an array.\r\n * @param delimiter - The delimiter used in CSV files (default is ',' if not provided).\r\n * @param columnsToArray - Configuration for columns that need to be transformed into arrays (optional).\r\n * @param apiHeaders - Headers for the API request (optional).\r\n * @param dataTransformation - A Handlebars template used for transforming the data (optional).\r\n * @param idColumnTitle - The title of the ID column when merging multiple data sources (optional).\r\n *\r\n * @returns A Promise that resolves to the transformed data ready for the graph, or null if an error occurs.\r\n *\r\n * @throws {Error} Throws an error if the data fetching or processing fails.\r\n *\r\n * @example\r\n * const dataURL = 'https://example.com/data.json';\r\n * const dataConfiguration = [\r\n *   { column: 'value', chartConfigId: 'size' },\r\n *   { column: 'category', chartConfigId: 'label' },\r\n * ];\r\n * const graph = 'barChart';\r\n * transformDataForGraphFromFile(dataURL, dataConfiguration, graph, 'json')\r\n *   .then(data => {\r\n *     console.log('Formatted Data:', data);\r\n *   })\r\n *   .catch(error => {\r\n *     console.error('Error:', error);\r\n *   });\r\n */\r\nexport async function transformDataForGraphFromFile(\r\n  dataURL: string | FileSettingsDataType[],\r\n  dataConfiguration: GraphConfigurationDataType[],\r\n  graph: GraphType,\r\n  fileType?: 'csv' | 'json' | 'api',\r\n  delimiter?: string,\r\n  columnsToArray?: ColumnConfigurationDataType[],\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  apiHeaders?: any,\r\n  dataTransformation?: string,\r\n  idColumnTitle?: string,\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n): Promise<any> {\r\n  // Ensure the function returns a Promise\r\n  try {\r\n    const fetchedData = await (typeof dataURL === 'string'\r\n      ? fileType === 'json'\r\n        ? fetchAndParseJSON(dataURL, columnsToArray, dataTransformation, false)\r\n        : fileType === 'api'\r\n          ? fetchAndTransformDataFromAPI(\r\n              dataURL,\r\n              apiHeaders,\r\n              columnsToArray,\r\n              dataTransformation,\r\n              false,\r\n            )\r\n          : fetchAndParseCSV(dataURL, dataTransformation, columnsToArray, false, delimiter, true)\r\n      : fetchAndParseMultipleDataSources(dataURL, idColumnTitle));\r\n\r\n    const formattedData = transformDataForGraph(\r\n      fetchedData,\r\n      graph,\r\n      dataConfiguration as GraphConfigurationDataType[],\r\n    );\r\n    return formattedData;\r\n  } catch (error) {\r\n    console.error('Error fetching or processing data', error);\r\n    return null; // Return null in case of any errors\r\n  }\r\n}\r\n"],"mappings":"sGAkDA,eAAsB,EACpB,EACA,EACA,EACA,EACA,EACA,EAEA,EACA,EACA,EAEc,CAEd,GAAI,CAoBF,OALsB,EAAA,EACpB,MAfyB,OAAO,GAAY,SAC1C,IAAa,OACX,EAAA,EAAkB,EAAS,EAAgB,EAAoB,EAAK,EACpE,IAAa,MACX,EAAA,EACE,EACA,EACA,EACA,EACA,EACF,EACA,EAAA,EAAiB,EAAS,EAAoB,EAAgB,GAAO,EAAW,EAAI,EACxF,EAAA,EAAiC,EAAS,CAAa,GAIzD,EACA,CAEK,CACT,OAAS,EAAO,CAEd,OADA,QAAQ,MAAM,oCAAqC,CAAK,EACjD,IACT,CACF"}