@nmakarov/cli-toolkit 0.11.2 → 0.11.3

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
@@ -2506,14 +2506,26 @@ var FileDatabase = class {
2506
2506
  figureOutDataAndFileToWrite(data) {
2507
2507
  let dataToWrite;
2508
2508
  let dataLeftOver;
2509
- if (!this.metadata.dataType) {
2510
- this.metadata.dataType = detectDataType(data);
2509
+ const incomingDataType = detectDataType(data);
2510
+ if (this.metadata.dataType !== incomingDataType) {
2511
+ this.metadata.dataType = incomingDataType;
2511
2512
  }
2512
2513
  if (this.metadata.files.length === 0) {
2513
2514
  this.makeNewFile();
2514
2515
  }
2515
2516
  const lastFile = this.metadata.files[this.metadata.files.length - 1];
2516
2517
  const lastFileRecordsCount = lastFile.recordsCount;
2518
+ if (!Array.isArray(data)) {
2519
+ const lastFileExtension = path3.extname(lastFile.fileName);
2520
+ const expectedExtension = `.${getFileExtension(incomingDataType)}`;
2521
+ if (lastFileExtension !== expectedExtension) {
2522
+ if (lastFileRecordsCount > 0) {
2523
+ this.makeNewFile();
2524
+ } else {
2525
+ lastFile.fileName = `${this.currentFileNumber.toString().padStart(6, "0")}.${getFileExtension(incomingDataType)}`;
2526
+ }
2527
+ }
2528
+ }
2517
2529
  if (Array.isArray(data)) {
2518
2530
  if (lastFileRecordsCount < this.pageSize) {
2519
2531
  dataToWrite = [...this.lastFileData || [], ...data.slice(0, this.pageSize - lastFileRecordsCount)];
@@ -2696,10 +2708,13 @@ var FileDatabase = class {
2696
2708
  throw new FileDatabaseError("Cannot use forceNewVersion in non-versioned mode");
2697
2709
  }
2698
2710
  await this.prepare({ write: true });
2711
+ const incomingDataType = detectDataType(data);
2712
+ this.metadata.dataType = incomingDataType;
2699
2713
  if (options.forceNewVersion) {
2700
2714
  await this.makeNewVersion();
2701
2715
  this.metadata = this.getDefaultMetadata();
2702
2716
  this.metadata.version = this.currentVersion;
2717
+ this.metadata.dataType = incomingDataType;
2703
2718
  this.makeNewFile();
2704
2719
  }
2705
2720
  let { dataToWrite, dataLeftOver, fileName } = this.figureOutDataAndFileToWrite(data);