zen-fs-config 0.5.49 → 0.5.51

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.d.mts CHANGED
@@ -954,6 +954,12 @@ declare class ConfigRepo implements IConfigRepo {
954
954
  }): Promise<SyncResult>;
955
955
  peekNodeConfig<T = unknown>(nodeId: string, path: string): Promise<T>;
956
956
  flush(): Promise<SyncResult[]>;
957
+ /**
958
+ * Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
959
+ * mirror for one release cycle). Records only metadata — it never creates
960
+ * the deleted file locally.
961
+ */
962
+ private writeTombstoneFor;
957
963
  /**
958
964
  * Delete a file and write a tombstone so the deletion propagates
959
965
  * to all backends instead of being treated as "missing file → re-create".
package/dist/index.d.ts CHANGED
@@ -954,6 +954,12 @@ declare class ConfigRepo implements IConfigRepo {
954
954
  }): Promise<SyncResult>;
955
955
  peekNodeConfig<T = unknown>(nodeId: string, path: string): Promise<T>;
956
956
  flush(): Promise<SyncResult[]>;
957
+ /**
958
+ * Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
959
+ * mirror for one release cycle). Records only metadata — it never creates
960
+ * the deleted file locally.
961
+ */
962
+ private writeTombstoneFor;
957
963
  /**
958
964
  * Delete a file and write a tombstone so the deletion propagates
959
965
  * to all backends instead of being treated as "missing file → re-create".
package/dist/index.js CHANGED
@@ -1515,6 +1515,9 @@ async function existsSafe(fs, path) {
1515
1515
  return false;
1516
1516
  }
1517
1517
  }
1518
+ function isMtimeSidecarPath(path) {
1519
+ return path.endsWith(".mtime");
1520
+ }
1518
1521
  function encodeMetaPath(filePath) {
1519
1522
  const normalized = filePath.startsWith("/") ? filePath : `/${filePath}`;
1520
1523
  return normalized.replace(/^\//, "").replace(/\//g, "__").replace(/\./g, "++");
@@ -1607,7 +1610,7 @@ var TombstoneStore = class {
1607
1610
  }
1608
1611
  }
1609
1612
  async deleteEverywhere(fs, filePath) {
1610
- if (!await existsSafe(fs, filePath)) return;
1613
+ if (!isMtimeSidecarPath(filePath) && !await existsSafe(fs, filePath)) return;
1611
1614
  try {
1612
1615
  await fs.unlink(filePath);
1613
1616
  } catch {
@@ -1836,6 +1839,20 @@ async function collectFilesUnder(fs, dir, out = []) {
1836
1839
  }
1837
1840
  return out;
1838
1841
  }
1842
+ async function collectDirectoriesUnder(fs, dir, out = []) {
1843
+ out.push(dir);
1844
+ let entries;
1845
+ try {
1846
+ entries = await fs.readdir(dir);
1847
+ } catch {
1848
+ return out;
1849
+ }
1850
+ for (const entry of entries) {
1851
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
1852
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnder(fs, child, out);
1853
+ }
1854
+ return out;
1855
+ }
1839
1856
  async function removeDirectoryTree(fs, dir) {
1840
1857
  let entries;
1841
1858
  try {
@@ -2146,6 +2163,26 @@ var ConfigRepo = class {
2146
2163
  // -----------------------------------------------------------------------
2147
2164
  // Tombstone (Deletion Tracking)
2148
2165
  // -----------------------------------------------------------------------
2166
+ /**
2167
+ * Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
2168
+ * mirror for one release cycle). Records only metadata — it never creates
2169
+ * the deleted file locally.
2170
+ */
2171
+ async writeTombstoneFor(filePath) {
2172
+ const normalizedPath = filePath.startsWith("/") ? filePath : "/" + filePath;
2173
+ const tombstone = {
2174
+ path: normalizedPath,
2175
+ deletedAt: Date.now(),
2176
+ deletedBy: this.primaryBackendId,
2177
+ confirmedBy: [this.primaryBackendId]
2178
+ };
2179
+ const tombstoneBytes = new TextEncoder().encode(JSON.stringify(tombstone, null, 2));
2180
+ for (const dir of [TOMBSTONES_DIR, LEGACY_TOMBSTONES_DIR]) {
2181
+ const tombstonePath = tombstonePathFor(normalizedPath, dir);
2182
+ await this.ensureDir(tombstonePath);
2183
+ await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
2184
+ }
2185
+ }
2149
2186
  /**
2150
2187
  * Delete a file and write a tombstone so the deletion propagates
2151
2188
  * to all backends instead of being treated as "missing file → re-create".
@@ -2156,24 +2193,18 @@ var ConfigRepo = class {
2156
2193
  if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
2157
2194
  const files = await collectFilesUnder(this.cachedFS, normalizedPath);
2158
2195
  for (const file of files) await this.deleteFile(file);
2196
+ for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
2197
+ const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
2198
+ await this.writeTombstoneFor(keepPath);
2199
+ await this.writeTombstoneFor(`${keepPath}.mtime`);
2200
+ }
2159
2201
  await removeDirectoryTree(this.cachedFS, normalizedPath);
2160
2202
  this.invalidateTombstoneCache();
2161
2203
  this.schedulePostDeleteSync();
2162
2204
  log2.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
2163
2205
  return;
2164
2206
  }
2165
- const tombstone = {
2166
- path: normalizedPath,
2167
- deletedAt: Date.now(),
2168
- deletedBy: this.primaryBackendId,
2169
- confirmedBy: [this.primaryBackendId]
2170
- };
2171
- const tombstoneBytes = new TextEncoder().encode(JSON.stringify(tombstone, null, 2));
2172
- for (const dir of [TOMBSTONES_DIR, LEGACY_TOMBSTONES_DIR]) {
2173
- const tombstonePath = tombstonePathFor(normalizedPath, dir);
2174
- await this.ensureDir(tombstonePath);
2175
- await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
2176
- }
2207
+ await this.writeTombstoneFor(normalizedPath);
2177
2208
  try {
2178
2209
  await this.cachedFS.unlink(normalizedPath);
2179
2210
  } catch {
@@ -2185,6 +2216,12 @@ var ConfigRepo = class {
2185
2216
  } catch {
2186
2217
  }
2187
2218
  }
2219
+ if (!isMtimeSidecar(normalizedPath)) {
2220
+ try {
2221
+ await this.cachedFS.unlink(`${normalizedPath}.mtime`);
2222
+ } catch {
2223
+ }
2224
+ }
2188
2225
  log2.log(`[ConfigRepo] deleteFile: ${normalizedPath} (tombstone at ${tombstonePathFor(normalizedPath)})`);
2189
2226
  this.invalidateTombstoneCache();
2190
2227
  this.schedulePostDeleteSync();
@@ -2263,9 +2300,10 @@ var ConfigRepo = class {
2263
2300
  let processed = 0;
2264
2301
  let alreadyDeleted = 0;
2265
2302
  for (const tombstone of tombstones) {
2266
- const tVersionPath = versionPathFor(tombstone.path);
2267
- log2.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"}`);
2268
- const existedOnPrimary = await this.safeExists(this.cachedFS, tombstone.path);
2303
+ const forceDelete = isMtimeSidecar(tombstone.path);
2304
+ const tVersionPath = forceDelete ? null : versionPathFor(tombstone.path);
2305
+ log2.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"} forceDelete=${forceDelete}`);
2306
+ const existedOnPrimary = forceDelete || await this.safeExists(this.cachedFS, tombstone.path);
2269
2307
  log2.log(`[TOMB-TRACE] primary safeExists(${tombstone.path}) \u2192 ${existedOnPrimary}`);
2270
2308
  if (existedOnPrimary) {
2271
2309
  log2.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on primary \u2192 EXISTS`);
@@ -2289,7 +2327,7 @@ var ConfigRepo = class {
2289
2327
  }
2290
2328
  for (const [replicaId, replica] of this.replicaBackends) {
2291
2329
  log2.log(`[TOMB-TRACE] checking replica: ${replicaId} for ${tombstone.path}`);
2292
- const existed = await this.safeExists(replica.instance, tombstone.path);
2330
+ const existed = forceDelete || await this.safeExists(replica.instance, tombstone.path);
2293
2331
  log2.log(`[TOMB-TRACE] replica ${replicaId} safeExists(${tombstone.path}) \u2192 ${existed}`);
2294
2332
  if (existed) {
2295
2333
  log2.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on ${replicaId} \u2192 EXISTS`);
@@ -3923,6 +3961,15 @@ var AppDataGroupImpl = class {
3923
3961
  log2.warn(`[AppDataGroup:${this.groupId}] tombstone confirmations failed:`, err);
3924
3962
  }
3925
3963
  }
3964
+ /** Write a tombstone for `filePath`. Records metadata only — it never creates the file. */
3965
+ async writeTombstoneFor(filePath) {
3966
+ await this.tombstones.write({
3967
+ path: filePath.startsWith("/") ? filePath : `/${filePath}`,
3968
+ deletedAt: Date.now(),
3969
+ deletedBy: this.localBackendId,
3970
+ confirmedBy: [this.localBackendId]
3971
+ });
3972
+ }
3926
3973
  /**
3927
3974
  * Delete a data file with a tombstone in `.meta/tombstones/`.
3928
3975
  * The tombstone is synced (`.meta/` is no longer excluded), so the deletion
@@ -3937,18 +3984,17 @@ var AppDataGroupImpl = class {
3937
3984
  if (await isDirectoryPath(this.localFS, normalized)) {
3938
3985
  const files = await collectFilesUnder(this.localFS, normalized);
3939
3986
  for (const file of files) await this.deleteFile(file);
3987
+ for (const dir of await collectDirectoriesUnder(this.localFS, normalized)) {
3988
+ const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
3989
+ await this.writeTombstoneFor(keepPath);
3990
+ await this.writeTombstoneFor(`${keepPath}.mtime`);
3991
+ }
3940
3992
  await removeDirectoryTree(this.localFS, normalized);
3941
3993
  this.schedulePostDeleteSync();
3942
3994
  log2.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
3943
3995
  return;
3944
3996
  }
3945
- const tombstone = {
3946
- path: normalized,
3947
- deletedAt: Date.now(),
3948
- deletedBy: this.localBackendId,
3949
- confirmedBy: [this.localBackendId]
3950
- };
3951
- await this.tombstones.write(tombstone);
3997
+ await this.writeTombstoneFor(normalized);
3952
3998
  try {
3953
3999
  await this.localFS.unlink(normalized);
3954
4000
  } catch {
@@ -3960,6 +4006,12 @@ var AppDataGroupImpl = class {
3960
4006
  } catch {
3961
4007
  }
3962
4008
  }
4009
+ if (!isMtimeSidecar(normalized)) {
4010
+ try {
4011
+ await this.localFS.unlink(`${normalized}.mtime`);
4012
+ } catch {
4013
+ }
4014
+ }
3963
4015
  this.schedulePostDeleteSync();
3964
4016
  }
3965
4017
  schedulePostDeleteSync() {
package/dist/index.mjs CHANGED
@@ -960,6 +960,9 @@ async function existsSafe(fs, path) {
960
960
  return false;
961
961
  }
962
962
  }
963
+ function isMtimeSidecarPath(path) {
964
+ return path.endsWith(".mtime");
965
+ }
963
966
  function encodeMetaPath(filePath) {
964
967
  const normalized = filePath.startsWith("/") ? filePath : `/${filePath}`;
965
968
  return normalized.replace(/^\//, "").replace(/\//g, "__").replace(/\./g, "++");
@@ -1052,7 +1055,7 @@ var TombstoneStore = class {
1052
1055
  }
1053
1056
  }
1054
1057
  async deleteEverywhere(fs, filePath) {
1055
- if (!await existsSafe(fs, filePath)) return;
1058
+ if (!isMtimeSidecarPath(filePath) && !await existsSafe(fs, filePath)) return;
1056
1059
  try {
1057
1060
  await fs.unlink(filePath);
1058
1061
  } catch {
@@ -1281,6 +1284,20 @@ async function collectFilesUnder(fs, dir, out = []) {
1281
1284
  }
1282
1285
  return out;
1283
1286
  }
1287
+ async function collectDirectoriesUnder(fs, dir, out = []) {
1288
+ out.push(dir);
1289
+ let entries;
1290
+ try {
1291
+ entries = await fs.readdir(dir);
1292
+ } catch {
1293
+ return out;
1294
+ }
1295
+ for (const entry of entries) {
1296
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
1297
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnder(fs, child, out);
1298
+ }
1299
+ return out;
1300
+ }
1284
1301
  async function removeDirectoryTree(fs, dir) {
1285
1302
  let entries;
1286
1303
  try {
@@ -1591,6 +1608,26 @@ var ConfigRepo = class {
1591
1608
  // -----------------------------------------------------------------------
1592
1609
  // Tombstone (Deletion Tracking)
1593
1610
  // -----------------------------------------------------------------------
1611
+ /**
1612
+ * Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
1613
+ * mirror for one release cycle). Records only metadata — it never creates
1614
+ * the deleted file locally.
1615
+ */
1616
+ async writeTombstoneFor(filePath) {
1617
+ const normalizedPath = filePath.startsWith("/") ? filePath : "/" + filePath;
1618
+ const tombstone = {
1619
+ path: normalizedPath,
1620
+ deletedAt: Date.now(),
1621
+ deletedBy: this.primaryBackendId,
1622
+ confirmedBy: [this.primaryBackendId]
1623
+ };
1624
+ const tombstoneBytes = new TextEncoder().encode(JSON.stringify(tombstone, null, 2));
1625
+ for (const dir of [TOMBSTONES_DIR, LEGACY_TOMBSTONES_DIR]) {
1626
+ const tombstonePath = tombstonePathFor(normalizedPath, dir);
1627
+ await this.ensureDir(tombstonePath);
1628
+ await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
1629
+ }
1630
+ }
1594
1631
  /**
1595
1632
  * Delete a file and write a tombstone so the deletion propagates
1596
1633
  * to all backends instead of being treated as "missing file → re-create".
@@ -1601,24 +1638,18 @@ var ConfigRepo = class {
1601
1638
  if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
1602
1639
  const files = await collectFilesUnder(this.cachedFS, normalizedPath);
1603
1640
  for (const file of files) await this.deleteFile(file);
1641
+ for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
1642
+ const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
1643
+ await this.writeTombstoneFor(keepPath);
1644
+ await this.writeTombstoneFor(`${keepPath}.mtime`);
1645
+ }
1604
1646
  await removeDirectoryTree(this.cachedFS, normalizedPath);
1605
1647
  this.invalidateTombstoneCache();
1606
1648
  this.schedulePostDeleteSync();
1607
1649
  log2.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
1608
1650
  return;
1609
1651
  }
1610
- const tombstone = {
1611
- path: normalizedPath,
1612
- deletedAt: Date.now(),
1613
- deletedBy: this.primaryBackendId,
1614
- confirmedBy: [this.primaryBackendId]
1615
- };
1616
- const tombstoneBytes = new TextEncoder().encode(JSON.stringify(tombstone, null, 2));
1617
- for (const dir of [TOMBSTONES_DIR, LEGACY_TOMBSTONES_DIR]) {
1618
- const tombstonePath = tombstonePathFor(normalizedPath, dir);
1619
- await this.ensureDir(tombstonePath);
1620
- await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
1621
- }
1652
+ await this.writeTombstoneFor(normalizedPath);
1622
1653
  try {
1623
1654
  await this.cachedFS.unlink(normalizedPath);
1624
1655
  } catch {
@@ -1630,6 +1661,12 @@ var ConfigRepo = class {
1630
1661
  } catch {
1631
1662
  }
1632
1663
  }
1664
+ if (!isMtimeSidecar(normalizedPath)) {
1665
+ try {
1666
+ await this.cachedFS.unlink(`${normalizedPath}.mtime`);
1667
+ } catch {
1668
+ }
1669
+ }
1633
1670
  log2.log(`[ConfigRepo] deleteFile: ${normalizedPath} (tombstone at ${tombstonePathFor(normalizedPath)})`);
1634
1671
  this.invalidateTombstoneCache();
1635
1672
  this.schedulePostDeleteSync();
@@ -1708,9 +1745,10 @@ var ConfigRepo = class {
1708
1745
  let processed = 0;
1709
1746
  let alreadyDeleted = 0;
1710
1747
  for (const tombstone of tombstones) {
1711
- const tVersionPath = versionPathFor(tombstone.path);
1712
- log2.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"}`);
1713
- const existedOnPrimary = await this.safeExists(this.cachedFS, tombstone.path);
1748
+ const forceDelete = isMtimeSidecar(tombstone.path);
1749
+ const tVersionPath = forceDelete ? null : versionPathFor(tombstone.path);
1750
+ log2.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"} forceDelete=${forceDelete}`);
1751
+ const existedOnPrimary = forceDelete || await this.safeExists(this.cachedFS, tombstone.path);
1714
1752
  log2.log(`[TOMB-TRACE] primary safeExists(${tombstone.path}) \u2192 ${existedOnPrimary}`);
1715
1753
  if (existedOnPrimary) {
1716
1754
  log2.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on primary \u2192 EXISTS`);
@@ -1734,7 +1772,7 @@ var ConfigRepo = class {
1734
1772
  }
1735
1773
  for (const [replicaId, replica] of this.replicaBackends) {
1736
1774
  log2.log(`[TOMB-TRACE] checking replica: ${replicaId} for ${tombstone.path}`);
1737
- const existed = await this.safeExists(replica.instance, tombstone.path);
1775
+ const existed = forceDelete || await this.safeExists(replica.instance, tombstone.path);
1738
1776
  log2.log(`[TOMB-TRACE] replica ${replicaId} safeExists(${tombstone.path}) \u2192 ${existed}`);
1739
1777
  if (existed) {
1740
1778
  log2.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on ${replicaId} \u2192 EXISTS`);
@@ -3368,6 +3406,15 @@ var AppDataGroupImpl = class {
3368
3406
  log2.warn(`[AppDataGroup:${this.groupId}] tombstone confirmations failed:`, err);
3369
3407
  }
3370
3408
  }
3409
+ /** Write a tombstone for `filePath`. Records metadata only — it never creates the file. */
3410
+ async writeTombstoneFor(filePath) {
3411
+ await this.tombstones.write({
3412
+ path: filePath.startsWith("/") ? filePath : `/${filePath}`,
3413
+ deletedAt: Date.now(),
3414
+ deletedBy: this.localBackendId,
3415
+ confirmedBy: [this.localBackendId]
3416
+ });
3417
+ }
3371
3418
  /**
3372
3419
  * Delete a data file with a tombstone in `.meta/tombstones/`.
3373
3420
  * The tombstone is synced (`.meta/` is no longer excluded), so the deletion
@@ -3382,18 +3429,17 @@ var AppDataGroupImpl = class {
3382
3429
  if (await isDirectoryPath(this.localFS, normalized)) {
3383
3430
  const files = await collectFilesUnder(this.localFS, normalized);
3384
3431
  for (const file of files) await this.deleteFile(file);
3432
+ for (const dir of await collectDirectoriesUnder(this.localFS, normalized)) {
3433
+ const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
3434
+ await this.writeTombstoneFor(keepPath);
3435
+ await this.writeTombstoneFor(`${keepPath}.mtime`);
3436
+ }
3385
3437
  await removeDirectoryTree(this.localFS, normalized);
3386
3438
  this.schedulePostDeleteSync();
3387
3439
  log2.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
3388
3440
  return;
3389
3441
  }
3390
- const tombstone = {
3391
- path: normalized,
3392
- deletedAt: Date.now(),
3393
- deletedBy: this.localBackendId,
3394
- confirmedBy: [this.localBackendId]
3395
- };
3396
- await this.tombstones.write(tombstone);
3442
+ await this.writeTombstoneFor(normalized);
3397
3443
  try {
3398
3444
  await this.localFS.unlink(normalized);
3399
3445
  } catch {
@@ -3405,6 +3451,12 @@ var AppDataGroupImpl = class {
3405
3451
  } catch {
3406
3452
  }
3407
3453
  }
3454
+ if (!isMtimeSidecar(normalized)) {
3455
+ try {
3456
+ await this.localFS.unlink(`${normalized}.mtime`);
3457
+ } catch {
3458
+ }
3459
+ }
3408
3460
  this.schedulePostDeleteSync();
3409
3461
  }
3410
3462
  schedulePostDeleteSync() {
@@ -27540,6 +27540,9 @@ var ZenFSConfig = (() => {
27540
27540
  return false;
27541
27541
  }
27542
27542
  }
27543
+ function isMtimeSidecarPath(path) {
27544
+ return path.endsWith(".mtime");
27545
+ }
27543
27546
  function encodeMetaPath(filePath) {
27544
27547
  const normalized = filePath.startsWith("/") ? filePath : `/${filePath}`;
27545
27548
  return normalized.replace(/^\//, "").replace(/\//g, "__").replace(/\./g, "++");
@@ -27630,7 +27633,7 @@ var ZenFSConfig = (() => {
27630
27633
  }
27631
27634
  }
27632
27635
  async deleteEverywhere(fs, filePath) {
27633
- if (!await existsSafe(fs, filePath)) return;
27636
+ if (!isMtimeSidecarPath(filePath) && !await existsSafe(fs, filePath)) return;
27634
27637
  try {
27635
27638
  await fs.unlink(filePath);
27636
27639
  } catch {
@@ -27853,6 +27856,20 @@ var ZenFSConfig = (() => {
27853
27856
  }
27854
27857
  return out;
27855
27858
  }
27859
+ async function collectDirectoriesUnder(fs, dir, out = []) {
27860
+ out.push(dir);
27861
+ let entries2;
27862
+ try {
27863
+ entries2 = await fs.readdir(dir);
27864
+ } catch {
27865
+ return out;
27866
+ }
27867
+ for (const entry of entries2) {
27868
+ const child = dir === "/" ? `/${entry}` : `${dir}/${entry}`;
27869
+ if (await isDirectoryPath(fs, child)) await collectDirectoriesUnder(fs, child, out);
27870
+ }
27871
+ return out;
27872
+ }
27856
27873
  async function removeDirectoryTree(fs, dir) {
27857
27874
  let entries2;
27858
27875
  try {
@@ -28169,6 +28186,26 @@ var ZenFSConfig = (() => {
28169
28186
  // -----------------------------------------------------------------------
28170
28187
  // Tombstone (Deletion Tracking)
28171
28188
  // -----------------------------------------------------------------------
28189
+ /**
28190
+ * Write the tombstone record for `filePath` (new `.meta/tombstones` + legacy
28191
+ * mirror for one release cycle). Records only metadata — it never creates
28192
+ * the deleted file locally.
28193
+ */
28194
+ async writeTombstoneFor(filePath) {
28195
+ const normalizedPath = filePath.startsWith("/") ? filePath : "/" + filePath;
28196
+ const tombstone = {
28197
+ path: normalizedPath,
28198
+ deletedAt: Date.now(),
28199
+ deletedBy: this.primaryBackendId,
28200
+ confirmedBy: [this.primaryBackendId]
28201
+ };
28202
+ const tombstoneBytes = new TextEncoder().encode(JSON.stringify(tombstone, null, 2));
28203
+ for (const dir of [TOMBSTONES_DIR, LEGACY_TOMBSTONES_DIR]) {
28204
+ const tombstonePath = tombstonePathFor(normalizedPath, dir);
28205
+ await this.ensureDir(tombstonePath);
28206
+ await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
28207
+ }
28208
+ }
28172
28209
  /**
28173
28210
  * Delete a file and write a tombstone so the deletion propagates
28174
28211
  * to all backends instead of being treated as "missing file → re-create".
@@ -28179,24 +28216,18 @@ var ZenFSConfig = (() => {
28179
28216
  if (await isDirectoryPath(this.cachedFS, normalizedPath)) {
28180
28217
  const files = await collectFilesUnder(this.cachedFS, normalizedPath);
28181
28218
  for (const file of files) await this.deleteFile(file);
28219
+ for (const dir of await collectDirectoriesUnder(this.cachedFS, normalizedPath)) {
28220
+ const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
28221
+ await this.writeTombstoneFor(keepPath);
28222
+ await this.writeTombstoneFor(`${keepPath}.mtime`);
28223
+ }
28182
28224
  await removeDirectoryTree(this.cachedFS, normalizedPath);
28183
28225
  this.invalidateTombstoneCache();
28184
28226
  this.schedulePostDeleteSync();
28185
28227
  log6.log(`[ConfigRepo] deleteFile(directory): ${normalizedPath} (${files.length} file(s))`);
28186
28228
  return;
28187
28229
  }
28188
- const tombstone = {
28189
- path: normalizedPath,
28190
- deletedAt: Date.now(),
28191
- deletedBy: this.primaryBackendId,
28192
- confirmedBy: [this.primaryBackendId]
28193
- };
28194
- const tombstoneBytes = new TextEncoder().encode(JSON.stringify(tombstone, null, 2));
28195
- for (const dir of [TOMBSTONES_DIR, LEGACY_TOMBSTONES_DIR]) {
28196
- const tombstonePath = tombstonePathFor(normalizedPath, dir);
28197
- await this.ensureDir(tombstonePath);
28198
- await this.cachedFS.writeFile(tombstonePath, tombstoneBytes);
28199
- }
28230
+ await this.writeTombstoneFor(normalizedPath);
28200
28231
  try {
28201
28232
  await this.cachedFS.unlink(normalizedPath);
28202
28233
  } catch {
@@ -28208,6 +28239,12 @@ var ZenFSConfig = (() => {
28208
28239
  } catch {
28209
28240
  }
28210
28241
  }
28242
+ if (!isMtimeSidecar(normalizedPath)) {
28243
+ try {
28244
+ await this.cachedFS.unlink(`${normalizedPath}.mtime`);
28245
+ } catch {
28246
+ }
28247
+ }
28211
28248
  log6.log(`[ConfigRepo] deleteFile: ${normalizedPath} (tombstone at ${tombstonePathFor(normalizedPath)})`);
28212
28249
  this.invalidateTombstoneCache();
28213
28250
  this.schedulePostDeleteSync();
@@ -28280,9 +28317,10 @@ var ZenFSConfig = (() => {
28280
28317
  let processed = 0;
28281
28318
  let alreadyDeleted = 0;
28282
28319
  for (const tombstone of tombstones) {
28283
- const tVersionPath = versionPathFor(tombstone.path);
28284
- log6.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"}`);
28285
- const existedOnPrimary = await this.safeExists(this.cachedFS, tombstone.path);
28320
+ const forceDelete = isMtimeSidecar(tombstone.path);
28321
+ const tVersionPath = forceDelete ? null : versionPathFor(tombstone.path);
28322
+ log6.log(`[TOMB-TRACE] processing tombstone: path=${tombstone.path} versionPath=${tVersionPath ?? "null"} forceDelete=${forceDelete}`);
28323
+ const existedOnPrimary = forceDelete || await this.safeExists(this.cachedFS, tombstone.path);
28286
28324
  log6.log(`[TOMB-TRACE] primary safeExists(${tombstone.path}) \u2192 ${existedOnPrimary}`);
28287
28325
  if (existedOnPrimary) {
28288
28326
  log6.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on primary \u2192 EXISTS`);
@@ -28306,7 +28344,7 @@ var ZenFSConfig = (() => {
28306
28344
  }
28307
28345
  for (const [replicaId, replica] of this.replicaBackends) {
28308
28346
  log6.log(`[TOMB-TRACE] checking replica: ${replicaId} for ${tombstone.path}`);
28309
- const existed = await this.safeExists(replica.instance, tombstone.path);
28347
+ const existed = forceDelete || await this.safeExists(replica.instance, tombstone.path);
28310
28348
  log6.log(`[TOMB-TRACE] replica ${replicaId} safeExists(${tombstone.path}) \u2192 ${existed}`);
28311
28349
  if (existed) {
28312
28350
  log6.log(`[TOMB-TRACE] tombstone check: ${tombstone.path} on ${replicaId} \u2192 EXISTS`);
@@ -29940,6 +29978,15 @@ var ZenFSConfig = (() => {
29940
29978
  log6.warn(`[AppDataGroup:${this.groupId}] tombstone confirmations failed:`, err2);
29941
29979
  }
29942
29980
  }
29981
+ /** Write a tombstone for `filePath`. Records metadata only — it never creates the file. */
29982
+ async writeTombstoneFor(filePath) {
29983
+ await this.tombstones.write({
29984
+ path: filePath.startsWith("/") ? filePath : `/${filePath}`,
29985
+ deletedAt: Date.now(),
29986
+ deletedBy: this.localBackendId,
29987
+ confirmedBy: [this.localBackendId]
29988
+ });
29989
+ }
29943
29990
  /**
29944
29991
  * Delete a data file with a tombstone in `.meta/tombstones/`.
29945
29992
  * The tombstone is synced (`.meta/` is no longer excluded), so the deletion
@@ -29954,18 +30001,17 @@ var ZenFSConfig = (() => {
29954
30001
  if (await isDirectoryPath(this.localFS, normalized)) {
29955
30002
  const files = await collectFilesUnder(this.localFS, normalized);
29956
30003
  for (const file of files) await this.deleteFile(file);
30004
+ for (const dir of await collectDirectoriesUnder(this.localFS, normalized)) {
30005
+ const keepPath = dir === "/" ? "/.keep" : `${dir}/.keep`;
30006
+ await this.writeTombstoneFor(keepPath);
30007
+ await this.writeTombstoneFor(`${keepPath}.mtime`);
30008
+ }
29957
30009
  await removeDirectoryTree(this.localFS, normalized);
29958
30010
  this.schedulePostDeleteSync();
29959
30011
  log6.log(`[AppDataGroup:${this.groupId}] deleteFile(directory): ${normalized} (${files.length} file(s))`);
29960
30012
  return;
29961
30013
  }
29962
- const tombstone = {
29963
- path: normalized,
29964
- deletedAt: Date.now(),
29965
- deletedBy: this.localBackendId,
29966
- confirmedBy: [this.localBackendId]
29967
- };
29968
- await this.tombstones.write(tombstone);
30014
+ await this.writeTombstoneFor(normalized);
29969
30015
  try {
29970
30016
  await this.localFS.unlink(normalized);
29971
30017
  } catch {
@@ -29977,6 +30023,12 @@ var ZenFSConfig = (() => {
29977
30023
  } catch {
29978
30024
  }
29979
30025
  }
30026
+ if (!isMtimeSidecar(normalized)) {
30027
+ try {
30028
+ await this.localFS.unlink(`${normalized}.mtime`);
30029
+ } catch {
30030
+ }
30031
+ }
29980
30032
  this.schedulePostDeleteSync();
29981
30033
  }
29982
30034
  schedulePostDeleteSync() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.5.49",
3
+ "version": "0.5.51",
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",