@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.
package/dist/tasks.cjs CHANGED
@@ -990,8 +990,13 @@ var FileDatabase = class _FileDatabase {
990
990
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
991
991
  }
992
992
  /**
993
- * Create a new version folder with comprehensive timestamp logic
994
- * Only works in versioned mode
993
+ * Create a new version folder named with the current UTC second.
994
+ * Only works in versioned mode.
995
+ *
996
+ * Clash protection: if that name already exists (two writers in the same
997
+ * second, or wall clock behind the latest version), advance +1s until free.
998
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
999
+ * hours apart still land one second apart on disk.
995
1000
  */
996
1001
  async makeNewVersion() {
997
1002
  if (!this.versioned) {
@@ -999,19 +1004,22 @@ var FileDatabase = class _FileDatabase {
999
1004
  }
1000
1005
  this.metadata = this.getDefaultMetadata();
1001
1006
  const existingVersions = await this.getVersions();
1002
- let versionName;
1007
+ const existingSet = new Set(existingVersions);
1008
+ let candidateMs = Date.now();
1003
1009
  if (existingVersions.length > 0) {
1004
- const maxTimestamp = existingVersions.reduce((max, version) => {
1005
- const versionDate = new Date(version.replace("Z", ""));
1006
- const maxDate2 = new Date(max.replace("Z", ""));
1007
- return versionDate > maxDate2 ? version : max;
1008
- });
1009
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
1010
- const nextDate = new Date(maxDate.getTime() + 1e3);
1011
- versionName = nextDate.toISOString().split(".")[0] + "Z";
1012
- } else {
1013
- const now = /* @__PURE__ */ new Date();
1014
- versionName = now.toISOString().split(".")[0] + "Z";
1010
+ let maxMs = 0;
1011
+ for (const version of existingVersions) {
1012
+ const ms = new Date(version).getTime();
1013
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
1014
+ }
1015
+ if (candidateMs <= maxMs) {
1016
+ candidateMs = maxMs + 1e3;
1017
+ }
1018
+ }
1019
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
1020
+ while (existingSet.has(versionName)) {
1021
+ candidateMs += 1e3;
1022
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
1015
1023
  }
1016
1024
  await this.setCurrentVersion(versionName);
1017
1025
  this.currentFileNumber = 0;