@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.
@@ -377,8 +377,13 @@ var FileDatabase = class _FileDatabase {
377
377
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
378
378
  }
379
379
  /**
380
- * Create a new version folder with comprehensive timestamp logic
381
- * Only works in versioned mode
380
+ * Create a new version folder named with the current UTC second.
381
+ * Only works in versioned mode.
382
+ *
383
+ * Clash protection: if that name already exists (two writers in the same
384
+ * second, or wall clock behind the latest version), advance +1s until free.
385
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
386
+ * hours apart still land one second apart on disk.
382
387
  */
383
388
  async makeNewVersion() {
384
389
  if (!this.versioned) {
@@ -386,19 +391,22 @@ var FileDatabase = class _FileDatabase {
386
391
  }
387
392
  this.metadata = this.getDefaultMetadata();
388
393
  const existingVersions = await this.getVersions();
389
- let versionName;
394
+ const existingSet = new Set(existingVersions);
395
+ let candidateMs = Date.now();
390
396
  if (existingVersions.length > 0) {
391
- const maxTimestamp = existingVersions.reduce((max, version) => {
392
- const versionDate = new Date(version.replace("Z", ""));
393
- const maxDate2 = new Date(max.replace("Z", ""));
394
- return versionDate > maxDate2 ? version : max;
395
- });
396
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
397
- const nextDate = new Date(maxDate.getTime() + 1e3);
398
- versionName = nextDate.toISOString().split(".")[0] + "Z";
399
- } else {
400
- const now = /* @__PURE__ */ new Date();
401
- versionName = now.toISOString().split(".")[0] + "Z";
397
+ let maxMs = 0;
398
+ for (const version of existingVersions) {
399
+ const ms = new Date(version).getTime();
400
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
401
+ }
402
+ if (candidateMs <= maxMs) {
403
+ candidateMs = maxMs + 1e3;
404
+ }
405
+ }
406
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
407
+ while (existingSet.has(versionName)) {
408
+ candidateMs += 1e3;
409
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
402
410
  }
403
411
  await this.setCurrentVersion(versionName);
404
412
  this.currentFileNumber = 0;
@@ -1210,6 +1218,12 @@ var FileDatabase = class _FileDatabase {
1210
1218
  getCurrentVersion() {
1211
1219
  return this.currentVersion;
1212
1220
  }
1221
+ /**
1222
+ * Max retained version folders (used by harvest_sync.loaded_versions cap, etc.).
1223
+ */
1224
+ getMaxVersions() {
1225
+ return this.maxVersions;
1226
+ }
1213
1227
  /**
1214
1228
  * Get current metadata
1215
1229
  */