@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.js CHANGED
@@ -2452,8 +2452,13 @@ var FileDatabase = class _FileDatabase {
2452
2452
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
2453
2453
  }
2454
2454
  /**
2455
- * Create a new version folder with comprehensive timestamp logic
2456
- * Only works in versioned mode
2455
+ * Create a new version folder named with the current UTC second.
2456
+ * Only works in versioned mode.
2457
+ *
2458
+ * Clash protection: if that name already exists (two writers in the same
2459
+ * second, or wall clock behind the latest version), advance +1s until free.
2460
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
2461
+ * hours apart still land one second apart on disk.
2457
2462
  */
2458
2463
  async makeNewVersion() {
2459
2464
  if (!this.versioned) {
@@ -2461,19 +2466,22 @@ var FileDatabase = class _FileDatabase {
2461
2466
  }
2462
2467
  this.metadata = this.getDefaultMetadata();
2463
2468
  const existingVersions = await this.getVersions();
2464
- let versionName;
2469
+ const existingSet = new Set(existingVersions);
2470
+ let candidateMs = Date.now();
2465
2471
  if (existingVersions.length > 0) {
2466
- const maxTimestamp = existingVersions.reduce((max, version) => {
2467
- const versionDate = new Date(version.replace("Z", ""));
2468
- const maxDate2 = new Date(max.replace("Z", ""));
2469
- return versionDate > maxDate2 ? version : max;
2470
- });
2471
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
2472
- const nextDate = new Date(maxDate.getTime() + 1e3);
2473
- versionName = nextDate.toISOString().split(".")[0] + "Z";
2474
- } else {
2475
- const now = /* @__PURE__ */ new Date();
2476
- versionName = now.toISOString().split(".")[0] + "Z";
2472
+ let maxMs = 0;
2473
+ for (const version of existingVersions) {
2474
+ const ms = new Date(version).getTime();
2475
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
2476
+ }
2477
+ if (candidateMs <= maxMs) {
2478
+ candidateMs = maxMs + 1e3;
2479
+ }
2480
+ }
2481
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
2482
+ while (existingSet.has(versionName)) {
2483
+ candidateMs += 1e3;
2484
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
2477
2485
  }
2478
2486
  await this.setCurrentVersion(versionName);
2479
2487
  this.currentFileNumber = 0;
@@ -3285,6 +3293,12 @@ var FileDatabase = class _FileDatabase {
3285
3293
  getCurrentVersion() {
3286
3294
  return this.currentVersion;
3287
3295
  }
3296
+ /**
3297
+ * Max retained version folders (used by harvest_sync.loaded_versions cap, etc.).
3298
+ */
3299
+ getMaxVersions() {
3300
+ return this.maxVersions;
3301
+ }
3288
3302
  /**
3289
3303
  * Get current metadata
3290
3304
  */