@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.
@@ -149,6 +149,9 @@ var FileDatabase = class _FileDatabase {
149
149
  currentRecord = 0;
150
150
  hasReadFirstPage = false;
151
151
  lastFileData = null;
152
+ /** Cache of the last JSON file parsed during paginated reads (avoid re-parse per page). */
153
+ readFileCache = null;
154
+ // { filePath: string, data: any[] } | null
152
155
  metadata;
153
156
  // Synopsis calculation functions
154
157
  fileSynopsisFunction = null;
@@ -915,7 +918,6 @@ var FileDatabase = class _FileDatabase {
915
918
  let effectivePageSize;
916
919
  if (nextPage && this.hasReadFirstPage) {
917
920
  effectivePageSize = pageSize || this.pageSize;
918
- this.currentRecord += effectivePageSize;
919
921
  } else if (!nextPage) {
920
922
  effectivePageSize = pageSize !== void 0 ? pageSize : this.metadata.totalRecords;
921
923
  this.currentRecord = 0;
@@ -944,8 +946,14 @@ var FileDatabase = class _FileDatabase {
944
946
  const file = this.metadata.files[i];
945
947
  const filePath = path3.join(this.getDestinationPath(this.currentVersion || void 0), file.fileName);
946
948
  try {
947
- const rawData = await fs3.promises.readFile(filePath, "utf8");
948
- const fileData = deserializeData(rawData, this.metadata.dataType);
949
+ let fileData;
950
+ if (this.readFileCache?.filePath === filePath && Array.isArray(this.readFileCache.data)) {
951
+ fileData = this.readFileCache.data;
952
+ } else {
953
+ const rawData = await fs3.promises.readFile(filePath, "utf8");
954
+ fileData = deserializeData(rawData, this.metadata.dataType);
955
+ this.readFileCache = { filePath, data: fileData };
956
+ }
949
957
  let startIndex = 0;
950
958
  if (i === currentFileIndex) {
951
959
  startIndex = this.currentRecord - cumulativeRecords;
@@ -959,6 +967,7 @@ var FileDatabase = class _FileDatabase {
959
967
  throw new FileDatabaseError(`Failed to read file ${file.fileName}: ${error.message}`);
960
968
  }
961
969
  }
970
+ this.currentRecord += recordsRead;
962
971
  if (result.length > 0) {
963
972
  if (nextPage || pageSize !== void 0 && pageSize < this.metadata.totalRecords) {
964
973
  this.hasReadFirstPage = true;
@@ -972,6 +981,7 @@ var FileDatabase = class _FileDatabase {
972
981
  setStartRecord(startRecord) {
973
982
  this.currentRecord = startRecord - 1;
974
983
  this.hasReadFirstPage = false;
984
+ this.readFileCache = null;
975
985
  }
976
986
  /**
977
987
  * Reset read pagination state
@@ -979,6 +989,7 @@ var FileDatabase = class _FileDatabase {
979
989
  resetPagination() {
980
990
  this.currentRecord = 0;
981
991
  this.hasReadFirstPage = false;
992
+ this.readFileCache = null;
982
993
  }
983
994
  /**
984
995
  * List filenames in the table directory.