@nmakarov/cli-toolkit 0.63.0 → 0.66.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.cjs CHANGED
@@ -2643,8 +2643,13 @@ var FileDatabase = class _FileDatabase {
2643
2643
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
2644
2644
  }
2645
2645
  /**
2646
- * Create a new version folder with comprehensive timestamp logic
2647
- * Only works in versioned mode
2646
+ * Create a new version folder named with the current UTC second.
2647
+ * Only works in versioned mode.
2648
+ *
2649
+ * Clash protection: if that name already exists (two writers in the same
2650
+ * second, or wall clock behind the latest version), advance +1s until free.
2651
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
2652
+ * hours apart still land one second apart on disk.
2648
2653
  */
2649
2654
  async makeNewVersion() {
2650
2655
  if (!this.versioned) {
@@ -2652,19 +2657,22 @@ var FileDatabase = class _FileDatabase {
2652
2657
  }
2653
2658
  this.metadata = this.getDefaultMetadata();
2654
2659
  const existingVersions = await this.getVersions();
2655
- let versionName;
2660
+ const existingSet = new Set(existingVersions);
2661
+ let candidateMs = Date.now();
2656
2662
  if (existingVersions.length > 0) {
2657
- const maxTimestamp = existingVersions.reduce((max, version) => {
2658
- const versionDate = new Date(version.replace("Z", ""));
2659
- const maxDate2 = new Date(max.replace("Z", ""));
2660
- return versionDate > maxDate2 ? version : max;
2661
- });
2662
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
2663
- const nextDate = new Date(maxDate.getTime() + 1e3);
2664
- versionName = nextDate.toISOString().split(".")[0] + "Z";
2665
- } else {
2666
- const now = /* @__PURE__ */ new Date();
2667
- versionName = now.toISOString().split(".")[0] + "Z";
2663
+ let maxMs = 0;
2664
+ for (const version of existingVersions) {
2665
+ const ms = new Date(version).getTime();
2666
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
2667
+ }
2668
+ if (candidateMs <= maxMs) {
2669
+ candidateMs = maxMs + 1e3;
2670
+ }
2671
+ }
2672
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
2673
+ while (existingSet.has(versionName)) {
2674
+ candidateMs += 1e3;
2675
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
2668
2676
  }
2669
2677
  await this.setCurrentVersion(versionName);
2670
2678
  this.currentFileNumber = 0;
@@ -3476,6 +3484,12 @@ var FileDatabase = class _FileDatabase {
3476
3484
  getCurrentVersion() {
3477
3485
  return this.currentVersion;
3478
3486
  }
3487
+ /**
3488
+ * Max retained version folders (used by harvest_sync.loaded_versions cap, etc.).
3489
+ */
3490
+ getMaxVersions() {
3491
+ return this.maxVersions;
3492
+ }
3479
3493
  /**
3480
3494
  * Get current metadata
3481
3495
  */