@deepagents/text2sql 7.32.0 → 7.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1766,19 +1766,19 @@ function parseFile(filePath) {
1766
1766
  });
1767
1767
  }
1768
1768
  const sheets = [];
1769
+ const tableIdentifier = uniqueIdentifiers();
1769
1770
  for (const sheetName of workbook.SheetNames) {
1770
1771
  const sheet = workbook.Sheets[sheetName];
1771
1772
  const rows = XLSX.utils.sheet_to_json(sheet);
1772
1773
  if (rows.length === 0) {
1773
1774
  continue;
1774
1775
  }
1775
- const tableName = ext === ".csv" || ext === ".tsv" ? getTableNameFromFile(filePath) : sanitizeTableName(sheetName);
1776
1776
  const columns = inferColumns(rows);
1777
1777
  if (columns.length === 0) {
1778
1778
  continue;
1779
1779
  }
1780
1780
  sheets.push({
1781
- name: tableName,
1781
+ name: ext === ".csv" || ext === ".tsv" ? getTableNameFromFile(filePath) : tableIdentifier(sheetName),
1782
1782
  columns,
1783
1783
  rows
1784
1784
  });
@@ -1821,32 +1821,24 @@ function inferColumns(rows) {
1821
1821
  if (keySet.size === 0) {
1822
1822
  return [];
1823
1823
  }
1824
- const rawNames = Array.from(keySet);
1825
- const dedupedNames = deduplicateColumnNames(rawNames);
1826
- return dedupedNames.map((name, idx) => {
1827
- const originalKey = rawNames[idx];
1824
+ const columnIdentifier = uniqueIdentifiers();
1825
+ return Array.from(keySet, (originalKey) => {
1828
1826
  const values = rows.map((row) => row[originalKey]);
1829
1827
  const type = inferColumnType(values);
1830
- return { name, originalKey, type };
1828
+ return { name: columnIdentifier(originalKey), originalKey, type };
1831
1829
  });
1832
1830
  }
1833
- function deduplicateColumnNames(names) {
1834
- const seen = /* @__PURE__ */ new Map();
1835
- const result = [];
1836
- for (const rawName of names) {
1837
- let name = sanitizeTableName(rawName);
1838
- if (!name) {
1839
- name = "column";
1840
- }
1841
- const count = seen.get(name) ?? 0;
1842
- if (count > 0) {
1843
- result.push(`${name}_${count + 1}`);
1844
- } else {
1845
- result.push(name);
1846
- }
1847
- seen.set(name, count + 1);
1848
- }
1849
- return result;
1831
+ function uniqueIdentifiers() {
1832
+ const used = /* @__PURE__ */ new Set();
1833
+ return (rawName) => {
1834
+ const base = sanitizeIdentifier(rawName);
1835
+ let name = base;
1836
+ for (let suffix = 2; used.has(name); suffix++) {
1837
+ name = `${base}_${suffix}`;
1838
+ }
1839
+ used.add(name);
1840
+ return name;
1841
+ };
1850
1842
  }
1851
1843
  function inferColumnType(values) {
1852
1844
  let hasInteger = false;