zen-fs-config 0.7.5 → 0.7.7

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.
@@ -9,7 +9,7 @@ import {
9
9
  registerBackend,
10
10
  unregisterBackend,
11
11
  wrapZenFSFileSystem
12
- } from "./chunk-H2F4TFQD.mjs";
12
+ } from "./chunk-WURWDHNT.mjs";
13
13
  export {
14
14
  createBackend,
15
15
  getAccountFields,
@@ -54,6 +54,17 @@ async function wrapZenFSFileSystem(config) {
54
54
  const notifyChange = () => {
55
55
  if (changeCallback) changeCallback();
56
56
  };
57
+ const writeQueues = /* @__PURE__ */ new Map();
58
+ const runExclusive = async (path, task) => {
59
+ const prev = writeQueues.get(path);
60
+ const run = (prev ?? Promise.resolve()).catch(() => void 0).then(task);
61
+ writeQueues.set(path, run);
62
+ try {
63
+ await run;
64
+ } finally {
65
+ if (writeQueues.get(path) === run) writeQueues.delete(path);
66
+ }
67
+ };
57
68
  const backend = {
58
69
  async readFile(path, ...args) {
59
70
  const st = await isolatedFS.stat(path);
@@ -64,31 +75,28 @@ async function wrapZenFSFileSystem(config) {
64
75
  return buf;
65
76
  },
66
77
  async writeFile(path, data, _options) {
67
- const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : data instanceof Uint8Array ? data : new TextEncoder().encode(data);
68
- const parts = path.split("/").filter(Boolean);
69
- parts.pop();
70
- let dir = "";
71
- for (const p of parts) {
72
- dir += "/" + p;
73
- if (!await isolatedFS.exists(dir)) {
74
- await isolatedFS.mkdir(dir, { uid: 0, gid: 0, mode: 493 });
78
+ const source = data instanceof ArrayBuffer ? new Uint8Array(data) : data instanceof Uint8Array ? data : new TextEncoder().encode(data);
79
+ const bytes = new Uint8Array(source);
80
+ await runExclusive(path, async () => {
81
+ const parts = path.split("/").filter(Boolean);
82
+ parts.pop();
83
+ let dir = "";
84
+ for (const p of parts) {
85
+ dir += "/" + p;
86
+ if (!await isolatedFS.exists(dir)) {
87
+ await isolatedFS.mkdir(dir, { uid: 0, gid: 0, mode: 493 });
88
+ }
89
+ }
90
+ if (await isolatedFS.exists(path)) {
91
+ await isolatedFS.unlink(path);
75
92
  }
76
- }
77
- let currentSize = 0;
78
- if (await isolatedFS.exists(path)) {
79
- currentSize = (await isolatedFS.stat(path)).size;
80
- } else {
81
- await isolatedFS.createFile(path, { uid: 0, gid: 0, mode: 420 });
82
- }
83
- if (currentSize > 0) {
84
- await isolatedFS.unlink(path);
85
93
  await isolatedFS.createFile(path, { uid: 0, gid: 0, mode: 420 });
86
- }
87
- await isolatedFS.write(path, bytes, 0);
88
- try {
89
- await isolatedFS.touch(path, { size: bytes.byteLength, mtimeMs: _options?.mtime ?? Date.now() });
90
- } catch {
91
- }
94
+ await isolatedFS.write(path, bytes, 0);
95
+ try {
96
+ await isolatedFS.touch(path, { size: bytes.byteLength, mtimeMs: _options?.mtime ?? Date.now() });
97
+ } catch {
98
+ }
99
+ });
92
100
  notifyChange();
93
101
  },
94
102
  async readdir(path) {
package/dist/index.d.mts CHANGED
@@ -160,9 +160,16 @@ interface VersionMeta {
160
160
  /** Timestamp when the version was created. */
161
161
  timestamp: number;
162
162
  }
163
- /** Content of a tombstone file in `.meta/.deleted/`. */
163
+ /**
164
+ * 墓碑目标类型。
165
+ * - `file`(缺省,兼容旧数据):只删除该路径这一个文件。
166
+ * - `directory`:删除整个目录树。目录墓碑只需一条记录,不必为树里每个文件
167
+ * 各写一条;应用时按树清理(含 `.keep` / `.keep.mtime` 占位)。
168
+ */
169
+ type TombstoneType = 'file' | 'directory';
170
+ /** Content of a tombstone file in `.meta/tombstones/`. */
164
171
  interface TombstoneMeta {
165
- /** The deleted file path. */
172
+ /** 被删除的路径(目录墓碑为目录本身,不带结尾 `/`)。 */
166
173
  path: string;
167
174
  /** Timestamp of deletion. */
168
175
  deletedAt: number;
@@ -170,6 +177,8 @@ interface TombstoneMeta {
170
177
  deletedBy: string;
171
178
  /** Backend IDs that have confirmed the deletion (synced). */
172
179
  confirmedBy: string[];
180
+ /** 目标类型;缺省视为 `file`(旧版本墓碑没有该字段)。 */
181
+ type?: TombstoneType;
173
182
  }
174
183
  /** Content of a conflict archive file in `.meta/.conflicts/`. */
175
184
  interface ConflictArchive {
@@ -347,6 +356,11 @@ interface AppDataGroupDescriptor {
347
356
  groupType: 'data-sync';
348
357
  /** User-editable display name. `id` is the stable identifier. */
349
358
  name?: string;
359
+ /**
360
+ * 组的实例身份(见 `GroupDescriptor.instanceId`)。引导副本随它一起下发,
361
+ * 让新设备在连远端之前就知道该组声明的身份,避免认领到别人的仓库。
362
+ */
363
+ instanceId?: string;
350
364
  /** Capability overrides (versions/conflicts are opt-in for data groups). */
351
365
  features?: Partial<SyncGroupFeatures>;
352
366
  backends: AppDataBackendDescriptor[];
@@ -393,6 +407,14 @@ interface GroupDescriptor {
393
407
  kind: SyncGroupKind;
394
408
  /** Group id (`config` for the config-sync group, the descriptor id otherwise). */
395
409
  id?: string;
410
+ /**
411
+ * 组的实例身份(UUID)。创建时生成一次,之后不可变。
412
+ *
413
+ * 同步边界就是它:连接任何远端之前先读对方的 `.meta/group.json`,实例身份
414
+ * 不一致就**不建立同步对**,因此两个不同的同步组永远不会互相同步。
415
+ * 缺失表示「尚未认领」的老仓库,由第一个连接的组认领并写入。
416
+ */
417
+ instanceId?: string;
396
418
  /** User-editable display name. */
397
419
  name?: string;
398
420
  features?: Partial<SyncGroupFeatures>;
@@ -420,6 +442,16 @@ interface SyncGroupHandle {
420
442
  /** Derived, never persisted separately from the descriptor. */
421
443
  readonly features: SyncGroupFeatures;
422
444
  readonly name?: string;
445
+ /**
446
+ * 本组的实例身份(UUID)。它是同步边界:连接远端前比对对方
447
+ * `.meta/group.json` 的 `instanceId`,不一致就不建同步对。
448
+ */
449
+ getGroupInstanceId(): string | undefined;
450
+ /** 因归属其他同步组而被跳过的后端(不建同步对)。 */
451
+ listSkippedBackends(): {
452
+ backendId: string;
453
+ reason: string;
454
+ }[];
423
455
  /** Direct fs view; metadata paths (`.meta`, `.config`) are hidden. */
424
456
  readonly fs: typeof node_fs;
425
457
  getSyncStatuses(): Map<string, SyncPairStatus>;
@@ -599,6 +631,15 @@ interface IConfigRepo {
599
631
  * instead of being treated as a "missing file" that gets re-created.
600
632
  */
601
633
  deleteFile(path: string): Promise<void>;
634
+ /**
635
+ * Write a repo-root file (`/.config/...`, `/.meta/...`, `/shared/...`) at its
636
+ * real path and record its `.version` sidecar.
637
+ *
638
+ * Distinct from `setConfig(path)`, which prefixes `/${appId}` and is meant for
639
+ * app payload keys; using it for root paths writes to a shadow location
640
+ * (`/admin/.config/...`) that nothing reads.
641
+ */
642
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
602
643
  /**
603
644
  * Sync .meta/ files (backends.json) to all replica backends.
604
645
  * Called automatically by createConfigRepo() after setupSync().
@@ -970,6 +1011,15 @@ declare class ConfigRepo implements IConfigRepo {
970
1011
  private readonly tombstoneConfirmations;
971
1012
  /** Per-backend sync state (successful pairs + connect failures). */
972
1013
  private backendStates;
1014
+ /**
1015
+ * 本组的实例身份(UUID,见 `group-identity.ts`)。
1016
+ *
1017
+ * 它同时是同步边界:连接任何远端副本前先比对对方 `.meta/group.json` 里的
1018
+ * `instanceId`,不一致就不建同步对 —— 两个不同的同步组永不互相同步。
1019
+ */
1020
+ private instanceId?;
1021
+ /** 因归属他人而被跳过的后端 id → 原因,供 UI 展示。 */
1022
+ private skippedBackends;
973
1023
  /** Last known backend descriptors, for the synchronous unified handle API. */
974
1024
  private backendDescriptorCache;
975
1025
  /**
@@ -994,9 +1044,11 @@ declare class ConfigRepo implements IConfigRepo {
994
1044
  peekNodeConfig<T = unknown>(nodeId: string, path: string): Promise<T>;
995
1045
  flush(): Promise<SyncResult[]>;
996
1046
  /**
997
- * Write the tombstone record for `filePath` under `.meta/tombstones/`.
998
- * Records only metadata — it never creates the deleted file locally, and the
1047
+ * Write the tombstone record for `path` under `.meta/tombstones/`.
1048
+ * Records only metadata — it never creates the deleted path locally, and the
999
1049
  * legacy `/.meta/.deleted/` archive is neither read nor written.
1050
+ *
1051
+ * `type: 'directory'` 表示这是一条目录墓碑:应用时按整棵树清理。
1000
1052
  */
1001
1053
  private writeTombstoneFor;
1002
1054
  /**
@@ -1200,6 +1252,17 @@ declare class ConfigRepo implements IConfigRepo {
1200
1252
  ensureDir(filePath: string): Promise<void>;
1201
1253
  private walkDir;
1202
1254
  writeMetaFile(path: string, data: unknown): Promise<void>;
1255
+ /**
1256
+ * 写仓库根级文件(`/.config/...`、`/.meta/...`、`/shared/...` 等,不是 app 载荷)。
1257
+ *
1258
+ * 与 `setConfig()` 的区别:`setConfig(path)` 会把路径拼成 `/${appId}${path}`,
1259
+ * 是给应用自己的配置键用的;根级文件必须落在 cachedFS 的真实路径上,否则编辑
1260
+ * 会写进 `/admin/.config/...` 之类的影子目录(读的地方看不到,文件"改了又没改")。
1261
+ *
1262
+ * 落盘后按同一套机制记录 `.version` 边车(作者为 `appId/nodeId`),
1263
+ * 与内部写描述符 / 元数据的行为一致。
1264
+ */
1265
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
1203
1266
  readMetaFile<T>(path: string): Promise<T | null>;
1204
1267
  /** Read a text file; `null` when absent (used for byte-compare-then-write). */
1205
1268
  private readTextIfExists;
@@ -1258,6 +1321,27 @@ declare class ConfigRepo implements IConfigRepo {
1258
1321
  * tombstoned, so this never delete-then-recreates it.
1259
1322
  */
1260
1323
  replaceBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
1324
+ /**
1325
+ * 本组的同步身份(kind + id + 不可变 instanceId)。
1326
+ *
1327
+ * 首次调用时若 `.meta/group.json` 里还没有 `instanceId`(老部署),生成一个
1328
+ * 并就地写回 —— 只写一次,之后字节相同不再落盘。
1329
+ */
1330
+ private ensureGroupIdentity;
1331
+ /** 组实例身份(未初始化时先兜底生成并落盘)。 */
1332
+ ensureGroupInstanceId(): Promise<string>;
1333
+ /** 组实例身份(同步读取;init 之前可能为 `undefined`)。 */
1334
+ getGroupInstanceId(): string | undefined;
1335
+ /**
1336
+ * 连接远端前校验归属:属于别的组 → `conflict`(调用方必须跳过、不建同步对)。
1337
+ * 老仓库(无 instanceId)会被本组认领。
1338
+ */
1339
+ private bindBackendIdentity;
1340
+ /** 因归属他人而被跳过的后端(id → 原因)。 */
1341
+ listSkippedBackends(): {
1342
+ backendId: string;
1343
+ reason: string;
1344
+ }[];
1261
1345
  /** Write the group-type marker file if it doesn't exist. */
1262
1346
  ensureGroupType(type: SyncGroupType): Promise<void>;
1263
1347
  /** Read the group-type marker. Returns null if not set (new path, then legacy). */
@@ -1625,6 +1709,14 @@ interface TombstoneTarget {
1625
1709
  declare class TombstoneStore {
1626
1710
  private fs;
1627
1711
  private author;
1712
+ /**
1713
+ * 本轮 `process()` 真正核对过"确实不存在"的(路径 → 目标 id)。
1714
+ *
1715
+ * 只有出现在这里的副本才会被写进 `confirmedBy`(见 {@link confirm}),与
1716
+ * 配置组 `ConfigRepo.updateTombstoneConfirmations` 的保守语义一致:副本删除
1717
+ * 失败(网络、后端限制、只剩占位目录)时绝不算已确认。
1718
+ */
1719
+ private readonly verifiedAbsent;
1628
1720
  constructor(fs: MetaFS, author: string);
1629
1721
  private pathFor;
1630
1722
  /** All tombstones. */
@@ -1646,6 +1738,15 @@ declare class TombstoneStore {
1646
1738
  * 文件并删除墓碑;否则按删除传播处理。
1647
1739
  */
1648
1740
  process(targets?: TombstoneTarget[]): Promise<void>;
1741
+ private markVerified;
1742
+ /**
1743
+ * 目标上该路径当前是否确实不存在。
1744
+ *
1745
+ * `.mtime` 侧车与 `.keep` 占位对部分后端不可见(`exists()` 恒为 false),这类
1746
+ * 路径只能相信本轮 unlink 没有报错,因此按"不可见即可信"处理(与配置组的
1747
+ * `allReplicasConfirmAbsent` 一致)。
1748
+ */
1749
+ private absentOnTarget;
1649
1750
  /**
1650
1751
  * 本地存储上该路径的 mtime 是否晚于墓碑的删除时刻。
1651
1752
  *
@@ -1655,8 +1756,15 @@ declare class TombstoneStore {
1655
1756
  private wasRecreatedAfterDeletion;
1656
1757
  private mtimeOf;
1657
1758
  private deleteEverywhere;
1658
- /** Add the given backend ids to every tombstone's confirmation set. */
1659
- confirm(backendIds: string[]): Promise<number>;
1759
+ /**
1760
+ * 把本轮真正核对过"确实不存在"的目标写进墓碑的 `confirmedBy`。
1761
+ *
1762
+ * 旧实现把传入的后端 id 无条件写入,等于"跑过一轮就算所有副本都清干净了";
1763
+ * 副本删除失败时墓碑仍会被 GC,下一轮同步再把残留拉回本地。现在只确认
1764
+ * {@link process} 中现场核对通过的目标(与配置组语义一致),并支持只传 id
1765
+ * 的旧调用方式(此时沿用同一份核对结果)。
1766
+ */
1767
+ confirm(targets: TombstoneTarget[] | string[]): Promise<number>;
1660
1768
  /** Remove tombstones confirmed by every connected backend. */
1661
1769
  gc(allBackendIds: string[], targets?: TombstoneTarget[]): Promise<void>;
1662
1770
  }
package/dist/index.d.ts CHANGED
@@ -160,9 +160,16 @@ interface VersionMeta {
160
160
  /** Timestamp when the version was created. */
161
161
  timestamp: number;
162
162
  }
163
- /** Content of a tombstone file in `.meta/.deleted/`. */
163
+ /**
164
+ * 墓碑目标类型。
165
+ * - `file`(缺省,兼容旧数据):只删除该路径这一个文件。
166
+ * - `directory`:删除整个目录树。目录墓碑只需一条记录,不必为树里每个文件
167
+ * 各写一条;应用时按树清理(含 `.keep` / `.keep.mtime` 占位)。
168
+ */
169
+ type TombstoneType = 'file' | 'directory';
170
+ /** Content of a tombstone file in `.meta/tombstones/`. */
164
171
  interface TombstoneMeta {
165
- /** The deleted file path. */
172
+ /** 被删除的路径(目录墓碑为目录本身,不带结尾 `/`)。 */
166
173
  path: string;
167
174
  /** Timestamp of deletion. */
168
175
  deletedAt: number;
@@ -170,6 +177,8 @@ interface TombstoneMeta {
170
177
  deletedBy: string;
171
178
  /** Backend IDs that have confirmed the deletion (synced). */
172
179
  confirmedBy: string[];
180
+ /** 目标类型;缺省视为 `file`(旧版本墓碑没有该字段)。 */
181
+ type?: TombstoneType;
173
182
  }
174
183
  /** Content of a conflict archive file in `.meta/.conflicts/`. */
175
184
  interface ConflictArchive {
@@ -347,6 +356,11 @@ interface AppDataGroupDescriptor {
347
356
  groupType: 'data-sync';
348
357
  /** User-editable display name. `id` is the stable identifier. */
349
358
  name?: string;
359
+ /**
360
+ * 组的实例身份(见 `GroupDescriptor.instanceId`)。引导副本随它一起下发,
361
+ * 让新设备在连远端之前就知道该组声明的身份,避免认领到别人的仓库。
362
+ */
363
+ instanceId?: string;
350
364
  /** Capability overrides (versions/conflicts are opt-in for data groups). */
351
365
  features?: Partial<SyncGroupFeatures>;
352
366
  backends: AppDataBackendDescriptor[];
@@ -393,6 +407,14 @@ interface GroupDescriptor {
393
407
  kind: SyncGroupKind;
394
408
  /** Group id (`config` for the config-sync group, the descriptor id otherwise). */
395
409
  id?: string;
410
+ /**
411
+ * 组的实例身份(UUID)。创建时生成一次,之后不可变。
412
+ *
413
+ * 同步边界就是它:连接任何远端之前先读对方的 `.meta/group.json`,实例身份
414
+ * 不一致就**不建立同步对**,因此两个不同的同步组永远不会互相同步。
415
+ * 缺失表示「尚未认领」的老仓库,由第一个连接的组认领并写入。
416
+ */
417
+ instanceId?: string;
396
418
  /** User-editable display name. */
397
419
  name?: string;
398
420
  features?: Partial<SyncGroupFeatures>;
@@ -420,6 +442,16 @@ interface SyncGroupHandle {
420
442
  /** Derived, never persisted separately from the descriptor. */
421
443
  readonly features: SyncGroupFeatures;
422
444
  readonly name?: string;
445
+ /**
446
+ * 本组的实例身份(UUID)。它是同步边界:连接远端前比对对方
447
+ * `.meta/group.json` 的 `instanceId`,不一致就不建同步对。
448
+ */
449
+ getGroupInstanceId(): string | undefined;
450
+ /** 因归属其他同步组而被跳过的后端(不建同步对)。 */
451
+ listSkippedBackends(): {
452
+ backendId: string;
453
+ reason: string;
454
+ }[];
423
455
  /** Direct fs view; metadata paths (`.meta`, `.config`) are hidden. */
424
456
  readonly fs: typeof node_fs;
425
457
  getSyncStatuses(): Map<string, SyncPairStatus>;
@@ -599,6 +631,15 @@ interface IConfigRepo {
599
631
  * instead of being treated as a "missing file" that gets re-created.
600
632
  */
601
633
  deleteFile(path: string): Promise<void>;
634
+ /**
635
+ * Write a repo-root file (`/.config/...`, `/.meta/...`, `/shared/...`) at its
636
+ * real path and record its `.version` sidecar.
637
+ *
638
+ * Distinct from `setConfig(path)`, which prefixes `/${appId}` and is meant for
639
+ * app payload keys; using it for root paths writes to a shadow location
640
+ * (`/admin/.config/...`) that nothing reads.
641
+ */
642
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
602
643
  /**
603
644
  * Sync .meta/ files (backends.json) to all replica backends.
604
645
  * Called automatically by createConfigRepo() after setupSync().
@@ -970,6 +1011,15 @@ declare class ConfigRepo implements IConfigRepo {
970
1011
  private readonly tombstoneConfirmations;
971
1012
  /** Per-backend sync state (successful pairs + connect failures). */
972
1013
  private backendStates;
1014
+ /**
1015
+ * 本组的实例身份(UUID,见 `group-identity.ts`)。
1016
+ *
1017
+ * 它同时是同步边界:连接任何远端副本前先比对对方 `.meta/group.json` 里的
1018
+ * `instanceId`,不一致就不建同步对 —— 两个不同的同步组永不互相同步。
1019
+ */
1020
+ private instanceId?;
1021
+ /** 因归属他人而被跳过的后端 id → 原因,供 UI 展示。 */
1022
+ private skippedBackends;
973
1023
  /** Last known backend descriptors, for the synchronous unified handle API. */
974
1024
  private backendDescriptorCache;
975
1025
  /**
@@ -994,9 +1044,11 @@ declare class ConfigRepo implements IConfigRepo {
994
1044
  peekNodeConfig<T = unknown>(nodeId: string, path: string): Promise<T>;
995
1045
  flush(): Promise<SyncResult[]>;
996
1046
  /**
997
- * Write the tombstone record for `filePath` under `.meta/tombstones/`.
998
- * Records only metadata — it never creates the deleted file locally, and the
1047
+ * Write the tombstone record for `path` under `.meta/tombstones/`.
1048
+ * Records only metadata — it never creates the deleted path locally, and the
999
1049
  * legacy `/.meta/.deleted/` archive is neither read nor written.
1050
+ *
1051
+ * `type: 'directory'` 表示这是一条目录墓碑:应用时按整棵树清理。
1000
1052
  */
1001
1053
  private writeTombstoneFor;
1002
1054
  /**
@@ -1200,6 +1252,17 @@ declare class ConfigRepo implements IConfigRepo {
1200
1252
  ensureDir(filePath: string): Promise<void>;
1201
1253
  private walkDir;
1202
1254
  writeMetaFile(path: string, data: unknown): Promise<void>;
1255
+ /**
1256
+ * 写仓库根级文件(`/.config/...`、`/.meta/...`、`/shared/...` 等,不是 app 载荷)。
1257
+ *
1258
+ * 与 `setConfig()` 的区别:`setConfig(path)` 会把路径拼成 `/${appId}${path}`,
1259
+ * 是给应用自己的配置键用的;根级文件必须落在 cachedFS 的真实路径上,否则编辑
1260
+ * 会写进 `/admin/.config/...` 之类的影子目录(读的地方看不到,文件"改了又没改")。
1261
+ *
1262
+ * 落盘后按同一套机制记录 `.version` 边车(作者为 `appId/nodeId`),
1263
+ * 与内部写描述符 / 元数据的行为一致。
1264
+ */
1265
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
1203
1266
  readMetaFile<T>(path: string): Promise<T | null>;
1204
1267
  /** Read a text file; `null` when absent (used for byte-compare-then-write). */
1205
1268
  private readTextIfExists;
@@ -1258,6 +1321,27 @@ declare class ConfigRepo implements IConfigRepo {
1258
1321
  * tombstoned, so this never delete-then-recreates it.
1259
1322
  */
1260
1323
  replaceBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
1324
+ /**
1325
+ * 本组的同步身份(kind + id + 不可变 instanceId)。
1326
+ *
1327
+ * 首次调用时若 `.meta/group.json` 里还没有 `instanceId`(老部署),生成一个
1328
+ * 并就地写回 —— 只写一次,之后字节相同不再落盘。
1329
+ */
1330
+ private ensureGroupIdentity;
1331
+ /** 组实例身份(未初始化时先兜底生成并落盘)。 */
1332
+ ensureGroupInstanceId(): Promise<string>;
1333
+ /** 组实例身份(同步读取;init 之前可能为 `undefined`)。 */
1334
+ getGroupInstanceId(): string | undefined;
1335
+ /**
1336
+ * 连接远端前校验归属:属于别的组 → `conflict`(调用方必须跳过、不建同步对)。
1337
+ * 老仓库(无 instanceId)会被本组认领。
1338
+ */
1339
+ private bindBackendIdentity;
1340
+ /** 因归属他人而被跳过的后端(id → 原因)。 */
1341
+ listSkippedBackends(): {
1342
+ backendId: string;
1343
+ reason: string;
1344
+ }[];
1261
1345
  /** Write the group-type marker file if it doesn't exist. */
1262
1346
  ensureGroupType(type: SyncGroupType): Promise<void>;
1263
1347
  /** Read the group-type marker. Returns null if not set (new path, then legacy). */
@@ -1625,6 +1709,14 @@ interface TombstoneTarget {
1625
1709
  declare class TombstoneStore {
1626
1710
  private fs;
1627
1711
  private author;
1712
+ /**
1713
+ * 本轮 `process()` 真正核对过"确实不存在"的(路径 → 目标 id)。
1714
+ *
1715
+ * 只有出现在这里的副本才会被写进 `confirmedBy`(见 {@link confirm}),与
1716
+ * 配置组 `ConfigRepo.updateTombstoneConfirmations` 的保守语义一致:副本删除
1717
+ * 失败(网络、后端限制、只剩占位目录)时绝不算已确认。
1718
+ */
1719
+ private readonly verifiedAbsent;
1628
1720
  constructor(fs: MetaFS, author: string);
1629
1721
  private pathFor;
1630
1722
  /** All tombstones. */
@@ -1646,6 +1738,15 @@ declare class TombstoneStore {
1646
1738
  * 文件并删除墓碑;否则按删除传播处理。
1647
1739
  */
1648
1740
  process(targets?: TombstoneTarget[]): Promise<void>;
1741
+ private markVerified;
1742
+ /**
1743
+ * 目标上该路径当前是否确实不存在。
1744
+ *
1745
+ * `.mtime` 侧车与 `.keep` 占位对部分后端不可见(`exists()` 恒为 false),这类
1746
+ * 路径只能相信本轮 unlink 没有报错,因此按"不可见即可信"处理(与配置组的
1747
+ * `allReplicasConfirmAbsent` 一致)。
1748
+ */
1749
+ private absentOnTarget;
1649
1750
  /**
1650
1751
  * 本地存储上该路径的 mtime 是否晚于墓碑的删除时刻。
1651
1752
  *
@@ -1655,8 +1756,15 @@ declare class TombstoneStore {
1655
1756
  private wasRecreatedAfterDeletion;
1656
1757
  private mtimeOf;
1657
1758
  private deleteEverywhere;
1658
- /** Add the given backend ids to every tombstone's confirmation set. */
1659
- confirm(backendIds: string[]): Promise<number>;
1759
+ /**
1760
+ * 把本轮真正核对过"确实不存在"的目标写进墓碑的 `confirmedBy`。
1761
+ *
1762
+ * 旧实现把传入的后端 id 无条件写入,等于"跑过一轮就算所有副本都清干净了";
1763
+ * 副本删除失败时墓碑仍会被 GC,下一轮同步再把残留拉回本地。现在只确认
1764
+ * {@link process} 中现场核对通过的目标(与配置组语义一致),并支持只传 id
1765
+ * 的旧调用方式(此时沿用同一份核对结果)。
1766
+ */
1767
+ confirm(targets: TombstoneTarget[] | string[]): Promise<number>;
1660
1768
  /** Remove tombstones confirmed by every connected backend. */
1661
1769
  gc(allBackendIds: string[], targets?: TombstoneTarget[]): Promise<void>;
1662
1770
  }