@nmakarov/cli-toolkit 0.40.0 → 0.43.0

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.
package/dist/tasks.cjs CHANGED
@@ -828,6 +828,9 @@ var FileDatabase = class _FileDatabase {
828
828
  currentRecord = 0;
829
829
  hasReadFirstPage = false;
830
830
  lastFileData = null;
831
+ /** Cache of the last JSON file parsed during paginated reads (avoid re-parse per page). */
832
+ readFileCache = null;
833
+ // { filePath: string, data: any[] } | null
831
834
  metadata;
832
835
  // Synopsis calculation functions
833
836
  fileSynopsisFunction = null;
@@ -1594,7 +1597,6 @@ var FileDatabase = class _FileDatabase {
1594
1597
  let effectivePageSize;
1595
1598
  if (nextPage && this.hasReadFirstPage) {
1596
1599
  effectivePageSize = pageSize || this.pageSize;
1597
- this.currentRecord += effectivePageSize;
1598
1600
  } else if (!nextPage) {
1599
1601
  effectivePageSize = pageSize !== void 0 ? pageSize : this.metadata.totalRecords;
1600
1602
  this.currentRecord = 0;
@@ -1623,8 +1625,14 @@ var FileDatabase = class _FileDatabase {
1623
1625
  const file = this.metadata.files[i];
1624
1626
  const filePath = import_path3.default.join(this.getDestinationPath(this.currentVersion || void 0), file.fileName);
1625
1627
  try {
1626
- const rawData = await import_fs3.default.promises.readFile(filePath, "utf8");
1627
- const fileData = deserializeData(rawData, this.metadata.dataType);
1628
+ let fileData;
1629
+ if (this.readFileCache?.filePath === filePath && Array.isArray(this.readFileCache.data)) {
1630
+ fileData = this.readFileCache.data;
1631
+ } else {
1632
+ const rawData = await import_fs3.default.promises.readFile(filePath, "utf8");
1633
+ fileData = deserializeData(rawData, this.metadata.dataType);
1634
+ this.readFileCache = { filePath, data: fileData };
1635
+ }
1628
1636
  let startIndex = 0;
1629
1637
  if (i === currentFileIndex) {
1630
1638
  startIndex = this.currentRecord - cumulativeRecords;
@@ -1638,6 +1646,7 @@ var FileDatabase = class _FileDatabase {
1638
1646
  throw new FileDatabaseError(`Failed to read file ${file.fileName}: ${error.message}`);
1639
1647
  }
1640
1648
  }
1649
+ this.currentRecord += recordsRead;
1641
1650
  if (result.length > 0) {
1642
1651
  if (nextPage || pageSize !== void 0 && pageSize < this.metadata.totalRecords) {
1643
1652
  this.hasReadFirstPage = true;
@@ -1651,6 +1660,7 @@ var FileDatabase = class _FileDatabase {
1651
1660
  setStartRecord(startRecord) {
1652
1661
  this.currentRecord = startRecord - 1;
1653
1662
  this.hasReadFirstPage = false;
1663
+ this.readFileCache = null;
1654
1664
  }
1655
1665
  /**
1656
1666
  * Reset read pagination state
@@ -1658,6 +1668,7 @@ var FileDatabase = class _FileDatabase {
1658
1668
  resetPagination() {
1659
1669
  this.currentRecord = 0;
1660
1670
  this.hasReadFirstPage = false;
1671
+ this.readFileCache = null;
1661
1672
  }
1662
1673
  /**
1663
1674
  * List filenames in the table directory.