zen-fs-config 0.7.7 → 0.7.8

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
@@ -1077,6 +1077,15 @@ declare class ConfigRepo implements IConfigRepo {
1077
1077
  private refreshSyncExclusions;
1078
1078
  /** Invalidate the tombstone cache — call after tombstones are modified. */
1079
1079
  private invalidateTombstoneCache;
1080
+ /**
1081
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
1082
+ *
1083
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
1084
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
1085
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
1086
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
1087
+ */
1088
+ private clearTombstonesForWrite;
1080
1089
  /**
1081
1090
  * 判定墓碑目标路径是否在删除之后被重新创建。
1082
1091
  *
package/dist/index.d.ts CHANGED
@@ -1077,6 +1077,15 @@ declare class ConfigRepo implements IConfigRepo {
1077
1077
  private refreshSyncExclusions;
1078
1078
  /** Invalidate the tombstone cache — call after tombstones are modified. */
1079
1079
  private invalidateTombstoneCache;
1080
+ /**
1081
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
1082
+ *
1083
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
1084
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
1085
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
1086
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
1087
+ */
1088
+ private clearTombstonesForWrite;
1080
1089
  /**
1081
1090
  * 判定墓碑目标路径是否在删除之后被重新创建。
1082
1091
  *
package/dist/index.js CHANGED
@@ -3006,6 +3006,40 @@ var ConfigRepo = class {
3006
3006
  invalidateTombstoneCache() {
3007
3007
  this.tombstoneCache = null;
3008
3008
  }
3009
+ /**
3010
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
3011
+ *
3012
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
3013
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
3014
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
3015
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
3016
+ */
3017
+ async clearTombstonesForWrite(filePath) {
3018
+ let tombstones;
3019
+ try {
3020
+ tombstones = await this.readTombstones();
3021
+ } catch {
3022
+ return;
3023
+ }
3024
+ const normalized = normalizeTombstonePath(filePath);
3025
+ const affected = tombstones.filter((t) => {
3026
+ if (!t.path) return false;
3027
+ if (t.path === normalized) return true;
3028
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
3029
+ });
3030
+ if (affected.length === 0) return;
3031
+ for (const tombstone of affected) {
3032
+ try {
3033
+ await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
3034
+ } catch {
3035
+ }
3036
+ }
3037
+ this.invalidateTombstoneCache();
3038
+ await this.readTombstones();
3039
+ log5.log(
3040
+ `[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
3041
+ );
3042
+ }
3009
3043
  /**
3010
3044
  * 判定墓碑目标路径是否在删除之后被重新创建。
3011
3045
  *
@@ -3774,6 +3808,7 @@ var ConfigRepo = class {
3774
3808
  async persistConfig(fullPath, bytes) {
3775
3809
  await this.ensureDir(fullPath);
3776
3810
  await this.cachedFS.writeFile(fullPath, bytes);
3811
+ await this.clearTombstonesForWrite(fullPath);
3777
3812
  const author = `${this.appId}/${this.nodeId}`;
3778
3813
  const version = await incrementVersion(this.fullFS, fullPath, bytes, author);
3779
3814
  await this.writeVersionSidecar(fullPath, version);
@@ -3931,6 +3966,7 @@ var ConfigRepo = class {
3931
3966
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
3932
3967
  await this.ensureDir(p);
3933
3968
  await this.cachedFS.writeFile(p, bytes);
3969
+ await this.clearTombstonesForWrite(p);
3934
3970
  const author = `${this.appId}/${this.nodeId}`;
3935
3971
  try {
3936
3972
  const version = await incrementVersion(this.fullFS, p, bytes, author);
@@ -5162,7 +5198,10 @@ var AppDataGroupImpl = class {
5162
5198
  }
5163
5199
  this.fs = createChrootFS(this.localFS, "/", {
5164
5200
  hiddenPrefixes: [META_DIR, CONFIG_DIR],
5165
- onWrite: (path, data) => this.recordVersion(path, data),
5201
+ onWrite: async (path, data) => {
5202
+ await this.clearTombstonesForWrite(path);
5203
+ await this.recordVersion(path, data);
5204
+ },
5166
5205
  onUnlink: (path) => this.deleteFile(path),
5167
5206
  onRmdir: (path) => this.deleteFile(path)
5168
5207
  });
@@ -5318,6 +5357,34 @@ var AppDataGroupImpl = class {
5318
5357
  this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
5319
5358
  }
5320
5359
  }
5360
+ /**
5361
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
5362
+ *
5363
+ * 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
5364
+ * 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
5365
+ */
5366
+ async clearTombstonesForWrite(filePath) {
5367
+ try {
5368
+ const tombstones = await this.tombstones.list();
5369
+ const normalized = normalizeTombstonePath(filePath);
5370
+ const affected = tombstones.filter((t) => {
5371
+ if (!t.path) return false;
5372
+ if (t.path === normalized) return true;
5373
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
5374
+ });
5375
+ if (affected.length === 0) return;
5376
+ for (const tombstone of affected) await this.tombstones.remove(tombstone);
5377
+ this.refreshSyncExclusions(await this.tombstones.list());
5378
+ log5.log(
5379
+ `[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
5380
+ );
5381
+ } catch (err) {
5382
+ log5.warn(
5383
+ `[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
5384
+ err
5385
+ );
5386
+ }
5387
+ }
5321
5388
  async confirmTombstones() {
5322
5389
  try {
5323
5390
  await this.tombstones.confirm(this.tombstoneTargets());
package/dist/index.mjs CHANGED
@@ -2431,6 +2431,40 @@ var ConfigRepo = class {
2431
2431
  invalidateTombstoneCache() {
2432
2432
  this.tombstoneCache = null;
2433
2433
  }
2434
+ /**
2435
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
2436
+ *
2437
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
2438
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
2439
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
2440
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
2441
+ */
2442
+ async clearTombstonesForWrite(filePath) {
2443
+ let tombstones;
2444
+ try {
2445
+ tombstones = await this.readTombstones();
2446
+ } catch {
2447
+ return;
2448
+ }
2449
+ const normalized = normalizeTombstonePath(filePath);
2450
+ const affected = tombstones.filter((t) => {
2451
+ if (!t.path) return false;
2452
+ if (t.path === normalized) return true;
2453
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
2454
+ });
2455
+ if (affected.length === 0) return;
2456
+ for (const tombstone of affected) {
2457
+ try {
2458
+ await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
2459
+ } catch {
2460
+ }
2461
+ }
2462
+ this.invalidateTombstoneCache();
2463
+ await this.readTombstones();
2464
+ log5.log(
2465
+ `[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
2466
+ );
2467
+ }
2434
2468
  /**
2435
2469
  * 判定墓碑目标路径是否在删除之后被重新创建。
2436
2470
  *
@@ -3199,6 +3233,7 @@ var ConfigRepo = class {
3199
3233
  async persistConfig(fullPath, bytes) {
3200
3234
  await this.ensureDir(fullPath);
3201
3235
  await this.cachedFS.writeFile(fullPath, bytes);
3236
+ await this.clearTombstonesForWrite(fullPath);
3202
3237
  const author = `${this.appId}/${this.nodeId}`;
3203
3238
  const version = await incrementVersion(this.fullFS, fullPath, bytes, author);
3204
3239
  await this.writeVersionSidecar(fullPath, version);
@@ -3356,6 +3391,7 @@ var ConfigRepo = class {
3356
3391
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
3357
3392
  await this.ensureDir(p);
3358
3393
  await this.cachedFS.writeFile(p, bytes);
3394
+ await this.clearTombstonesForWrite(p);
3359
3395
  const author = `${this.appId}/${this.nodeId}`;
3360
3396
  try {
3361
3397
  const version = await incrementVersion(this.fullFS, p, bytes, author);
@@ -4587,7 +4623,10 @@ var AppDataGroupImpl = class {
4587
4623
  }
4588
4624
  this.fs = createChrootFS(this.localFS, "/", {
4589
4625
  hiddenPrefixes: [META_DIR, CONFIG_DIR],
4590
- onWrite: (path, data) => this.recordVersion(path, data),
4626
+ onWrite: async (path, data) => {
4627
+ await this.clearTombstonesForWrite(path);
4628
+ await this.recordVersion(path, data);
4629
+ },
4591
4630
  onUnlink: (path) => this.deleteFile(path),
4592
4631
  onRmdir: (path) => this.deleteFile(path)
4593
4632
  });
@@ -4743,6 +4782,34 @@ var AppDataGroupImpl = class {
4743
4782
  this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
4744
4783
  }
4745
4784
  }
4785
+ /**
4786
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
4787
+ *
4788
+ * 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
4789
+ * 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
4790
+ */
4791
+ async clearTombstonesForWrite(filePath) {
4792
+ try {
4793
+ const tombstones = await this.tombstones.list();
4794
+ const normalized = normalizeTombstonePath(filePath);
4795
+ const affected = tombstones.filter((t) => {
4796
+ if (!t.path) return false;
4797
+ if (t.path === normalized) return true;
4798
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
4799
+ });
4800
+ if (affected.length === 0) return;
4801
+ for (const tombstone of affected) await this.tombstones.remove(tombstone);
4802
+ this.refreshSyncExclusions(await this.tombstones.list());
4803
+ log5.log(
4804
+ `[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
4805
+ );
4806
+ } catch (err) {
4807
+ log5.warn(
4808
+ `[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
4809
+ err
4810
+ );
4811
+ }
4812
+ }
4746
4813
  async confirmTombstones() {
4747
4814
  try {
4748
4815
  await this.tombstones.confirm(this.tombstoneTargets());
@@ -28963,6 +28963,40 @@ var ZenFSConfig = (() => {
28963
28963
  invalidateTombstoneCache() {
28964
28964
  this.tombstoneCache = null;
28965
28965
  }
28966
+ /**
28967
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
28968
+ *
28969
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
28970
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
28971
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
28972
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
28973
+ */
28974
+ async clearTombstonesForWrite(filePath) {
28975
+ let tombstones;
28976
+ try {
28977
+ tombstones = await this.readTombstones();
28978
+ } catch {
28979
+ return;
28980
+ }
28981
+ const normalized = normalizeTombstonePath(filePath);
28982
+ const affected = tombstones.filter((t) => {
28983
+ if (!t.path) return false;
28984
+ if (t.path === normalized) return true;
28985
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
28986
+ });
28987
+ if (affected.length === 0) return;
28988
+ for (const tombstone of affected) {
28989
+ try {
28990
+ await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
28991
+ } catch {
28992
+ }
28993
+ }
28994
+ this.invalidateTombstoneCache();
28995
+ await this.readTombstones();
28996
+ log9.log(
28997
+ `[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
28998
+ );
28999
+ }
28966
29000
  /**
28967
29001
  * 判定墓碑目标路径是否在删除之后被重新创建。
28968
29002
  *
@@ -29731,6 +29765,7 @@ var ZenFSConfig = (() => {
29731
29765
  async persistConfig(fullPath, bytes) {
29732
29766
  await this.ensureDir(fullPath);
29733
29767
  await this.cachedFS.writeFile(fullPath, bytes);
29768
+ await this.clearTombstonesForWrite(fullPath);
29734
29769
  const author = `${this.appId}/${this.nodeId}`;
29735
29770
  const version2 = await incrementVersion(this.fullFS, fullPath, bytes, author);
29736
29771
  await this.writeVersionSidecar(fullPath, version2);
@@ -29888,6 +29923,7 @@ var ZenFSConfig = (() => {
29888
29923
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
29889
29924
  await this.ensureDir(p);
29890
29925
  await this.cachedFS.writeFile(p, bytes);
29926
+ await this.clearTombstonesForWrite(p);
29891
29927
  const author = `${this.appId}/${this.nodeId}`;
29892
29928
  try {
29893
29929
  const version2 = await incrementVersion(this.fullFS, p, bytes, author);
@@ -31119,7 +31155,10 @@ var ZenFSConfig = (() => {
31119
31155
  }
31120
31156
  this.fs = createChrootFS(this.localFS, "/", {
31121
31157
  hiddenPrefixes: [META_DIR, CONFIG_DIR],
31122
- onWrite: (path, data) => this.recordVersion(path, data),
31158
+ onWrite: async (path, data) => {
31159
+ await this.clearTombstonesForWrite(path);
31160
+ await this.recordVersion(path, data);
31161
+ },
31123
31162
  onUnlink: (path) => this.deleteFile(path),
31124
31163
  onRmdir: (path) => this.deleteFile(path)
31125
31164
  });
@@ -31275,6 +31314,34 @@ var ZenFSConfig = (() => {
31275
31314
  this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
31276
31315
  }
31277
31316
  }
31317
+ /**
31318
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
31319
+ *
31320
+ * 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
31321
+ * 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
31322
+ */
31323
+ async clearTombstonesForWrite(filePath) {
31324
+ try {
31325
+ const tombstones = await this.tombstones.list();
31326
+ const normalized = normalizeTombstonePath(filePath);
31327
+ const affected = tombstones.filter((t) => {
31328
+ if (!t.path) return false;
31329
+ if (t.path === normalized) return true;
31330
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
31331
+ });
31332
+ if (affected.length === 0) return;
31333
+ for (const tombstone of affected) await this.tombstones.remove(tombstone);
31334
+ this.refreshSyncExclusions(await this.tombstones.list());
31335
+ log9.log(
31336
+ `[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
31337
+ );
31338
+ } catch (err2) {
31339
+ log9.warn(
31340
+ `[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
31341
+ err2
31342
+ );
31343
+ }
31344
+ }
31278
31345
  async confirmTombstones() {
31279
31346
  try {
31280
31347
  await this.tombstones.confirm(this.tombstoneTargets());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
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",