@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.
@@ -237,8 +237,13 @@ var FileDatabase = class _FileDatabase {
237
237
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
238
238
  }
239
239
  /**
240
- * Create a new version folder with comprehensive timestamp logic
241
- * Only works in versioned mode
240
+ * Create a new version folder named with the current UTC second.
241
+ * Only works in versioned mode.
242
+ *
243
+ * Clash protection: if that name already exists (two writers in the same
244
+ * second, or wall clock behind the latest version), advance +1s until free.
245
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
246
+ * hours apart still land one second apart on disk.
242
247
  */
243
248
  async makeNewVersion() {
244
249
  if (!this.versioned) {
@@ -246,19 +251,22 @@ var FileDatabase = class _FileDatabase {
246
251
  }
247
252
  this.metadata = this.getDefaultMetadata();
248
253
  const existingVersions = await this.getVersions();
249
- let versionName;
254
+ const existingSet = new Set(existingVersions);
255
+ let candidateMs = Date.now();
250
256
  if (existingVersions.length > 0) {
251
- const maxTimestamp = existingVersions.reduce((max, version) => {
252
- const versionDate = new Date(version.replace("Z", ""));
253
- const maxDate2 = new Date(max.replace("Z", ""));
254
- return versionDate > maxDate2 ? version : max;
255
- });
256
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
257
- const nextDate = new Date(maxDate.getTime() + 1e3);
258
- versionName = nextDate.toISOString().split(".")[0] + "Z";
259
- } else {
260
- const now = /* @__PURE__ */ new Date();
261
- versionName = now.toISOString().split(".")[0] + "Z";
257
+ let maxMs = 0;
258
+ for (const version of existingVersions) {
259
+ const ms = new Date(version).getTime();
260
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
261
+ }
262
+ if (candidateMs <= maxMs) {
263
+ candidateMs = maxMs + 1e3;
264
+ }
265
+ }
266
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
267
+ while (existingSet.has(versionName)) {
268
+ candidateMs += 1e3;
269
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
262
270
  }
263
271
  await this.setCurrentVersion(versionName);
264
272
  this.currentFileNumber = 0;