@nmakarov/cli-toolkit 0.61.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.
@@ -343,8 +343,13 @@ var FileDatabase = class _FileDatabase {
343
343
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
344
344
  }
345
345
  /**
346
- * Create a new version folder with comprehensive timestamp logic
347
- * Only works in versioned mode
346
+ * Create a new version folder named with the current UTC second.
347
+ * Only works in versioned mode.
348
+ *
349
+ * Clash protection: if that name already exists (two writers in the same
350
+ * second, or wall clock behind the latest version), advance +1s until free.
351
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
352
+ * hours apart still land one second apart on disk.
348
353
  */
349
354
  async makeNewVersion() {
350
355
  if (!this.versioned) {
@@ -352,19 +357,22 @@ var FileDatabase = class _FileDatabase {
352
357
  }
353
358
  this.metadata = this.getDefaultMetadata();
354
359
  const existingVersions = await this.getVersions();
355
- let versionName;
360
+ const existingSet = new Set(existingVersions);
361
+ let candidateMs = Date.now();
356
362
  if (existingVersions.length > 0) {
357
- const maxTimestamp = existingVersions.reduce((max, version) => {
358
- const versionDate = new Date(version.replace("Z", ""));
359
- const maxDate2 = new Date(max.replace("Z", ""));
360
- return versionDate > maxDate2 ? version : max;
361
- });
362
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
363
- const nextDate = new Date(maxDate.getTime() + 1e3);
364
- versionName = nextDate.toISOString().split(".")[0] + "Z";
365
- } else {
366
- const now = /* @__PURE__ */ new Date();
367
- versionName = now.toISOString().split(".")[0] + "Z";
363
+ let maxMs = 0;
364
+ for (const version of existingVersions) {
365
+ const ms = new Date(version).getTime();
366
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
367
+ }
368
+ if (candidateMs <= maxMs) {
369
+ candidateMs = maxMs + 1e3;
370
+ }
371
+ }
372
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
373
+ while (existingSet.has(versionName)) {
374
+ candidateMs += 1e3;
375
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
368
376
  }
369
377
  await this.setCurrentVersion(versionName);
370
378
  this.currentFileNumber = 0;