speclore 0.1.3 → 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.
@@ -2,8 +2,13 @@
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __esm = (fn, res) => function __init() {
6
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ var __esm = (fn, res, err) => function __init() {
6
+ if (err) throw err[0];
7
+ try {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ } catch (e) {
10
+ throw err = [e], e;
11
+ }
7
12
  };
8
13
  var __export = (target, all) => {
9
14
  for (var name in all)
@@ -945,7 +950,7 @@ var DocxReader = class {
945
950
  };
946
951
 
947
952
  // src/plugins/builtin/xlsx-reader.ts
948
- import ExcelJS from "exceljs";
953
+ import { readFile, utils } from "xlsx";
949
954
 
950
955
  // src/infra/excel-utils.ts
951
956
  function formatCellValue(value) {
@@ -953,6 +958,13 @@ function formatCellValue(value) {
953
958
  if (typeof value === "string") return value;
954
959
  if (typeof value === "number" || typeof value === "boolean") return String(value);
955
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
+ }
956
968
  return "";
957
969
  }
958
970
 
@@ -963,27 +975,23 @@ var XlsxReader = class {
963
975
  canRead(source) {
964
976
  return /\.xlsx$/i.test(source) || /\.xls$/i.test(source);
965
977
  }
966
- async read(source) {
967
- const workbook = new ExcelJS.Workbook();
968
- await workbook.xlsx.readFile(source);
978
+ read(source) {
979
+ const workbook = readFile(source);
969
980
  const requirements = [];
970
- for (const sheet of workbook.worksheets) {
971
- const sheetName = sheet.name;
972
- const headers = [];
973
- const rows = [];
974
- sheet.eachRow((row, rowNumber) => {
975
- if (rowNumber === 1) {
976
- row.eachCell((cell, colNumber) => {
977
- headers[colNumber - 1] = formatCellValue(cell.value);
978
- });
979
- } else {
980
- const obj = {};
981
- row.eachCell((cell, colNumber) => {
982
- const key = headers[colNumber - 1] ?? `Col${colNumber}`;
983
- obj[key] = formatCellValue(cell.value);
984
- });
985
- rows.push(obj);
986
- }
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;
987
995
  });
988
996
  for (let i = 0; i < rows.length; i++) {
989
997
  const row = rows[i];
@@ -1002,7 +1010,7 @@ var XlsxReader = class {
1002
1010
  }
1003
1011
  }
1004
1012
  }
1005
- return requirements;
1013
+ return Promise.resolve(requirements);
1006
1014
  }
1007
1015
  };
1008
1016
 
@@ -1660,52 +1668,59 @@ async function readDocxFile(filePath) {
1660
1668
 
1661
1669
  // src/core/requirement-reader/xlsx-reader.ts
1662
1670
  import { basename as basename3, extname as extname3 } from "path";
1663
- import ExcelJS2 from "exceljs";
1664
- async function readXlsxFile(filePath) {
1665
- const workbook = new ExcelJS2.Workbook();
1666
- await workbook.xlsx.readFile(filePath);
1671
+ import { readFile as readFile2, utils as utils2 } from "xlsx";
1672
+ function readXlsxFile(filePath) {
1673
+ const workbook = readFile2(filePath);
1667
1674
  const id = basename3(filePath, extname3(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
1668
- 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];
1669
1680
  if (!sheet) {
1670
- throw new Error(`No sheets found in ${filePath}`);
1671
- }
1672
- const title = sheet.name;
1673
- const headers = [];
1674
- const rows = [];
1675
- sheet.eachRow((row, rowNumber) => {
1676
- if (rowNumber === 1) {
1677
- row.eachCell((cell, colNumber) => {
1678
- headers[colNumber - 1] = formatCellValue(cell.value);
1679
- });
1680
- } else {
1681
- const obj = {};
1682
- row.eachCell((cell, colNumber) => {
1683
- const key = headers[colNumber - 1] ?? `Col${colNumber}`;
1684
- obj[key] = formatCellValue(cell.value);
1685
- });
1686
- rows.push(obj);
1687
- }
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;
1688
1703
  });
1689
- const textRows = rows.map((row) => {
1704
+ const textRows = objects.map((row) => {
1690
1705
  const cells = Object.entries(row).map(([key, value]) => `${key}: ${value}`).join(" | ");
1691
1706
  return cells;
1692
1707
  });
1693
1708
  const content = textRows.join("\n");
1694
- return {
1709
+ return Promise.resolve({
1695
1710
  id,
1696
1711
  title,
1697
1712
  description: content,
1698
1713
  rawContent: content,
1699
1714
  confidence: 0.85
1700
- };
1715
+ });
1701
1716
  }
1702
1717
 
1703
1718
  // src/core/requirement-reader/pdf-reader.ts
1704
1719
  import { basename as basename4, extname as extname4 } from "path";
1705
- import { readFile } from "fs/promises";
1720
+ import { readFile as readFile3 } from "fs/promises";
1706
1721
  async function readPdfFile(filePath) {
1707
1722
  const pdfParse = (await import("pdf-parse")).default;
1708
- const dataBuffer = await readFile(filePath);
1723
+ const dataBuffer = await readFile3(filePath);
1709
1724
  const data = await pdfParse(dataBuffer);
1710
1725
  const id = basename4(filePath, extname4(filePath)).toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff-]/g, "-").replace(/-+/g, "-");
1711
1726
  const lines = data.text.split("\n").filter((l) => l.trim());