@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/index.js CHANGED
@@ -2361,6 +2361,9 @@ var FileDatabase = class _FileDatabase {
2361
2361
  currentRecord = 0;
2362
2362
  hasReadFirstPage = false;
2363
2363
  lastFileData = null;
2364
+ /** Cache of the last JSON file parsed during paginated reads (avoid re-parse per page). */
2365
+ readFileCache = null;
2366
+ // { filePath: string, data: any[] } | null
2364
2367
  metadata;
2365
2368
  // Synopsis calculation functions
2366
2369
  fileSynopsisFunction = null;
@@ -3127,7 +3130,6 @@ var FileDatabase = class _FileDatabase {
3127
3130
  let effectivePageSize;
3128
3131
  if (nextPage && this.hasReadFirstPage) {
3129
3132
  effectivePageSize = pageSize || this.pageSize;
3130
- this.currentRecord += effectivePageSize;
3131
3133
  } else if (!nextPage) {
3132
3134
  effectivePageSize = pageSize !== void 0 ? pageSize : this.metadata.totalRecords;
3133
3135
  this.currentRecord = 0;
@@ -3156,8 +3158,14 @@ var FileDatabase = class _FileDatabase {
3156
3158
  const file = this.metadata.files[i];
3157
3159
  const filePath = path3.join(this.getDestinationPath(this.currentVersion || void 0), file.fileName);
3158
3160
  try {
3159
- const rawData = await fs3.promises.readFile(filePath, "utf8");
3160
- const fileData = deserializeData(rawData, this.metadata.dataType);
3161
+ let fileData;
3162
+ if (this.readFileCache?.filePath === filePath && Array.isArray(this.readFileCache.data)) {
3163
+ fileData = this.readFileCache.data;
3164
+ } else {
3165
+ const rawData = await fs3.promises.readFile(filePath, "utf8");
3166
+ fileData = deserializeData(rawData, this.metadata.dataType);
3167
+ this.readFileCache = { filePath, data: fileData };
3168
+ }
3161
3169
  let startIndex = 0;
3162
3170
  if (i === currentFileIndex) {
3163
3171
  startIndex = this.currentRecord - cumulativeRecords;
@@ -3171,6 +3179,7 @@ var FileDatabase = class _FileDatabase {
3171
3179
  throw new FileDatabaseError(`Failed to read file ${file.fileName}: ${error.message}`);
3172
3180
  }
3173
3181
  }
3182
+ this.currentRecord += recordsRead;
3174
3183
  if (result.length > 0) {
3175
3184
  if (nextPage || pageSize !== void 0 && pageSize < this.metadata.totalRecords) {
3176
3185
  this.hasReadFirstPage = true;
@@ -3184,6 +3193,7 @@ var FileDatabase = class _FileDatabase {
3184
3193
  setStartRecord(startRecord) {
3185
3194
  this.currentRecord = startRecord - 1;
3186
3195
  this.hasReadFirstPage = false;
3196
+ this.readFileCache = null;
3187
3197
  }
3188
3198
  /**
3189
3199
  * Reset read pagination state
@@ -3191,6 +3201,7 @@ var FileDatabase = class _FileDatabase {
3191
3201
  resetPagination() {
3192
3202
  this.currentRecord = 0;
3193
3203
  this.hasReadFirstPage = false;
3204
+ this.readFileCache = null;
3194
3205
  }
3195
3206
  /**
3196
3207
  * List filenames in the table directory.