speclore 0.1.4 → 0.1.6

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.
@@ -950,7 +950,7 @@ var DocxReader = class {
950
950
  };
951
951
 
952
952
  // src/plugins/builtin/xlsx-reader.ts
953
- import ExcelJS from "exceljs";
953
+ import { readFile, utils } from "xlsx";
954
954
 
955
955
  // src/infra/excel-utils.ts
956
956
  function formatCellValue(value) {
@@ -958,6 +958,13 @@ function formatCellValue(value) {
958
958
  if (typeof value === "string") return value;
959
959
  if (typeof value === "number" || typeof value === "boolean") return String(value);
960
960
  if (value instanceof Date) return value.toISOString();
961
+ if (typeof value === "object" && value !== null && "v" in value) {
962
+ const cell = value;
963
+ if (cell.w != null) return cell.w;
964
+ if (cell.v == null) return "";
965
+ if (typeof cell.v === "string" || typeof cell.v === "number" || typeof cell.v === "boolean") return String(cell.v);
966
+ return JSON.stringify(cell.v);
967
+ }
961
968
  return "";
962
969
  }
963
970
 
@@ -968,27 +975,23 @@ var XlsxReader = class {
968
975
  canRead(source) {
969
976
  return /\.xlsx$/i.test(source) || /\.xls$/i.test(source);
970
977
  }
971
- async read(source) {
972
- const workbook = new ExcelJS.Workbook();
973
- await workbook.xlsx.readFile(source);
978
+ read(source) {
979
+ const workbook = readFile(source);
974
980
  const requirements = [];
975
- for (const sheet of workbook.worksheets) {
976
- const sheetName = sheet.name;
977
- const headers = [];
978
- const rows = [];
979
- sheet.eachRow((row, rowNumber) => {
980
- if (rowNumber === 1) {
981
- row.eachCell((cell, colNumber) => {
982
- headers[colNumber - 1] = formatCellValue(cell.value);
983
- });
984
- } else {
985
- const obj = {};
986
- row.eachCell((cell, colNumber) => {
987
- const key = headers[colNumber - 1] ?? `Col${colNumber}`;
988
- obj[key] = formatCellValue(cell.value);
989
- });
990
- rows.push(obj);
991
- }
981
+ for (const sheetName of workbook.SheetNames) {
982
+ const sheet = workbook.Sheets[sheetName];
983
+ if (!sheet) continue;
984
+ const allRows = utils.sheet_to_json(sheet, { header: 1, defval: "" });
985
+ if (allRows.length === 0) continue;
986
+ const headers = allRows[0].map((cell) => formatCellValue(cell));
987
+ const dataRows = allRows.slice(1);
988
+ const rows = dataRows.map((row) => {
989
+ const obj = {};
990
+ row.forEach((cell, colNumber) => {
991
+ const key = headers[colNumber] ?? `Col${colNumber + 1}`;
992
+ obj[key] = formatCellValue(cell);
993
+ });
994
+ return obj;
992
995
  });
993
996
  for (let i = 0; i < rows.length; i++) {
994
997
  const row = rows[i];
@@ -1007,7 +1010,7 @@ var XlsxReader = class {
1007
1010
  }
1008
1011
  }
1009
1012
  }
1010
- return requirements;
1013
+ return Promise.resolve(requirements);
1011
1014
  }
1012
1015
  };
1013
1016
 
@@ -1665,52 +1668,59 @@ async function readDocxFile(filePath) {
1665
1668
 
1666
1669
  // src/core/requirement-reader/xlsx-reader.ts
1667
1670
  import { basename as basename3, extname as extname3 } from "path";
1668
- import ExcelJS2 from "exceljs";
1669
- async function readXlsxFile(filePath) {
1670
- const workbook = new ExcelJS2.Workbook();
1671
- await workbook.xlsx.readFile(filePath);
1671
+ import { readFile as readFile2, utils as utils2 } from "xlsx";
1672
+ function readXlsxFile(filePath) {
1673
+ const workbook = readFile2(filePath);
1672
1674
  const id = basename3(filePath, extname3(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
1673
- const sheet = workbook.worksheets[0];
1675
+ const firstSheetName = workbook.SheetNames[0];
1676
+ if (!firstSheetName) {
1677
+ return Promise.reject(new Error(`No sheets found in ${filePath}`));
1678
+ }
1679
+ const sheet = workbook.Sheets[firstSheetName];
1674
1680
  if (!sheet) {
1675
- throw new Error(`No sheets found in ${filePath}`);
1676
- }
1677
- const title = sheet.name;
1678
- const headers = [];
1679
- const rows = [];
1680
- sheet.eachRow((row, rowNumber) => {
1681
- if (rowNumber === 1) {
1682
- row.eachCell((cell, colNumber) => {
1683
- headers[colNumber - 1] = formatCellValue(cell.value);
1684
- });
1685
- } else {
1686
- const obj = {};
1687
- row.eachCell((cell, colNumber) => {
1688
- const key = headers[colNumber - 1] ?? `Col${colNumber}`;
1689
- obj[key] = formatCellValue(cell.value);
1690
- });
1691
- rows.push(obj);
1692
- }
1681
+ return Promise.reject(new Error(`Sheet "${firstSheetName}" not found in ${filePath}`));
1682
+ }
1683
+ const title = firstSheetName;
1684
+ const rows = utils2.sheet_to_json(sheet, { header: 1, defval: "" });
1685
+ if (rows.length === 0) {
1686
+ return Promise.resolve({
1687
+ id,
1688
+ title,
1689
+ description: "",
1690
+ rawContent: "",
1691
+ confidence: 0.85
1692
+ });
1693
+ }
1694
+ const headers = rows[0].map((cell) => formatCellValue(cell));
1695
+ const dataRows = rows.slice(1);
1696
+ const objects = dataRows.map((row) => {
1697
+ const obj = {};
1698
+ row.forEach((cell, colNumber) => {
1699
+ const key = headers[colNumber] ?? `Col${colNumber + 1}`;
1700
+ obj[key] = formatCellValue(cell);
1701
+ });
1702
+ return obj;
1693
1703
  });
1694
- const textRows = rows.map((row) => {
1704
+ const textRows = objects.map((row) => {
1695
1705
  const cells = Object.entries(row).map(([key, value]) => `${key}: ${value}`).join(" | ");
1696
1706
  return cells;
1697
1707
  });
1698
1708
  const content = textRows.join("\n");
1699
- return {
1709
+ return Promise.resolve({
1700
1710
  id,
1701
1711
  title,
1702
1712
  description: content,
1703
1713
  rawContent: content,
1704
1714
  confidence: 0.85
1705
- };
1715
+ });
1706
1716
  }
1707
1717
 
1708
1718
  // src/core/requirement-reader/pdf-reader.ts
1709
1719
  import { basename as basename4, extname as extname4 } from "path";
1710
- import { readFile } from "fs/promises";
1720
+ import { readFile as readFile3 } from "fs/promises";
1711
1721
  async function readPdfFile(filePath) {
1712
1722
  const pdfParse = (await import("pdf-parse")).default;
1713
- const dataBuffer = await readFile(filePath);
1723
+ const dataBuffer = await readFile3(filePath);
1714
1724
  const data = await pdfParse(dataBuffer);
1715
1725
  const id = basename4(filePath, extname4(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
1716
1726
  const lines = data.text.split("\n").filter((l) => l.trim());