@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.
@@ -4066,6 +4066,9 @@ var FileDatabase = class _FileDatabase {
4066
4066
  currentRecord = 0;
4067
4067
  hasReadFirstPage = false;
4068
4068
  lastFileData = null;
4069
+ /** Cache of the last JSON file parsed during paginated reads (avoid re-parse per page). */
4070
+ readFileCache = null;
4071
+ // { filePath: string, data: any[] } | null
4069
4072
  metadata;
4070
4073
  // Synopsis calculation functions
4071
4074
  fileSynopsisFunction = null;
@@ -4832,7 +4835,6 @@ var FileDatabase = class _FileDatabase {
4832
4835
  let effectivePageSize;
4833
4836
  if (nextPage && this.hasReadFirstPage) {
4834
4837
  effectivePageSize = pageSize || this.pageSize;
4835
- this.currentRecord += effectivePageSize;
4836
4838
  } else if (!nextPage) {
4837
4839
  effectivePageSize = pageSize !== void 0 ? pageSize : this.metadata.totalRecords;
4838
4840
  this.currentRecord = 0;
@@ -4861,8 +4863,14 @@ var FileDatabase = class _FileDatabase {
4861
4863
  const file = this.metadata.files[i];
4862
4864
  const filePath = path3.join(this.getDestinationPath(this.currentVersion || void 0), file.fileName);
4863
4865
  try {
4864
- const rawData = await fs3.promises.readFile(filePath, "utf8");
4865
- const fileData = deserializeData(rawData, this.metadata.dataType);
4866
+ let fileData;
4867
+ if (this.readFileCache?.filePath === filePath && Array.isArray(this.readFileCache.data)) {
4868
+ fileData = this.readFileCache.data;
4869
+ } else {
4870
+ const rawData = await fs3.promises.readFile(filePath, "utf8");
4871
+ fileData = deserializeData(rawData, this.metadata.dataType);
4872
+ this.readFileCache = { filePath, data: fileData };
4873
+ }
4866
4874
  let startIndex = 0;
4867
4875
  if (i === currentFileIndex) {
4868
4876
  startIndex = this.currentRecord - cumulativeRecords;
@@ -4876,6 +4884,7 @@ var FileDatabase = class _FileDatabase {
4876
4884
  throw new FileDatabaseError(`Failed to read file ${file.fileName}: ${error.message}`);
4877
4885
  }
4878
4886
  }
4887
+ this.currentRecord += recordsRead;
4879
4888
  if (result.length > 0) {
4880
4889
  if (nextPage || pageSize !== void 0 && pageSize < this.metadata.totalRecords) {
4881
4890
  this.hasReadFirstPage = true;
@@ -4889,6 +4898,7 @@ var FileDatabase = class _FileDatabase {
4889
4898
  setStartRecord(startRecord) {
4890
4899
  this.currentRecord = startRecord - 1;
4891
4900
  this.hasReadFirstPage = false;
4901
+ this.readFileCache = null;
4892
4902
  }
4893
4903
  /**
4894
4904
  * Reset read pagination state
@@ -4896,6 +4906,7 @@ var FileDatabase = class _FileDatabase {
4896
4906
  resetPagination() {
4897
4907
  this.currentRecord = 0;
4898
4908
  this.hasReadFirstPage = false;
4909
+ this.readFileCache = null;
4899
4910
  }
4900
4911
  /**
4901
4912
  * List filenames in the table directory.