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