@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.
@@ -183,6 +183,9 @@ var FileDatabase = class _FileDatabase {
183
183
  currentRecord = 0;
184
184
  hasReadFirstPage = false;
185
185
  lastFileData = null;
186
+ /** Cache of the last JSON file parsed during paginated reads (avoid re-parse per page). */
187
+ readFileCache = null;
188
+ // { filePath: string, data: any[] } | null
186
189
  metadata;
187
190
  // Synopsis calculation functions
188
191
  fileSynopsisFunction = null;
@@ -949,7 +952,6 @@ var FileDatabase = class _FileDatabase {
949
952
  let effectivePageSize;
950
953
  if (nextPage && this.hasReadFirstPage) {
951
954
  effectivePageSize = pageSize || this.pageSize;
952
- this.currentRecord += effectivePageSize;
953
955
  } else if (!nextPage) {
954
956
  effectivePageSize = pageSize !== void 0 ? pageSize : this.metadata.totalRecords;
955
957
  this.currentRecord = 0;
@@ -978,8 +980,14 @@ var FileDatabase = class _FileDatabase {
978
980
  const file = this.metadata.files[i];
979
981
  const filePath = import_path3.default.join(this.getDestinationPath(this.currentVersion || void 0), file.fileName);
980
982
  try {
981
- const rawData = await import_fs3.default.promises.readFile(filePath, "utf8");
982
- const fileData = deserializeData(rawData, this.metadata.dataType);
983
+ let fileData;
984
+ if (this.readFileCache?.filePath === filePath && Array.isArray(this.readFileCache.data)) {
985
+ fileData = this.readFileCache.data;
986
+ } else {
987
+ const rawData = await import_fs3.default.promises.readFile(filePath, "utf8");
988
+ fileData = deserializeData(rawData, this.metadata.dataType);
989
+ this.readFileCache = { filePath, data: fileData };
990
+ }
983
991
  let startIndex = 0;
984
992
  if (i === currentFileIndex) {
985
993
  startIndex = this.currentRecord - cumulativeRecords;
@@ -993,6 +1001,7 @@ var FileDatabase = class _FileDatabase {
993
1001
  throw new FileDatabaseError(`Failed to read file ${file.fileName}: ${error.message}`);
994
1002
  }
995
1003
  }
1004
+ this.currentRecord += recordsRead;
996
1005
  if (result.length > 0) {
997
1006
  if (nextPage || pageSize !== void 0 && pageSize < this.metadata.totalRecords) {
998
1007
  this.hasReadFirstPage = true;
@@ -1006,6 +1015,7 @@ var FileDatabase = class _FileDatabase {
1006
1015
  setStartRecord(startRecord) {
1007
1016
  this.currentRecord = startRecord - 1;
1008
1017
  this.hasReadFirstPage = false;
1018
+ this.readFileCache = null;
1009
1019
  }
1010
1020
  /**
1011
1021
  * Reset read pagination state
@@ -1013,6 +1023,7 @@ var FileDatabase = class _FileDatabase {
1013
1023
  resetPagination() {
1014
1024
  this.currentRecord = 0;
1015
1025
  this.hasReadFirstPage = false;
1026
+ this.readFileCache = null;
1016
1027
  }
1017
1028
  /**
1018
1029
  * List filenames in the table directory.