@nmakarov/cli-toolkit 0.11.1 → 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,8 +2506,26 @@ var FileDatabase = class {
2506
2506
  figureOutDataAndFileToWrite(data) {
2507
2507
  let dataToWrite;
2508
2508
  let dataLeftOver;
2509
+ const incomingDataType = detectDataType(data);
2510
+ if (this.metadata.dataType !== incomingDataType) {
2511
+ this.metadata.dataType = incomingDataType;
2512
+ }
2513
+ if (this.metadata.files.length === 0) {
2514
+ this.makeNewFile();
2515
+ }
2509
2516
  const lastFile = this.metadata.files[this.metadata.files.length - 1];
2510
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
+ }
2511
2529
  if (Array.isArray(data)) {
2512
2530
  if (lastFileRecordsCount < this.pageSize) {
2513
2531
  dataToWrite = [...this.lastFileData || [], ...data.slice(0, this.pageSize - lastFileRecordsCount)];
@@ -2690,10 +2708,13 @@ var FileDatabase = class {
2690
2708
  throw new FileDatabaseError("Cannot use forceNewVersion in non-versioned mode");
2691
2709
  }
2692
2710
  await this.prepare({ write: true });
2711
+ const incomingDataType = detectDataType(data);
2712
+ this.metadata.dataType = incomingDataType;
2693
2713
  if (options.forceNewVersion) {
2694
2714
  await this.makeNewVersion();
2695
2715
  this.metadata = this.getDefaultMetadata();
2696
2716
  this.metadata.version = this.currentVersion;
2717
+ this.metadata.dataType = incomingDataType;
2697
2718
  this.makeNewFile();
2698
2719
  }
2699
2720
  let { dataToWrite, dataLeftOver, fileName } = this.figureOutDataAndFileToWrite(data);