@nmakarov/cli-toolkit 0.63.0 → 0.65.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.
@@ -4494,8 +4494,13 @@ var FileDatabase = class _FileDatabase {
4494
4494
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
4495
4495
  }
4496
4496
  /**
4497
- * Create a new version folder with comprehensive timestamp logic
4498
- * Only works in versioned mode
4497
+ * Create a new version folder named with the current UTC second.
4498
+ * Only works in versioned mode.
4499
+ *
4500
+ * Clash protection: if that name already exists (two writers in the same
4501
+ * second, or wall clock behind the latest version), advance +1s until free.
4502
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
4503
+ * hours apart still land one second apart on disk.
4499
4504
  */
4500
4505
  async makeNewVersion() {
4501
4506
  if (!this.versioned) {
@@ -4503,19 +4508,22 @@ var FileDatabase = class _FileDatabase {
4503
4508
  }
4504
4509
  this.metadata = this.getDefaultMetadata();
4505
4510
  const existingVersions = await this.getVersions();
4506
- let versionName;
4511
+ const existingSet = new Set(existingVersions);
4512
+ let candidateMs = Date.now();
4507
4513
  if (existingVersions.length > 0) {
4508
- const maxTimestamp = existingVersions.reduce((max, version) => {
4509
- const versionDate = new Date(version.replace("Z", ""));
4510
- const maxDate2 = new Date(max.replace("Z", ""));
4511
- return versionDate > maxDate2 ? version : max;
4512
- });
4513
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
4514
- const nextDate = new Date(maxDate.getTime() + 1e3);
4515
- versionName = nextDate.toISOString().split(".")[0] + "Z";
4516
- } else {
4517
- const now = /* @__PURE__ */ new Date();
4518
- versionName = now.toISOString().split(".")[0] + "Z";
4514
+ let maxMs = 0;
4515
+ for (const version of existingVersions) {
4516
+ const ms = new Date(version).getTime();
4517
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
4518
+ }
4519
+ if (candidateMs <= maxMs) {
4520
+ candidateMs = maxMs + 1e3;
4521
+ }
4522
+ }
4523
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
4524
+ while (existingSet.has(versionName)) {
4525
+ candidateMs += 1e3;
4526
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
4519
4527
  }
4520
4528
  await this.setCurrentVersion(versionName);
4521
4529
  this.currentFileNumber = 0;