@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.
@@ -4082,6 +4082,9 @@ var FileDatabase = class _FileDatabase {
4082
4082
  currentRecord = 0;
4083
4083
  hasReadFirstPage = false;
4084
4084
  lastFileData = null;
4085
+ /** Cache of the last JSON file parsed during paginated reads (avoid re-parse per page). */
4086
+ readFileCache = null;
4087
+ // { filePath: string, data: any[] } | null
4085
4088
  metadata;
4086
4089
  // Synopsis calculation functions
4087
4090
  fileSynopsisFunction = null;
@@ -4848,7 +4851,6 @@ var FileDatabase = class _FileDatabase {
4848
4851
  let effectivePageSize;
4849
4852
  if (nextPage && this.hasReadFirstPage) {
4850
4853
  effectivePageSize = pageSize || this.pageSize;
4851
- this.currentRecord += effectivePageSize;
4852
4854
  } else if (!nextPage) {
4853
4855
  effectivePageSize = pageSize !== void 0 ? pageSize : this.metadata.totalRecords;
4854
4856
  this.currentRecord = 0;
@@ -4877,8 +4879,14 @@ var FileDatabase = class _FileDatabase {
4877
4879
  const file = this.metadata.files[i];
4878
4880
  const filePath = import_path4.default.join(this.getDestinationPath(this.currentVersion || void 0), file.fileName);
4879
4881
  try {
4880
- const rawData = await import_fs4.default.promises.readFile(filePath, "utf8");
4881
- const fileData = deserializeData(rawData, this.metadata.dataType);
4882
+ let fileData;
4883
+ if (this.readFileCache?.filePath === filePath && Array.isArray(this.readFileCache.data)) {
4884
+ fileData = this.readFileCache.data;
4885
+ } else {
4886
+ const rawData = await import_fs4.default.promises.readFile(filePath, "utf8");
4887
+ fileData = deserializeData(rawData, this.metadata.dataType);
4888
+ this.readFileCache = { filePath, data: fileData };
4889
+ }
4882
4890
  let startIndex = 0;
4883
4891
  if (i === currentFileIndex) {
4884
4892
  startIndex = this.currentRecord - cumulativeRecords;
@@ -4892,6 +4900,7 @@ var FileDatabase = class _FileDatabase {
4892
4900
  throw new FileDatabaseError(`Failed to read file ${file.fileName}: ${error.message}`);
4893
4901
  }
4894
4902
  }
4903
+ this.currentRecord += recordsRead;
4895
4904
  if (result.length > 0) {
4896
4905
  if (nextPage || pageSize !== void 0 && pageSize < this.metadata.totalRecords) {
4897
4906
  this.hasReadFirstPage = true;
@@ -4905,6 +4914,7 @@ var FileDatabase = class _FileDatabase {
4905
4914
  setStartRecord(startRecord) {
4906
4915
  this.currentRecord = startRecord - 1;
4907
4916
  this.hasReadFirstPage = false;
4917
+ this.readFileCache = null;
4908
4918
  }
4909
4919
  /**
4910
4920
  * Reset read pagination state
@@ -4912,6 +4922,7 @@ var FileDatabase = class _FileDatabase {
4912
4922
  resetPagination() {
4913
4923
  this.currentRecord = 0;
4914
4924
  this.hasReadFirstPage = false;
4925
+ this.readFileCache = null;
4915
4926
  }
4916
4927
  /**
4917
4928
  * List filenames in the table directory.