@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.js CHANGED
@@ -752,6 +752,9 @@ var FileDatabase = class _FileDatabase {
752
752
  currentRecord = 0;
753
753
  hasReadFirstPage = false;
754
754
  lastFileData = null;
755
+ /** Cache of the last JSON file parsed during paginated reads (avoid re-parse per page). */
756
+ readFileCache = null;
757
+ // { filePath: string, data: any[] } | null
755
758
  metadata;
756
759
  // Synopsis calculation functions
757
760
  fileSynopsisFunction = null;
@@ -1518,7 +1521,6 @@ var FileDatabase = class _FileDatabase {
1518
1521
  let effectivePageSize;
1519
1522
  if (nextPage && this.hasReadFirstPage) {
1520
1523
  effectivePageSize = pageSize || this.pageSize;
1521
- this.currentRecord += effectivePageSize;
1522
1524
  } else if (!nextPage) {
1523
1525
  effectivePageSize = pageSize !== void 0 ? pageSize : this.metadata.totalRecords;
1524
1526
  this.currentRecord = 0;
@@ -1547,8 +1549,14 @@ var FileDatabase = class _FileDatabase {
1547
1549
  const file = this.metadata.files[i];
1548
1550
  const filePath = path3.join(this.getDestinationPath(this.currentVersion || void 0), file.fileName);
1549
1551
  try {
1550
- const rawData = await fs3.promises.readFile(filePath, "utf8");
1551
- const fileData = deserializeData(rawData, this.metadata.dataType);
1552
+ let fileData;
1553
+ if (this.readFileCache?.filePath === filePath && Array.isArray(this.readFileCache.data)) {
1554
+ fileData = this.readFileCache.data;
1555
+ } else {
1556
+ const rawData = await fs3.promises.readFile(filePath, "utf8");
1557
+ fileData = deserializeData(rawData, this.metadata.dataType);
1558
+ this.readFileCache = { filePath, data: fileData };
1559
+ }
1552
1560
  let startIndex = 0;
1553
1561
  if (i === currentFileIndex) {
1554
1562
  startIndex = this.currentRecord - cumulativeRecords;
@@ -1562,6 +1570,7 @@ var FileDatabase = class _FileDatabase {
1562
1570
  throw new FileDatabaseError(`Failed to read file ${file.fileName}: ${error.message}`);
1563
1571
  }
1564
1572
  }
1573
+ this.currentRecord += recordsRead;
1565
1574
  if (result.length > 0) {
1566
1575
  if (nextPage || pageSize !== void 0 && pageSize < this.metadata.totalRecords) {
1567
1576
  this.hasReadFirstPage = true;
@@ -1575,6 +1584,7 @@ var FileDatabase = class _FileDatabase {
1575
1584
  setStartRecord(startRecord) {
1576
1585
  this.currentRecord = startRecord - 1;
1577
1586
  this.hasReadFirstPage = false;
1587
+ this.readFileCache = null;
1578
1588
  }
1579
1589
  /**
1580
1590
  * Reset read pagination state
@@ -1582,6 +1592,7 @@ var FileDatabase = class _FileDatabase {
1582
1592
  resetPagination() {
1583
1593
  this.currentRecord = 0;
1584
1594
  this.hasReadFirstPage = false;
1595
+ this.readFileCache = null;
1585
1596
  }
1586
1597
  /**
1587
1598
  * List filenames in the table directory.