@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.js CHANGED
@@ -904,8 +904,13 @@ var FileDatabase = class _FileDatabase {
904
904
  this.currentVersionFolder = await ensurePath(this.getDestinationPath(), version);
905
905
  }
906
906
  /**
907
- * Create a new version folder with comprehensive timestamp logic
908
- * Only works in versioned mode
907
+ * Create a new version folder named with the current UTC second.
908
+ * Only works in versioned mode.
909
+ *
910
+ * Clash protection: if that name already exists (two writers in the same
911
+ * second, or wall clock behind the latest version), advance +1s until free.
912
+ * Do NOT always derive from max(existing)+1s — that made successive harvests
913
+ * hours apart still land one second apart on disk.
909
914
  */
910
915
  async makeNewVersion() {
911
916
  if (!this.versioned) {
@@ -913,19 +918,22 @@ var FileDatabase = class _FileDatabase {
913
918
  }
914
919
  this.metadata = this.getDefaultMetadata();
915
920
  const existingVersions = await this.getVersions();
916
- let versionName;
921
+ const existingSet = new Set(existingVersions);
922
+ let candidateMs = Date.now();
917
923
  if (existingVersions.length > 0) {
918
- const maxTimestamp = existingVersions.reduce((max, version) => {
919
- const versionDate = new Date(version.replace("Z", ""));
920
- const maxDate2 = new Date(max.replace("Z", ""));
921
- return versionDate > maxDate2 ? version : max;
922
- });
923
- const maxDate = new Date(maxTimestamp.replace("Z", ""));
924
- const nextDate = new Date(maxDate.getTime() + 1e3);
925
- versionName = nextDate.toISOString().split(".")[0] + "Z";
926
- } else {
927
- const now = /* @__PURE__ */ new Date();
928
- versionName = now.toISOString().split(".")[0] + "Z";
924
+ let maxMs = 0;
925
+ for (const version of existingVersions) {
926
+ const ms = new Date(version).getTime();
927
+ if (Number.isFinite(ms) && ms > maxMs) maxMs = ms;
928
+ }
929
+ if (candidateMs <= maxMs) {
930
+ candidateMs = maxMs + 1e3;
931
+ }
932
+ }
933
+ let versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
934
+ while (existingSet.has(versionName)) {
935
+ candidateMs += 1e3;
936
+ versionName = new Date(candidateMs).toISOString().split(".")[0] + "Z";
929
937
  }
930
938
  await this.setCurrentVersion(versionName);
931
939
  this.currentFileNumber = 0;