zen-fs-config 0.5.16 → 0.5.18

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
@@ -904,9 +904,11 @@ var ConfigRepo = class {
904
904
  let alreadyDeleted = 0;
905
905
  for (const tombstone of tombstones) {
906
906
  const tVersionPath = versionPathFor(tombstone.path);
907
+ console.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"}`);
907
908
  const existedOnPrimary = await this.safeExists(this.cachedFS, tombstone.path);
909
+ console.log(`[TOMB-TRACE] primary safeExists(${tombstone.path}) \u2192 ${existedOnPrimary}`);
908
910
  if (existedOnPrimary) {
909
- console.log(`[ConfigRepo] tombstone check: ${tombstone.path} on primary \u2192 EXISTS`);
911
+ console.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on primary \u2192 EXISTS`);
910
912
  }
911
913
  if (existedOnPrimary) {
912
914
  try {
@@ -915,36 +917,51 @@ var ConfigRepo = class {
915
917
  } catch {
916
918
  }
917
919
  }
918
- if (tVersionPath && await this.safeExists(this.cachedFS, tVersionPath)) {
919
- try {
920
- await this.cachedFS.unlink(tVersionPath);
921
- } catch {
920
+ if (tVersionPath) {
921
+ const vExistedOnPrimary = await this.safeExists(this.cachedFS, tVersionPath);
922
+ console.log(`[TOMB-TRACE] primary safeExists(${tVersionPath}) \u2192 ${vExistedOnPrimary}`);
923
+ if (vExistedOnPrimary) {
924
+ try {
925
+ await this.cachedFS.unlink(tVersionPath);
926
+ } catch {
927
+ }
922
928
  }
923
929
  }
924
930
  for (const [replicaId, replica] of this.replicaBackends) {
931
+ console.log(`[TOMB-TRACE] checking replica: ${replicaId} for ${tombstone.path}`);
925
932
  const existed = await this.safeExists(replica.instance, tombstone.path);
933
+ console.log(`[TOMB-TRACE] replica ${replicaId} safeExists(${tombstone.path}) \u2192 ${existed}`);
926
934
  if (existed) {
927
- console.log(`[ConfigRepo] tombstone check: ${tombstone.path} on ${replicaId} \u2192 EXISTS`);
935
+ console.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on ${replicaId} \u2192 EXISTS`);
928
936
  try {
937
+ console.log(`[TOMB-TRACE] calling unlink(${tombstone.path}) on ${replicaId}`);
929
938
  await replica.instance.unlink(tombstone.path);
930
- console.log(`[ConfigRepo] tombstone ${tombstone.path}: deleted on ${replicaId}`);
939
+ console.log(`[TOMB-TRACE] tombstone ${tombstone.path}: deleted on ${replicaId}`);
931
940
  processed++;
932
- } catch {
941
+ } catch (err) {
942
+ console.log(`[TOMB-TRACE] unlink(${tombstone.path}) on ${replicaId} FAILED: ${err}`);
933
943
  alreadyDeleted++;
934
944
  }
935
945
  } else {
946
+ console.log(`[TOMB-TRACE] replica ${replicaId}: already gone, skipping unlink`);
936
947
  alreadyDeleted++;
937
948
  }
938
- if (tVersionPath && await this.safeExists(replica.instance, tVersionPath)) {
939
- try {
940
- await replica.instance.unlink(tVersionPath);
941
- } catch {
949
+ if (tVersionPath) {
950
+ const vExisted = await this.safeExists(replica.instance, tVersionPath);
951
+ console.log(`[TOMB-TRACE] replica ${replicaId} safeExists(${tVersionPath}) \u2192 ${vExisted}`);
952
+ if (vExisted) {
953
+ try {
954
+ console.log(`[TOMB-TRACE] calling unlink(${tVersionPath}) on ${replicaId}`);
955
+ await replica.instance.unlink(tVersionPath);
956
+ } catch (err) {
957
+ console.log(`[TOMB-TRACE] unlink(${tVersionPath}) on ${replicaId} FAILED: ${err}`);
958
+ }
942
959
  }
943
960
  }
944
961
  }
945
962
  }
946
963
  if (processed > 0 || alreadyDeleted > 0) {
947
- console.log(`[ConfigRepo] processTombstones: ${tombstones.length} tombstone(s), ${processed} deleted, ${alreadyDeleted} already gone`);
964
+ console.log(`[TOMB-TRACE] processTombstones: ${tombstones.length} tombstone(s), ${processed} deleted, ${alreadyDeleted} already gone`);
948
965
  }
949
966
  }
950
967
  /**
@@ -953,14 +970,28 @@ var ConfigRepo = class {
953
970
  */
954
971
  async safeExists(fs, path) {
955
972
  try {
956
- if (typeof fs.exists === "function") {
973
+ const ctorName = fs?.constructor?.name ?? typeof fs;
974
+ const hasExists = typeof fs?.exists === "function";
975
+ const hasStat = typeof fs?.stat === "function";
976
+ const innerBackend = fs?.inner?.constructor?.name;
977
+ const innerBackendName = fs?.inner?.backendName;
978
+ const directBackendName = fs?.backendName;
979
+ const backendLabel = innerBackendName ?? directBackendName ?? innerBackend ?? ctorName;
980
+ console.log(`[TOMB-TRACE] safeExists(${path}): fs type=${ctorName} backend=${backendLabel} hasExists=${hasExists} hasStat=${hasStat} inner=${innerBackend ?? "N/A"}`);
981
+ if (hasExists) {
982
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2192 calling fs.exists() [backend=${backendLabel}]`);
957
983
  const result = await fs.exists(path);
984
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2190 fs.exists() [backend=${backendLabel}] \u2192 ${result}`);
958
985
  return result;
959
986
  }
987
+ console.log(`[TOMB-TRACE] safeExists(${path}): no exists(), calling fs.stat() [backend=${backendLabel}]`);
960
988
  await fs.stat(path);
989
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2190 fs.stat() [backend=${backendLabel}] \u2192 OK (exists)`);
961
990
  return true;
962
991
  } catch (err) {
963
- console.log(`[ConfigRepo] safeExists(${path}): threw ${err?.code ?? err?.status ?? ""} ${err?.message ?? err}`);
992
+ const errCode = err?.code ?? err?.status ?? "";
993
+ const errName = err?.constructor?.name ?? "";
994
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2190 ERROR ${errName} ${errCode} ${err?.message ?? err}`);
964
995
  return false;
965
996
  }
966
997
  }
package/dist/index.mjs CHANGED
@@ -814,9 +814,11 @@ var ConfigRepo = class {
814
814
  let alreadyDeleted = 0;
815
815
  for (const tombstone of tombstones) {
816
816
  const tVersionPath = versionPathFor(tombstone.path);
817
+ console.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"}`);
817
818
  const existedOnPrimary = await this.safeExists(this.cachedFS, tombstone.path);
819
+ console.log(`[TOMB-TRACE] primary safeExists(${tombstone.path}) \u2192 ${existedOnPrimary}`);
818
820
  if (existedOnPrimary) {
819
- console.log(`[ConfigRepo] tombstone check: ${tombstone.path} on primary \u2192 EXISTS`);
821
+ console.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on primary \u2192 EXISTS`);
820
822
  }
821
823
  if (existedOnPrimary) {
822
824
  try {
@@ -825,36 +827,51 @@ var ConfigRepo = class {
825
827
  } catch {
826
828
  }
827
829
  }
828
- if (tVersionPath && await this.safeExists(this.cachedFS, tVersionPath)) {
829
- try {
830
- await this.cachedFS.unlink(tVersionPath);
831
- } catch {
830
+ if (tVersionPath) {
831
+ const vExistedOnPrimary = await this.safeExists(this.cachedFS, tVersionPath);
832
+ console.log(`[TOMB-TRACE] primary safeExists(${tVersionPath}) \u2192 ${vExistedOnPrimary}`);
833
+ if (vExistedOnPrimary) {
834
+ try {
835
+ await this.cachedFS.unlink(tVersionPath);
836
+ } catch {
837
+ }
832
838
  }
833
839
  }
834
840
  for (const [replicaId, replica] of this.replicaBackends) {
841
+ console.log(`[TOMB-TRACE] checking replica: ${replicaId} for ${tombstone.path}`);
835
842
  const existed = await this.safeExists(replica.instance, tombstone.path);
843
+ console.log(`[TOMB-TRACE] replica ${replicaId} safeExists(${tombstone.path}) \u2192 ${existed}`);
836
844
  if (existed) {
837
- console.log(`[ConfigRepo] tombstone check: ${tombstone.path} on ${replicaId} \u2192 EXISTS`);
845
+ console.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on ${replicaId} \u2192 EXISTS`);
838
846
  try {
847
+ console.log(`[TOMB-TRACE] calling unlink(${tombstone.path}) on ${replicaId}`);
839
848
  await replica.instance.unlink(tombstone.path);
840
- console.log(`[ConfigRepo] tombstone ${tombstone.path}: deleted on ${replicaId}`);
849
+ console.log(`[TOMB-TRACE] tombstone ${tombstone.path}: deleted on ${replicaId}`);
841
850
  processed++;
842
- } catch {
851
+ } catch (err) {
852
+ console.log(`[TOMB-TRACE] unlink(${tombstone.path}) on ${replicaId} FAILED: ${err}`);
843
853
  alreadyDeleted++;
844
854
  }
845
855
  } else {
856
+ console.log(`[TOMB-TRACE] replica ${replicaId}: already gone, skipping unlink`);
846
857
  alreadyDeleted++;
847
858
  }
848
- if (tVersionPath && await this.safeExists(replica.instance, tVersionPath)) {
849
- try {
850
- await replica.instance.unlink(tVersionPath);
851
- } catch {
859
+ if (tVersionPath) {
860
+ const vExisted = await this.safeExists(replica.instance, tVersionPath);
861
+ console.log(`[TOMB-TRACE] replica ${replicaId} safeExists(${tVersionPath}) \u2192 ${vExisted}`);
862
+ if (vExisted) {
863
+ try {
864
+ console.log(`[TOMB-TRACE] calling unlink(${tVersionPath}) on ${replicaId}`);
865
+ await replica.instance.unlink(tVersionPath);
866
+ } catch (err) {
867
+ console.log(`[TOMB-TRACE] unlink(${tVersionPath}) on ${replicaId} FAILED: ${err}`);
868
+ }
852
869
  }
853
870
  }
854
871
  }
855
872
  }
856
873
  if (processed > 0 || alreadyDeleted > 0) {
857
- console.log(`[ConfigRepo] processTombstones: ${tombstones.length} tombstone(s), ${processed} deleted, ${alreadyDeleted} already gone`);
874
+ console.log(`[TOMB-TRACE] processTombstones: ${tombstones.length} tombstone(s), ${processed} deleted, ${alreadyDeleted} already gone`);
858
875
  }
859
876
  }
860
877
  /**
@@ -863,14 +880,28 @@ var ConfigRepo = class {
863
880
  */
864
881
  async safeExists(fs, path) {
865
882
  try {
866
- if (typeof fs.exists === "function") {
883
+ const ctorName = fs?.constructor?.name ?? typeof fs;
884
+ const hasExists = typeof fs?.exists === "function";
885
+ const hasStat = typeof fs?.stat === "function";
886
+ const innerBackend = fs?.inner?.constructor?.name;
887
+ const innerBackendName = fs?.inner?.backendName;
888
+ const directBackendName = fs?.backendName;
889
+ const backendLabel = innerBackendName ?? directBackendName ?? innerBackend ?? ctorName;
890
+ console.log(`[TOMB-TRACE] safeExists(${path}): fs type=${ctorName} backend=${backendLabel} hasExists=${hasExists} hasStat=${hasStat} inner=${innerBackend ?? "N/A"}`);
891
+ if (hasExists) {
892
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2192 calling fs.exists() [backend=${backendLabel}]`);
867
893
  const result = await fs.exists(path);
894
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2190 fs.exists() [backend=${backendLabel}] \u2192 ${result}`);
868
895
  return result;
869
896
  }
897
+ console.log(`[TOMB-TRACE] safeExists(${path}): no exists(), calling fs.stat() [backend=${backendLabel}]`);
870
898
  await fs.stat(path);
899
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2190 fs.stat() [backend=${backendLabel}] \u2192 OK (exists)`);
871
900
  return true;
872
901
  } catch (err) {
873
- console.log(`[ConfigRepo] safeExists(${path}): threw ${err?.code ?? err?.status ?? ""} ${err?.message ?? err}`);
902
+ const errCode = err?.code ?? err?.status ?? "";
903
+ const errName = err?.constructor?.name ?? "";
904
+ console.log(`[TOMB-TRACE] safeExists(${path}): \u2190 ERROR ${errName} ${errCode} ${err?.message ?? err}`);
874
905
  return false;
875
906
  }
876
907
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.5.16",
3
+ "version": "0.5.18",
4
4
  "description": "Distributed config management library built on ZenFS, zen-fs-cache, and zen-fs-sync",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",