zen-fs-config 0.5.15 → 0.5.17

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
  /**
@@ -954,13 +971,17 @@ var ConfigRepo = class {
954
971
  async safeExists(fs, path) {
955
972
  try {
956
973
  if (typeof fs.exists === "function") {
974
+ console.log(`[TOMB-TRACE] safeExists: calling fs.exists(${path})`);
957
975
  const result = await fs.exists(path);
976
+ console.log(`[TOMB-TRACE] safeExists: fs.exists(${path}) \u2192 ${result}`);
958
977
  return result;
959
978
  }
979
+ console.log(`[TOMB-TRACE] safeExists: no exists(), calling fs.stat(${path})`);
960
980
  await fs.stat(path);
981
+ console.log(`[TOMB-TRACE] safeExists: fs.stat(${path}) \u2192 OK (exists)`);
961
982
  return true;
962
983
  } catch (err) {
963
- console.log(`[ConfigRepo] safeExists(${path}): threw ${err?.code ?? err?.status ?? ""} ${err?.message ?? err}`);
984
+ console.log(`[TOMB-TRACE] safeExists(${path}): threw ${err?.code ?? err?.status ?? ""} ${err?.message ?? err}`);
964
985
  return false;
965
986
  }
966
987
  }
@@ -1238,6 +1259,7 @@ var ConfigRepo = class {
1238
1259
  async unlinkVersionSidecar(fs, configPath) {
1239
1260
  const vPath = versionPathFor(configPath);
1240
1261
  if (!vPath) return;
1262
+ if (!await this.safeExists(fs, vPath)) return;
1241
1263
  try {
1242
1264
  await fs.unlink(vPath);
1243
1265
  } catch {
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
  /**
@@ -864,13 +881,17 @@ var ConfigRepo = class {
864
881
  async safeExists(fs, path) {
865
882
  try {
866
883
  if (typeof fs.exists === "function") {
884
+ console.log(`[TOMB-TRACE] safeExists: calling fs.exists(${path})`);
867
885
  const result = await fs.exists(path);
886
+ console.log(`[TOMB-TRACE] safeExists: fs.exists(${path}) \u2192 ${result}`);
868
887
  return result;
869
888
  }
889
+ console.log(`[TOMB-TRACE] safeExists: no exists(), calling fs.stat(${path})`);
870
890
  await fs.stat(path);
891
+ console.log(`[TOMB-TRACE] safeExists: fs.stat(${path}) \u2192 OK (exists)`);
871
892
  return true;
872
893
  } catch (err) {
873
- console.log(`[ConfigRepo] safeExists(${path}): threw ${err?.code ?? err?.status ?? ""} ${err?.message ?? err}`);
894
+ console.log(`[TOMB-TRACE] safeExists(${path}): threw ${err?.code ?? err?.status ?? ""} ${err?.message ?? err}`);
874
895
  return false;
875
896
  }
876
897
  }
@@ -1148,6 +1169,7 @@ var ConfigRepo = class {
1148
1169
  async unlinkVersionSidecar(fs, configPath) {
1149
1170
  const vPath = versionPathFor(configPath);
1150
1171
  if (!vPath) return;
1172
+ if (!await this.safeExists(fs, vPath)) return;
1151
1173
  try {
1152
1174
  await fs.unlink(vPath);
1153
1175
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.5.15",
3
+ "version": "0.5.17",
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",