zen-fs-config 0.7.3 → 0.7.5

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/DESIGN.md CHANGED
@@ -98,6 +98,26 @@ A **sync group** is a set of backends that synchronize with each other. There ar
98
98
  | `data-sync` | Lightweight: data backends only, direct read/write, no config meta layer |
99
99
  | absent | New empty backend; caller decides group type at creation time |
100
100
 
101
+ **Group type is write-once, and sync may not change it**: besides the connect-time
102
+ check (`connect()` throws when `options.groupType` disagrees with the detected
103
+ type), every `SyncableFS` handed to the sync engine is wrapped by
104
+ `wrapGroupTypeGuard()` (`src/group-type-guard.ts`). The guard compares the
105
+ identity the sync write would produce with what the target side already holds and
106
+ drops the write when they differ, so a wrongly-wired replica can never flip a
107
+ config-sync group into a data-sync group (or the other way round). Guarded
108
+ identity fields:
109
+
110
+ | Path | Identity field | Allowed change |
111
+ |---|---|---|
112
+ | `.config/group-type`, `.meta/group-type` | trimmed text (`config-sync` / `data-sync`) | first write, or same value |
113
+ | `.meta/group.json` | `kind` (`config` / `data`) | first write, or same `kind` (name/features still update freely) |
114
+ | `.config/app-data-groups/{appId}/{id}.json` | `groupType` (`data-sync`) | first write, or same value |
115
+
116
+ Blocking is deliberately non-fatal: the write is skipped, a
117
+ `[GroupType] blocked group-type change on <side>` warning is logged once per
118
+ distinct (side, path, from→to) signature, and the repo stays usable. Fix the
119
+ group wiring instead of syncing the marker.
120
+
101
121
  ## 3. File System Structure
102
122
 
103
123
  ### 3.1 Config-Sync Group
package/README.md CHANGED
@@ -201,6 +201,22 @@ Detection & dispatch rules:
201
201
 
202
202
  `connect()` accepts the same options as `createConfigRepo` (`backendInfo`, `primaryBackendId`, `idbStoreName`, `nodeId`, `folderPath`, `cache`, `serializer`, `onConflict`, `syncPollIntervalMs`) plus `groupType`. On Node.js, pass `folderPath` (or set `ZEN_FS_CONFIG_HOME`) to enable local disk persistence.
203
203
 
204
+ ## App data group path semantics
205
+
206
+ `dataGroup.fs` exposes the **logical root of the data group** (the application's data directory). It is not a view of one backend's physical root.
207
+
208
+ - A write to a group-root-relative path such as `/struct/a.json` is replicated to every backend in the group.
209
+ - Each backend maps that same logical path into its own physical root: the Gitee/GitHub repo root, the RemoteStorage `basePath`, the WebDAV directory, etc.
210
+ - Backend `basePath` / repo root values are **physical roots**, not a shared logical prefix. Multiple backends with different physical roots are valid; do not reject a group just because their `basePath` values differ.
211
+ - Always use the same group-root-relative path for all backends. If the application defines a namespace inside the group (for example `app_data/folders`), that is an explicit application-level convention; do not derive it from backend `basePath`.
212
+
213
+ ```typescript
214
+ // dataGroup.fs is the logical group root; all attached backends receive this path.
215
+ await dataGroup.fs.promises.writeFile('/struct/host.json', json);
216
+ ```
217
+
218
+ A common mistake is to compare every backend's `basePath` and try to compute one "common write prefix". That conflates the logical group root with physical backend roots and incorrectly rejects otherwise valid multi-backend groups.
219
+
204
220
  ## Directory Structure
205
221
 
206
222
  ```
package/README.zh-CN.md CHANGED
@@ -194,6 +194,22 @@ if (result.groupType === 'data-sync') {
194
194
 
195
195
  `connect()` 接受与 `createConfigRepo` 相同的选项(`backendInfo`、`primaryBackendId`、`idbStoreName`、`nodeId`、`folderPath`、`cache`、`serializer`、`onConflict`、`syncPollIntervalMs`),另加 `groupType`。在 Node.js 上通过 `folderPath`(或设 `ZEN_FS_CONFIG_HOME`)开启本地磁盘持久化。
196
196
 
197
+ ## 数据组的路径语义
198
+
199
+ `dataGroup.fs` 暴露的是**数据组的逻辑根**(应用数据目录),不是某一个后端的物理根。
200
+
201
+ - 往组根相对路径(例如 `/struct/a.json`)写入,会同步到组内所有后端。
202
+ - 每个后端会把同一个逻辑路径映射到自己的物理根:Gitee/GitHub 仓库根、RemoteStorage 的 `basePath`、WebDAV 目录等。
203
+ - 后端的 `basePath` / 仓库根是**物理根**,不是所有后端共用的逻辑前缀。多个后端拥有不同的物理根是合法的;不要因为 `basePath` 不一致就判定数据组不可用。
204
+ - 所有后端都应使用同一个组根相对路径。如果应用要在组根下划一个命名空间(例如 `app_data/folders`),那是应用层显式约定,不能从后端 `basePath` 反推。
205
+
206
+ ```typescript
207
+ // dataGroup.fs 是数据组逻辑根;组内所有后端都会收到这个路径。
208
+ await dataGroup.fs.promises.writeFile('/struct/host.json', json);
209
+ ```
210
+
211
+ 一个常见错误是逐个比较后端的 `basePath`,再试图算出一个“公共写入前缀”。这把逻辑组根和物理后端根混为一谈,会误拒绝本来可用的多后端数据组。
212
+
197
213
  ## 目录结构
198
214
 
199
215
  ```
@@ -9,7 +9,7 @@ import {
9
9
  registerBackend,
10
10
  unregisterBackend,
11
11
  wrapZenFSFileSystem
12
- } from "./chunk-S2S3XBK2.mjs";
12
+ } from "./chunk-H2F4TFQD.mjs";
13
13
  export {
14
14
  createBackend,
15
15
  getAccountFields,
@@ -74,7 +74,14 @@ async function wrapZenFSFileSystem(config) {
74
74
  await isolatedFS.mkdir(dir, { uid: 0, gid: 0, mode: 493 });
75
75
  }
76
76
  }
77
- if (!await isolatedFS.exists(path)) {
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);
78
85
  await isolatedFS.createFile(path, { uid: 0, gid: 0, mode: 420 });
79
86
  }
80
87
  await isolatedFS.write(path, bytes, 0);
package/dist/index.d.mts CHANGED
@@ -1025,6 +1025,18 @@ declare class ConfigRepo implements IConfigRepo {
1025
1025
  private refreshSyncExclusions;
1026
1026
  /** Invalidate the tombstone cache — call after tombstones are modified. */
1027
1027
  private invalidateTombstoneCache;
1028
+ /**
1029
+ * 判定墓碑目标路径是否在删除之后被重新创建。
1030
+ *
1031
+ * 墓碑表达的是「删除意图」,但删除之后同一路径完全可能被再次写入。同步类工具
1032
+ * 的锁文件(`.sync.lock`)就是每轮「删除 → 重建」;若把墓碑当作永久否决权,
1033
+ * 这个路径会被每一轮 sync 反复删除,表现为「刚写进去 1 秒后就消失」、锁永远拿
1034
+ * 不到、深层目录刚建就没了。
1035
+ *
1036
+ * 判定依据是文件 mtime 晚于 `deletedAt`:写入必然刷新 mtime,因此 mtime 比删除
1037
+ * 时刻新就意味着这条墓碑已经被写操作撤销。
1038
+ */
1039
+ private isPathRecreatedAfterTombstone;
1028
1040
  /**
1029
1041
  * Before sync: for each tombstone, delete the actual file on all replicas.
1030
1042
  * This prevents bi-directional sync from copying the file back.
@@ -1389,6 +1401,74 @@ declare function resolveLocalPrimary(appId: string, kind: 'config' | 'data', opt
1389
1401
  /** The backend type used for the implicit local primary in the current env (default). */
1390
1402
  declare function localPrimaryType(): string;
1391
1403
 
1404
+ /**
1405
+ * 本地主存储(IndexedDB)不可用 / 已损坏。
1406
+ *
1407
+ * 背景:浏览器 IndexedDB 记录丢失时,@zenfs/dom 抛出 `NotReadableError`,
1408
+ * @zenfs/core 再把它映射成 `EIO`。此前 `AppDataGroupImpl.init()` 把任何异常
1409
+ * 都包成一句 `Failed to create local primary ...`,原始错因(name/code/message)
1410
+ * 全部丢失,调用方无法区分「本地库坏了」和「组就是不存在」,于是被降级成
1411
+ * 「没有可用的数据同步组」。
1412
+ *
1413
+ * 这个错误类型把「本地存储不可用」变成可识别、可修复的状态:
1414
+ * - 保留原始 `cause`(含 code/name/message);
1415
+ * - 带上 appId / groupId / IndexedDB 库名,供 UI 精确展示与一键重建;
1416
+ * - `isLocalStorageUnavailableError()` 能穿透 cause 链识别底层原始异常。
1417
+ */
1418
+ declare const LOCAL_STORAGE_UNAVAILABLE = "LOCAL_STORAGE_UNAVAILABLE";
1419
+ interface LocalStorageUnavailableDetails {
1420
+ appId: string;
1421
+ groupId: string;
1422
+ /** 该数据组独占的 IndexedDB 库名(`zen-fs-config-data-{appId}[-{groupId}]`)。 */
1423
+ storeName: string;
1424
+ /** 原始异常(NotReadableError / EIO / DOMException …)。 */
1425
+ cause?: unknown;
1426
+ }
1427
+ /** 数据组本地主存储所在的 IndexedDB 库名(与 resolveLocalPrimary 保持一致)。 */
1428
+ declare function dataGroupLocalStoreName(appId: string, groupId: string): string;
1429
+ declare class LocalStorageUnavailableError extends Error {
1430
+ readonly code = "LOCAL_STORAGE_UNAVAILABLE";
1431
+ readonly appId: string;
1432
+ readonly groupId: string;
1433
+ readonly storeName: string;
1434
+ readonly cause?: unknown;
1435
+ constructor(details: LocalStorageUnavailableDetails);
1436
+ /** 原始异常的可序列化摘要(code / name / message),便于日志与诊断面板展示。 */
1437
+ toJSON(): Record<string, unknown>;
1438
+ }
1439
+ /**
1440
+ * 判断一个异常(含 cause 链)是否代表「本地存储不可用」。
1441
+ *
1442
+ * 识别依据:
1443
+ * - 本库包装的 {@link LocalStorageUnavailableError};
1444
+ * - `NotReadableError`(IndexedDB 记录丢失);
1445
+ * - `EIO`(@zenfs/core 对 NotReadableError 的映射);
1446
+ * - “Data lost due to missing file” 等原始 message。
1447
+ */
1448
+ declare function isLocalStorageUnavailableError(err: unknown): boolean;
1449
+ interface LocalStoreDeletionResult {
1450
+ storeName: string;
1451
+ /** 库已被删除(或本来就不存在)。 */
1452
+ deleted: boolean;
1453
+ /** 删除被其它连接(其它标签页)阻塞,尚未完成。 */
1454
+ blocked: boolean;
1455
+ /** 当前环境没有 IndexedDB(例如 Node),无法执行。 */
1456
+ unsupported?: boolean;
1457
+ error?: string;
1458
+ }
1459
+ /**
1460
+ * 删除**该数据组独占**的本地 IndexedDB 库(只删
1461
+ * `zen-fs-config-data-{appId}[-{groupId}]`,绝不触碰配置仓的
1462
+ * `zen-fs-config-config-{appId}`)。
1463
+ *
1464
+ * 注意:如果还有别的标签页/实例连着这个库,浏览器会触发 `blocked`,此时删除
1465
+ * 会一直挂起。函数在 `timeoutMs` 后返回 `blocked: true`,调用方应提示用户关闭
1466
+ * 其它页面(或刷新后在没有旧连接的情况下重试)。
1467
+ */
1468
+ declare function deleteDataGroupLocalStore(appId: string, groupId: string, options?: {
1469
+ timeoutMs?: number;
1470
+ }): Promise<LocalStoreDeletionResult>;
1471
+
1392
1472
  /**
1393
1473
  * zen-fs-config — Unified Connect Entry Point
1394
1474
  *
@@ -1558,8 +1638,22 @@ declare class TombstoneStore {
1558
1638
  /**
1559
1639
  * Delete every tombstoned file (and its version record) on the local store
1560
1640
  * and on each target backend, so bi-directional sync cannot resurrect it.
1641
+ *
1642
+ * 墓碑只对「删除之后没有再写入」的路径有效。同步类工具会不断重建某些文件
1643
+ * (最典型的是 `.sync.lock`:每轮删除 → 重建),若墓碑永久生效,路径会被每一
1644
+ * 轮 preSync 删掉,表现为「刚写完 1 秒就消失、锁永远拿不到」。因此这里先判定
1645
+ * 目标路径是否在 `deletedAt` 之后被重新写入:是则墓碑已被用户写操作撤销,保留
1646
+ * 文件并删除墓碑;否则按删除传播处理。
1561
1647
  */
1562
1648
  process(targets?: TombstoneTarget[]): Promise<void>;
1649
+ /**
1650
+ * 本地存储上该路径的 mtime 是否晚于墓碑的删除时刻。
1651
+ *
1652
+ * 只看本地主存储:副本上的同路径文件可能只是「删除之前的旧副本」,它的 mtime
1653
+ * 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
1654
+ */
1655
+ private wasRecreatedAfterDeletion;
1656
+ private mtimeOf;
1563
1657
  private deleteEverywhere;
1564
1658
  /** Add the given backend ids to every tombstone's confirmation set. */
1565
1659
  confirm(backendIds: string[]): Promise<number>;
@@ -1607,4 +1701,4 @@ declare class ConflictStore {
1607
1701
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
1608
1702
  }
1609
1703
 
1610
- export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
1704
+ export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
package/dist/index.d.ts CHANGED
@@ -1025,6 +1025,18 @@ declare class ConfigRepo implements IConfigRepo {
1025
1025
  private refreshSyncExclusions;
1026
1026
  /** Invalidate the tombstone cache — call after tombstones are modified. */
1027
1027
  private invalidateTombstoneCache;
1028
+ /**
1029
+ * 判定墓碑目标路径是否在删除之后被重新创建。
1030
+ *
1031
+ * 墓碑表达的是「删除意图」,但删除之后同一路径完全可能被再次写入。同步类工具
1032
+ * 的锁文件(`.sync.lock`)就是每轮「删除 → 重建」;若把墓碑当作永久否决权,
1033
+ * 这个路径会被每一轮 sync 反复删除,表现为「刚写进去 1 秒后就消失」、锁永远拿
1034
+ * 不到、深层目录刚建就没了。
1035
+ *
1036
+ * 判定依据是文件 mtime 晚于 `deletedAt`:写入必然刷新 mtime,因此 mtime 比删除
1037
+ * 时刻新就意味着这条墓碑已经被写操作撤销。
1038
+ */
1039
+ private isPathRecreatedAfterTombstone;
1028
1040
  /**
1029
1041
  * Before sync: for each tombstone, delete the actual file on all replicas.
1030
1042
  * This prevents bi-directional sync from copying the file back.
@@ -1389,6 +1401,74 @@ declare function resolveLocalPrimary(appId: string, kind: 'config' | 'data', opt
1389
1401
  /** The backend type used for the implicit local primary in the current env (default). */
1390
1402
  declare function localPrimaryType(): string;
1391
1403
 
1404
+ /**
1405
+ * 本地主存储(IndexedDB)不可用 / 已损坏。
1406
+ *
1407
+ * 背景:浏览器 IndexedDB 记录丢失时,@zenfs/dom 抛出 `NotReadableError`,
1408
+ * @zenfs/core 再把它映射成 `EIO`。此前 `AppDataGroupImpl.init()` 把任何异常
1409
+ * 都包成一句 `Failed to create local primary ...`,原始错因(name/code/message)
1410
+ * 全部丢失,调用方无法区分「本地库坏了」和「组就是不存在」,于是被降级成
1411
+ * 「没有可用的数据同步组」。
1412
+ *
1413
+ * 这个错误类型把「本地存储不可用」变成可识别、可修复的状态:
1414
+ * - 保留原始 `cause`(含 code/name/message);
1415
+ * - 带上 appId / groupId / IndexedDB 库名,供 UI 精确展示与一键重建;
1416
+ * - `isLocalStorageUnavailableError()` 能穿透 cause 链识别底层原始异常。
1417
+ */
1418
+ declare const LOCAL_STORAGE_UNAVAILABLE = "LOCAL_STORAGE_UNAVAILABLE";
1419
+ interface LocalStorageUnavailableDetails {
1420
+ appId: string;
1421
+ groupId: string;
1422
+ /** 该数据组独占的 IndexedDB 库名(`zen-fs-config-data-{appId}[-{groupId}]`)。 */
1423
+ storeName: string;
1424
+ /** 原始异常(NotReadableError / EIO / DOMException …)。 */
1425
+ cause?: unknown;
1426
+ }
1427
+ /** 数据组本地主存储所在的 IndexedDB 库名(与 resolveLocalPrimary 保持一致)。 */
1428
+ declare function dataGroupLocalStoreName(appId: string, groupId: string): string;
1429
+ declare class LocalStorageUnavailableError extends Error {
1430
+ readonly code = "LOCAL_STORAGE_UNAVAILABLE";
1431
+ readonly appId: string;
1432
+ readonly groupId: string;
1433
+ readonly storeName: string;
1434
+ readonly cause?: unknown;
1435
+ constructor(details: LocalStorageUnavailableDetails);
1436
+ /** 原始异常的可序列化摘要(code / name / message),便于日志与诊断面板展示。 */
1437
+ toJSON(): Record<string, unknown>;
1438
+ }
1439
+ /**
1440
+ * 判断一个异常(含 cause 链)是否代表「本地存储不可用」。
1441
+ *
1442
+ * 识别依据:
1443
+ * - 本库包装的 {@link LocalStorageUnavailableError};
1444
+ * - `NotReadableError`(IndexedDB 记录丢失);
1445
+ * - `EIO`(@zenfs/core 对 NotReadableError 的映射);
1446
+ * - “Data lost due to missing file” 等原始 message。
1447
+ */
1448
+ declare function isLocalStorageUnavailableError(err: unknown): boolean;
1449
+ interface LocalStoreDeletionResult {
1450
+ storeName: string;
1451
+ /** 库已被删除(或本来就不存在)。 */
1452
+ deleted: boolean;
1453
+ /** 删除被其它连接(其它标签页)阻塞,尚未完成。 */
1454
+ blocked: boolean;
1455
+ /** 当前环境没有 IndexedDB(例如 Node),无法执行。 */
1456
+ unsupported?: boolean;
1457
+ error?: string;
1458
+ }
1459
+ /**
1460
+ * 删除**该数据组独占**的本地 IndexedDB 库(只删
1461
+ * `zen-fs-config-data-{appId}[-{groupId}]`,绝不触碰配置仓的
1462
+ * `zen-fs-config-config-{appId}`)。
1463
+ *
1464
+ * 注意:如果还有别的标签页/实例连着这个库,浏览器会触发 `blocked`,此时删除
1465
+ * 会一直挂起。函数在 `timeoutMs` 后返回 `blocked: true`,调用方应提示用户关闭
1466
+ * 其它页面(或刷新后在没有旧连接的情况下重试)。
1467
+ */
1468
+ declare function deleteDataGroupLocalStore(appId: string, groupId: string, options?: {
1469
+ timeoutMs?: number;
1470
+ }): Promise<LocalStoreDeletionResult>;
1471
+
1392
1472
  /**
1393
1473
  * zen-fs-config — Unified Connect Entry Point
1394
1474
  *
@@ -1558,8 +1638,22 @@ declare class TombstoneStore {
1558
1638
  /**
1559
1639
  * Delete every tombstoned file (and its version record) on the local store
1560
1640
  * and on each target backend, so bi-directional sync cannot resurrect it.
1641
+ *
1642
+ * 墓碑只对「删除之后没有再写入」的路径有效。同步类工具会不断重建某些文件
1643
+ * (最典型的是 `.sync.lock`:每轮删除 → 重建),若墓碑永久生效,路径会被每一
1644
+ * 轮 preSync 删掉,表现为「刚写完 1 秒就消失、锁永远拿不到」。因此这里先判定
1645
+ * 目标路径是否在 `deletedAt` 之后被重新写入:是则墓碑已被用户写操作撤销,保留
1646
+ * 文件并删除墓碑;否则按删除传播处理。
1561
1647
  */
1562
1648
  process(targets?: TombstoneTarget[]): Promise<void>;
1649
+ /**
1650
+ * 本地存储上该路径的 mtime 是否晚于墓碑的删除时刻。
1651
+ *
1652
+ * 只看本地主存储:副本上的同路径文件可能只是「删除之前的旧副本」,它的 mtime
1653
+ * 本来就旧,用副本判定既不可靠又会掩盖真正的删除传播。
1654
+ */
1655
+ private wasRecreatedAfterDeletion;
1656
+ private mtimeOf;
1563
1657
  private deleteEverywhere;
1564
1658
  /** Add the given backend ids to every tombstone's confirmation set. */
1565
1659
  confirm(backendIds: string[]): Promise<number>;
@@ -1607,4 +1701,4 @@ declare class ConflictStore {
1607
1701
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
1608
1702
  }
1609
1703
 
1610
- export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
1704
+ export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };