@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.
@@ -271,8 +271,13 @@ var FileDatabase = class _FileDatabase {
271
271
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
272
272
  }
273
273
  /**
274
- * Create a new version folder with comprehensive timestamp logic
275
- * Only works in versioned mode
274
+ * Create a new version folder named with the current UTC second.
275
+ * Only works in versioned mode.
276
+ *
277
+ * Clash protection: if that name already exists (two writers in the same
278
+ * second, or wall clock behind the latest version), advance +1s until free.
279
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
280
+ * hours apart still land one second apart on disk.
276
281
  */
277
282
  async makeNewVersion() {
278
283
  if (!this.versioned) {
@@ -280,19 +285,22 @@ var FileDatabase = class _FileDatabase {
280
285
  }
281
286
  this.metadata = this.getDefaultMetadata();
282
287
  const existingVersions = await this.getVersions();
283
- let versionName;
288
+ const existingSet = new Set(existingVersions);
289
+ let candidateMs = Date.now();
284
290
  if (existingVersions.length > 0) {
285
- const maxTimestamp = existingVersions.reduce((max, version) => {
286
- const versionDate = new Date(version.replace("Z", ""));
287
- const maxDate2 = new Date(max.replace("Z", ""));
288
- return versionDate > maxDate2 ? version : max;
289
- });
290
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
291
- const nextDate = new Date(maxDate.getTime() + 1e3);
292
- versionName = nextDate.toISOString().split(".")[0] + "Z";
293
- } else {
294
- const now = /* @__PURE__ */ new Date();
295
- versionName = now.toISOString().split(".")[0] + "Z";
291
+ let maxMs = 0;
292
+ for (const version of existingVersions) {
293
+ const ms = new Date(version).getTime();
294
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
295
+ }
296
+ if (candidateMs <= maxMs) {
297
+ candidateMs = maxMs + 1e3;
298
+ }
299
+ }
300
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
301
+ while (existingSet.has(versionName)) {
302
+ candidateMs += 1e3;
303
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
296
304
  }
297
305
  await this.setCurrentVersion(versionName);
298
306
  this.currentFileNumber = 0;
@@ -1104,6 +1112,12 @@ var FileDatabase = class _FileDatabase {
1104
1112
  getCurrentVersion() {
1105
1113
  return this.currentVersion;
1106
1114
  }
1115
+ /**
1116
+ * Max retained version folders (used by harvest_sync.loaded_versions cap, etc.).
1117
+ */
1118
+ getMaxVersions() {
1119
+ return this.maxVersions;
1120
+ }
1107
1121
  /**
1108
1122
  * Get current metadata
1109
1123
  */