zen-fs-config 0.7.13 → 0.7.15

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
@@ -435,6 +435,50 @@ interface GroupDescriptor {
435
435
  * `/nodes`、`/shared`。
436
436
  * 两个能力位互不蕴含。
437
437
  */
438
+ /** 归属冲突的细分原因。 */
439
+ type BackendConflictReason = 'kind-mismatch' | 'id-mismatch' | 'instance-mismatch' | 'unreadable' | 'claim-failed';
440
+ /**
441
+ * 一个后端与远端根归属冲突的完整信息。
442
+ *
443
+ * `kind` / `id` / `instanceId` 三者用途不同,必须同时展示:
444
+ * - `kind`:组类型(config / data);
445
+ * - `id`:组 id(同时决定本地库名与引导副本路径);
446
+ * - `instanceId`:组实例身份(UUID,判定“这个远端根归谁”)。
447
+ */
448
+ interface BackendConflictInfo {
449
+ backendId: string;
450
+ /** 一句话原因(已含两侧身份摘要,可直接展示)。 */
451
+ reason: string;
452
+ conflict?: BackendConflictReason;
453
+ /** 远端根的现状;空仓库或读不到时为 null。 */
454
+ remote: {
455
+ kind?: SyncGroupKind;
456
+ id?: string;
457
+ instanceId?: string;
458
+ name?: string;
459
+ } | null;
460
+ /** 本组身份。 */
461
+ local: {
462
+ kind: SyncGroupKind;
463
+ id: string;
464
+ instanceId?: string;
465
+ };
466
+ /** 允许“只把本地 instanceId 对齐到远端”(要求 kind 与 id 都相同)。 */
467
+ canAdoptRemoteInstance: boolean;
468
+ /** 允许“把远端 group.json 改写成本组身份”(要求 kind 相同;会影响共享该根的副本)。 */
469
+ canRewriteRemoteIdentity: boolean;
470
+ unreadable?: boolean;
471
+ error?: string;
472
+ }
473
+ /** 用户确认后的冲突解决动作。 */
474
+ type BackendConflictResolution = 'adopt-remote-instance' | 'rewrite-remote-identity';
475
+ interface BackendConflictResolutionResult {
476
+ mode: BackendConflictResolution;
477
+ ok: boolean;
478
+ reason?: string;
479
+ /** adopt-remote-instance 成功后应落盘的本地 instanceId。 */
480
+ instanceId?: string;
481
+ }
438
482
  interface SyncGroupHandle {
439
483
  readonly groupId: string;
440
484
  readonly appId: string;
@@ -452,6 +496,16 @@ interface SyncGroupHandle {
452
496
  backendId: string;
453
497
  reason: string;
454
498
  }[];
499
+ /**
500
+ * 归属冲突的完整信息(含两侧 kind / id / instanceId 与可执行的对齐动作)。
501
+ * UI 应展示这些字段让用户判断,而不是只给一句“不一致”。
502
+ */
503
+ listBackendConflicts(): BackendConflictInfo[];
504
+ /**
505
+ * 用户确认后解决某个后端的归属冲突。
506
+ * 调用方负责二次确认,并在成功后重新连接/刷新(本组实例需要重新 init)。
507
+ */
508
+ resolveBackendConflict(backendId: string, mode: BackendConflictResolution): Promise<BackendConflictResolutionResult>;
455
509
  /**
456
510
  * Direct fs view of the group root. `.config/` is hidden (config-sync
457
511
  * territory); sync bookkeeping under `.meta/` (tombstones / versions /
@@ -1025,6 +1079,8 @@ declare class ConfigRepo implements IConfigRepo {
1025
1079
  private instanceId?;
1026
1080
  /** 因归属他人而被跳过的后端 id → 原因,供 UI 展示。 */
1027
1081
  private skippedBackends;
1082
+ /** 归属冲突的完整信息(两侧 kind / id / instanceId + 可执行动作)。 */
1083
+ private backendConflicts;
1028
1084
  /** Last known backend descriptors, for the synchronous unified handle API. */
1029
1085
  private backendDescriptorCache;
1030
1086
  /**
@@ -1356,6 +1412,10 @@ declare class ConfigRepo implements IConfigRepo {
1356
1412
  backendId: string;
1357
1413
  reason: string;
1358
1414
  }[];
1415
+ /** 归属冲突的完整信息(配置组也会被别的组占用同一个根)。 */
1416
+ listBackendConflicts(): BackendConflictInfo[];
1417
+ /** 用户确认后解决配置组某个后端的归属冲突。 */
1418
+ resolveBackendConflict(backendId: string, mode: BackendConflictResolution): Promise<BackendConflictResolutionResult>;
1359
1419
  /** Write the group-type marker file if it doesn't exist. */
1360
1420
  ensureGroupType(type: SyncGroupType): Promise<void>;
1361
1421
  /** Read the group-type marker. Returns null if not set (new path, then legacy). */
@@ -1403,6 +1463,7 @@ declare class ConfigRepo implements IConfigRepo {
1403
1463
  updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[], meta?: {
1404
1464
  name?: string;
1405
1465
  features?: Partial<SyncGroupFeatures>;
1466
+ instanceId?: string;
1406
1467
  }): Promise<void>;
1407
1468
  /**
1408
1469
  * Change a data-sync group's display name only. `id`, backends, local stores
@@ -1567,6 +1628,168 @@ declare function deleteDataGroupLocalStore(appId: string, groupId: string, optio
1567
1628
  timeoutMs?: number;
1568
1629
  }): Promise<LocalStoreDeletionResult>;
1569
1630
 
1631
+ /**
1632
+ * zen-fs-config — 本地同步配置清理(“清除本页同步组配置”)。
1633
+ *
1634
+ * 只动**本页**应用的本地状态:
1635
+ * · 配置组的 IndexedDB:`zen-fs-config-config-{appId}`
1636
+ * · 各数据组的 IndexedDB:`zen-fs-config-data-{appId}`(default)与
1637
+ * `zen-fs-config-data-{appId}-{groupId}`
1638
+ * · 调用方显式列出的 localStorage 键(后端信息、重建标记等)
1639
+ *
1640
+ * 远端副本、其它设备与其它标签页的配置都不受影响;删除后本页会以「未连接」
1641
+ * 状态重来一次(重新选后端 / 重新认领远端根)。
1642
+ */
1643
+
1644
+ interface PurgeLocalSyncConfigOptions {
1645
+ /** 已知的数据组 id;与 `indexedDB.databases()` 的枚举结果合并。 */
1646
+ groupIds?: string[];
1647
+ /** 需要一并删除的 localStorage 键(后端信息、重建标记等)。 */
1648
+ extraStorageKeys?: string[];
1649
+ /** 单个库删除的超时;默认 4000ms。 */
1650
+ timeoutMs?: number;
1651
+ }
1652
+ interface PurgeLocalSyncConfigResult {
1653
+ appId: string;
1654
+ databases: LocalStoreDeletionResult[];
1655
+ removedStorageKeys: string[];
1656
+ /** 当前环境没有 IndexedDB(例如 Node):只清了 storage key。 */
1657
+ unsupported?: boolean;
1658
+ }
1659
+ /**
1660
+ * 删除一个 IndexedDB 库并等到成功 / 失败 / 超时。
1661
+ * 仍被其它连接占用时返回 `blocked: true`(而不是无限挂起)。
1662
+ */
1663
+ declare function deleteIndexedDbStore(name: string, timeoutMs?: number): Promise<LocalStoreDeletionResult>;
1664
+ /** 本页该应用会创建的全部本地配置库名(用于精确删除,不误伤别的 appId)。 */
1665
+ declare function localSyncStoreNames(appId: string, groupIds?: string[]): string[];
1666
+ /**
1667
+ * 清除本页该应用的同步组配置(IndexedDB 本地副本 + 指定的 storage 键)。
1668
+ *
1669
+ * 典型用法:同步时发现远端根属于类型不匹配 / instanceId 不一致的另一个组,
1670
+ * 用户确认后清掉本页配置,再重新连接一遍。
1671
+ */
1672
+ declare function purgeLocalSyncConfig(appId: string, options?: PurgeLocalSyncConfigOptions): Promise<PurgeLocalSyncConfigResult>;
1673
+
1674
+ /**
1675
+ * zen-fs-config — Group Identity (sync boundary)
1676
+ *
1677
+ * 每个同步组有一个不可变的实例身份(`instanceId`,UUID)。它写在两处:
1678
+ *
1679
+ * - 组自己的 `/.meta/group.json`(随同步走,因此每个副本都带着它);
1680
+ * - 引导副本 `.config/app-data-groups/{appId}/{id}.json`(配置组登记,新设备
1681
+ * 在还没连上任何数据后端时就知道该组声明的身份)。
1682
+ *
1683
+ * 规则:**连接任何远端之前,先读对方的 `/.meta/group.json`**。
1684
+ * - 对方带着同一个实例身份 → 同一组,允许建立同步对;
1685
+ * - 对方还没有实例身份(老仓库)→ 由当前组认领并写入,之后固定归属;
1686
+ * - 对方带着另一个实例身份 → **不建立同步对**,该后端被跳过并告警。
1687
+ *
1688
+ * 这就是「不同的同步组之间不能同步」的落地点:跨组不是靠路径隔离,而是靠
1689
+ * 连接前拒绝建对。
1690
+ */
1691
+
1692
+ /** 远端根当前归属的判定结果。 */
1693
+ type RemoteIdentityState =
1694
+ /** 远端根属于本组(实例身份一致)。 */
1695
+ 'match'
1696
+ /** 远端根原先没有实例身份,本次由本组认领并写入。 */
1697
+ | 'claimed'
1698
+ /** 远端根属于另一个同步组 —— 必须跳过,不能建同步对。 */
1699
+ | 'conflict';
1700
+ /** 冲突的细分原因:三类身份的哪一项不一致。 */
1701
+ type IdentityConflictReason =
1702
+ /** `kind` 不同(配置组 vs 数据组)。 */
1703
+ 'kind-mismatch'
1704
+ /** 同为一种 kind,但组 id 不同(同一远端根被另一个逻辑组占用)。 */
1705
+ | 'id-mismatch'
1706
+ /** kind 与 id 都相同,但实例身份(instanceId)不同。 */
1707
+ | 'instance-mismatch'
1708
+ /** 远端描述符读不到(网络 / 权限),无法判断归属。 */
1709
+ | 'unreadable'
1710
+ /** 认领写入失败(远端只读 / 无权限)。 */
1711
+ | 'claim-failed';
1712
+ /** 本组身份:kind + 显示用 id + 不可变实例身份。 */
1713
+ interface GroupIdentity {
1714
+ kind: SyncGroupKind;
1715
+ id: string;
1716
+ instanceId: string;
1717
+ name?: string;
1718
+ /** 组能力位;认领老仓库时一并写入,避免与本地描述符产生字节差异。 */
1719
+ features?: GroupDescriptor['features'];
1720
+ }
1721
+ /** 生成一个新的组实例身份(UUID v4)。 */
1722
+ declare function newGroupInstanceId(): string;
1723
+ /** 只接受 UUID v4 形态,避免把任意字符串当成身份写进会被同步的内容。 */
1724
+ declare function isValidGroupInstanceId(value: unknown): value is string;
1725
+ /**
1726
+ * 读远端根的归属,必要时认领。
1727
+ *
1728
+ * @param remoteFS 远端后端的文件系统(未 chroot 的根)
1729
+ * @param identity 本组身份
1730
+ */
1731
+ declare function bindRemoteGroupIdentity(remoteFS: any, identity: GroupIdentity): Promise<RemoteIdentityState>;
1732
+ /** 远端 `group.json` 的可见字段(用于在界面上把三方身份都摆出来)。 */
1733
+ interface RemoteIdentitySnapshot {
1734
+ kind?: SyncGroupKind;
1735
+ id?: string;
1736
+ instanceId?: string;
1737
+ name?: string;
1738
+ }
1739
+ /** 归属校验的完整结果:既给判定,也给两侧身份,UI 可以直接展示与决策。 */
1740
+ interface IdentityBindingResult {
1741
+ state: RemoteIdentityState;
1742
+ /** 远端当前描述符(空仓库 / 读不到时为 null)。 */
1743
+ remote: RemoteIdentitySnapshot | null;
1744
+ local: GroupIdentity;
1745
+ conflict?: IdentityConflictReason;
1746
+ /** 远端读不到(网络 / 权限),区别于“空仓库”。 */
1747
+ unreadable?: boolean;
1748
+ error?: string;
1749
+ }
1750
+ /** `kind=config · id=config · 实例 ID 665532a0…` 这类一行摘要。 */
1751
+ declare function summarizeIdentity(identity: {
1752
+ kind?: string;
1753
+ id?: string;
1754
+ instanceId?: string;
1755
+ } | null | undefined): string;
1756
+ /** instanceId 前 8 位,仅用于展示(永不作为比较依据)。 */
1757
+ declare function shortInstanceId(instanceId: string): string;
1758
+ /**
1759
+ * 归属校验的详细版:返回 `match` / `claimed` / `conflict` 以及两侧完整身份。
1760
+ *
1761
+ * 判定顺序(决定界面上的“原因”文案):
1762
+ * 1. 远端描述符读不到 → conflict(unreadable);
1763
+ * 2. `kind` 不同 → conflict(kind-mismatch);
1764
+ * 3. 远端有实例身份:与本地一致 → match;不一致 → conflict(
1765
+ * 本地 id 与远端不同 ? id-mismatch : instance-mismatch );
1766
+ * 4. 远端无身份(老仓库)→ 认领(保留远端已有的 kind/id/name)。
1767
+ */
1768
+ declare function bindRemoteGroupIdentityDetailed(remoteFS: any, identity: GroupIdentity): Promise<IdentityBindingResult>;
1769
+ /** 冲突解决动作。 */
1770
+ type IdentityResolutionMode =
1771
+ /** 只把本地实例身份对齐成远端的 instanceId(要求 kind 与 id 相同)。 */
1772
+ 'adopt-remote-instance'
1773
+ /** 把远端 `group.json` 改写成本组的 kind/id/instanceId(要求 kind 相同)。 */
1774
+ | 'rewrite-remote-identity';
1775
+ interface IdentityResolutionResult {
1776
+ mode: IdentityResolutionMode;
1777
+ ok: boolean;
1778
+ reason?: string;
1779
+ /** adopt-remote-instance 成功后应落盘到本地的 instanceId。 */
1780
+ instanceId?: string;
1781
+ remote?: RemoteIdentitySnapshot | null;
1782
+ }
1783
+ /**
1784
+ * 用户确认后的身份对齐(绝不静默执行)。
1785
+ *
1786
+ * - `adopt-remote-instance`:仅当远端 kind/id 与本组完全一致时,把远端 instanceId
1787
+ * 当作本组身份(本地库名、引导副本路径不变,无损)。
1788
+ * - `rewrite-remote-identity`:仅当 kind 相同时,把远端 `group.json` 改写成本组
1789
+ * 身份;会影响到共享同一个远端根的其它副本,调用方必须先警告用户。
1790
+ */
1791
+ declare function resolveRemoteIdentity(remoteFS: any, identity: GroupIdentity, mode: IdentityResolutionMode): Promise<IdentityResolutionResult>;
1792
+
1570
1793
  /**
1571
1794
  * zen-fs-config — Unified Connect Entry Point
1572
1795
  *
@@ -1823,4 +2046,4 @@ declare class ConflictStore {
1823
2046
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
1824
2047
  }
1825
2048
 
1826
- 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 };
2049
+ export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, 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 GroupIdentity, type IConfigRepo, type IdentityBindingResult, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, 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 PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, resolveRemoteIdentity, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
package/dist/index.d.ts CHANGED
@@ -435,6 +435,50 @@ interface GroupDescriptor {
435
435
  * `/nodes`、`/shared`。
436
436
  * 两个能力位互不蕴含。
437
437
  */
438
+ /** 归属冲突的细分原因。 */
439
+ type BackendConflictReason = 'kind-mismatch' | 'id-mismatch' | 'instance-mismatch' | 'unreadable' | 'claim-failed';
440
+ /**
441
+ * 一个后端与远端根归属冲突的完整信息。
442
+ *
443
+ * `kind` / `id` / `instanceId` 三者用途不同,必须同时展示:
444
+ * - `kind`:组类型(config / data);
445
+ * - `id`:组 id(同时决定本地库名与引导副本路径);
446
+ * - `instanceId`:组实例身份(UUID,判定“这个远端根归谁”)。
447
+ */
448
+ interface BackendConflictInfo {
449
+ backendId: string;
450
+ /** 一句话原因(已含两侧身份摘要,可直接展示)。 */
451
+ reason: string;
452
+ conflict?: BackendConflictReason;
453
+ /** 远端根的现状;空仓库或读不到时为 null。 */
454
+ remote: {
455
+ kind?: SyncGroupKind;
456
+ id?: string;
457
+ instanceId?: string;
458
+ name?: string;
459
+ } | null;
460
+ /** 本组身份。 */
461
+ local: {
462
+ kind: SyncGroupKind;
463
+ id: string;
464
+ instanceId?: string;
465
+ };
466
+ /** 允许“只把本地 instanceId 对齐到远端”(要求 kind 与 id 都相同)。 */
467
+ canAdoptRemoteInstance: boolean;
468
+ /** 允许“把远端 group.json 改写成本组身份”(要求 kind 相同;会影响共享该根的副本)。 */
469
+ canRewriteRemoteIdentity: boolean;
470
+ unreadable?: boolean;
471
+ error?: string;
472
+ }
473
+ /** 用户确认后的冲突解决动作。 */
474
+ type BackendConflictResolution = 'adopt-remote-instance' | 'rewrite-remote-identity';
475
+ interface BackendConflictResolutionResult {
476
+ mode: BackendConflictResolution;
477
+ ok: boolean;
478
+ reason?: string;
479
+ /** adopt-remote-instance 成功后应落盘的本地 instanceId。 */
480
+ instanceId?: string;
481
+ }
438
482
  interface SyncGroupHandle {
439
483
  readonly groupId: string;
440
484
  readonly appId: string;
@@ -452,6 +496,16 @@ interface SyncGroupHandle {
452
496
  backendId: string;
453
497
  reason: string;
454
498
  }[];
499
+ /**
500
+ * 归属冲突的完整信息(含两侧 kind / id / instanceId 与可执行的对齐动作)。
501
+ * UI 应展示这些字段让用户判断,而不是只给一句“不一致”。
502
+ */
503
+ listBackendConflicts(): BackendConflictInfo[];
504
+ /**
505
+ * 用户确认后解决某个后端的归属冲突。
506
+ * 调用方负责二次确认,并在成功后重新连接/刷新(本组实例需要重新 init)。
507
+ */
508
+ resolveBackendConflict(backendId: string, mode: BackendConflictResolution): Promise<BackendConflictResolutionResult>;
455
509
  /**
456
510
  * Direct fs view of the group root. `.config/` is hidden (config-sync
457
511
  * territory); sync bookkeeping under `.meta/` (tombstones / versions /
@@ -1025,6 +1079,8 @@ declare class ConfigRepo implements IConfigRepo {
1025
1079
  private instanceId?;
1026
1080
  /** 因归属他人而被跳过的后端 id → 原因,供 UI 展示。 */
1027
1081
  private skippedBackends;
1082
+ /** 归属冲突的完整信息(两侧 kind / id / instanceId + 可执行动作)。 */
1083
+ private backendConflicts;
1028
1084
  /** Last known backend descriptors, for the synchronous unified handle API. */
1029
1085
  private backendDescriptorCache;
1030
1086
  /**
@@ -1356,6 +1412,10 @@ declare class ConfigRepo implements IConfigRepo {
1356
1412
  backendId: string;
1357
1413
  reason: string;
1358
1414
  }[];
1415
+ /** 归属冲突的完整信息(配置组也会被别的组占用同一个根)。 */
1416
+ listBackendConflicts(): BackendConflictInfo[];
1417
+ /** 用户确认后解决配置组某个后端的归属冲突。 */
1418
+ resolveBackendConflict(backendId: string, mode: BackendConflictResolution): Promise<BackendConflictResolutionResult>;
1359
1419
  /** Write the group-type marker file if it doesn't exist. */
1360
1420
  ensureGroupType(type: SyncGroupType): Promise<void>;
1361
1421
  /** Read the group-type marker. Returns null if not set (new path, then legacy). */
@@ -1403,6 +1463,7 @@ declare class ConfigRepo implements IConfigRepo {
1403
1463
  updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[], meta?: {
1404
1464
  name?: string;
1405
1465
  features?: Partial<SyncGroupFeatures>;
1466
+ instanceId?: string;
1406
1467
  }): Promise<void>;
1407
1468
  /**
1408
1469
  * Change a data-sync group's display name only. `id`, backends, local stores
@@ -1567,6 +1628,168 @@ declare function deleteDataGroupLocalStore(appId: string, groupId: string, optio
1567
1628
  timeoutMs?: number;
1568
1629
  }): Promise<LocalStoreDeletionResult>;
1569
1630
 
1631
+ /**
1632
+ * zen-fs-config — 本地同步配置清理(“清除本页同步组配置”)。
1633
+ *
1634
+ * 只动**本页**应用的本地状态:
1635
+ * · 配置组的 IndexedDB:`zen-fs-config-config-{appId}`
1636
+ * · 各数据组的 IndexedDB:`zen-fs-config-data-{appId}`(default)与
1637
+ * `zen-fs-config-data-{appId}-{groupId}`
1638
+ * · 调用方显式列出的 localStorage 键(后端信息、重建标记等)
1639
+ *
1640
+ * 远端副本、其它设备与其它标签页的配置都不受影响;删除后本页会以「未连接」
1641
+ * 状态重来一次(重新选后端 / 重新认领远端根)。
1642
+ */
1643
+
1644
+ interface PurgeLocalSyncConfigOptions {
1645
+ /** 已知的数据组 id;与 `indexedDB.databases()` 的枚举结果合并。 */
1646
+ groupIds?: string[];
1647
+ /** 需要一并删除的 localStorage 键(后端信息、重建标记等)。 */
1648
+ extraStorageKeys?: string[];
1649
+ /** 单个库删除的超时;默认 4000ms。 */
1650
+ timeoutMs?: number;
1651
+ }
1652
+ interface PurgeLocalSyncConfigResult {
1653
+ appId: string;
1654
+ databases: LocalStoreDeletionResult[];
1655
+ removedStorageKeys: string[];
1656
+ /** 当前环境没有 IndexedDB(例如 Node):只清了 storage key。 */
1657
+ unsupported?: boolean;
1658
+ }
1659
+ /**
1660
+ * 删除一个 IndexedDB 库并等到成功 / 失败 / 超时。
1661
+ * 仍被其它连接占用时返回 `blocked: true`(而不是无限挂起)。
1662
+ */
1663
+ declare function deleteIndexedDbStore(name: string, timeoutMs?: number): Promise<LocalStoreDeletionResult>;
1664
+ /** 本页该应用会创建的全部本地配置库名(用于精确删除,不误伤别的 appId)。 */
1665
+ declare function localSyncStoreNames(appId: string, groupIds?: string[]): string[];
1666
+ /**
1667
+ * 清除本页该应用的同步组配置(IndexedDB 本地副本 + 指定的 storage 键)。
1668
+ *
1669
+ * 典型用法:同步时发现远端根属于类型不匹配 / instanceId 不一致的另一个组,
1670
+ * 用户确认后清掉本页配置,再重新连接一遍。
1671
+ */
1672
+ declare function purgeLocalSyncConfig(appId: string, options?: PurgeLocalSyncConfigOptions): Promise<PurgeLocalSyncConfigResult>;
1673
+
1674
+ /**
1675
+ * zen-fs-config — Group Identity (sync boundary)
1676
+ *
1677
+ * 每个同步组有一个不可变的实例身份(`instanceId`,UUID)。它写在两处:
1678
+ *
1679
+ * - 组自己的 `/.meta/group.json`(随同步走,因此每个副本都带着它);
1680
+ * - 引导副本 `.config/app-data-groups/{appId}/{id}.json`(配置组登记,新设备
1681
+ * 在还没连上任何数据后端时就知道该组声明的身份)。
1682
+ *
1683
+ * 规则:**连接任何远端之前,先读对方的 `/.meta/group.json`**。
1684
+ * - 对方带着同一个实例身份 → 同一组,允许建立同步对;
1685
+ * - 对方还没有实例身份(老仓库)→ 由当前组认领并写入,之后固定归属;
1686
+ * - 对方带着另一个实例身份 → **不建立同步对**,该后端被跳过并告警。
1687
+ *
1688
+ * 这就是「不同的同步组之间不能同步」的落地点:跨组不是靠路径隔离,而是靠
1689
+ * 连接前拒绝建对。
1690
+ */
1691
+
1692
+ /** 远端根当前归属的判定结果。 */
1693
+ type RemoteIdentityState =
1694
+ /** 远端根属于本组(实例身份一致)。 */
1695
+ 'match'
1696
+ /** 远端根原先没有实例身份,本次由本组认领并写入。 */
1697
+ | 'claimed'
1698
+ /** 远端根属于另一个同步组 —— 必须跳过,不能建同步对。 */
1699
+ | 'conflict';
1700
+ /** 冲突的细分原因:三类身份的哪一项不一致。 */
1701
+ type IdentityConflictReason =
1702
+ /** `kind` 不同(配置组 vs 数据组)。 */
1703
+ 'kind-mismatch'
1704
+ /** 同为一种 kind,但组 id 不同(同一远端根被另一个逻辑组占用)。 */
1705
+ | 'id-mismatch'
1706
+ /** kind 与 id 都相同,但实例身份(instanceId)不同。 */
1707
+ | 'instance-mismatch'
1708
+ /** 远端描述符读不到(网络 / 权限),无法判断归属。 */
1709
+ | 'unreadable'
1710
+ /** 认领写入失败(远端只读 / 无权限)。 */
1711
+ | 'claim-failed';
1712
+ /** 本组身份:kind + 显示用 id + 不可变实例身份。 */
1713
+ interface GroupIdentity {
1714
+ kind: SyncGroupKind;
1715
+ id: string;
1716
+ instanceId: string;
1717
+ name?: string;
1718
+ /** 组能力位;认领老仓库时一并写入,避免与本地描述符产生字节差异。 */
1719
+ features?: GroupDescriptor['features'];
1720
+ }
1721
+ /** 生成一个新的组实例身份(UUID v4)。 */
1722
+ declare function newGroupInstanceId(): string;
1723
+ /** 只接受 UUID v4 形态,避免把任意字符串当成身份写进会被同步的内容。 */
1724
+ declare function isValidGroupInstanceId(value: unknown): value is string;
1725
+ /**
1726
+ * 读远端根的归属,必要时认领。
1727
+ *
1728
+ * @param remoteFS 远端后端的文件系统(未 chroot 的根)
1729
+ * @param identity 本组身份
1730
+ */
1731
+ declare function bindRemoteGroupIdentity(remoteFS: any, identity: GroupIdentity): Promise<RemoteIdentityState>;
1732
+ /** 远端 `group.json` 的可见字段(用于在界面上把三方身份都摆出来)。 */
1733
+ interface RemoteIdentitySnapshot {
1734
+ kind?: SyncGroupKind;
1735
+ id?: string;
1736
+ instanceId?: string;
1737
+ name?: string;
1738
+ }
1739
+ /** 归属校验的完整结果:既给判定,也给两侧身份,UI 可以直接展示与决策。 */
1740
+ interface IdentityBindingResult {
1741
+ state: RemoteIdentityState;
1742
+ /** 远端当前描述符(空仓库 / 读不到时为 null)。 */
1743
+ remote: RemoteIdentitySnapshot | null;
1744
+ local: GroupIdentity;
1745
+ conflict?: IdentityConflictReason;
1746
+ /** 远端读不到(网络 / 权限),区别于“空仓库”。 */
1747
+ unreadable?: boolean;
1748
+ error?: string;
1749
+ }
1750
+ /** `kind=config · id=config · 实例 ID 665532a0…` 这类一行摘要。 */
1751
+ declare function summarizeIdentity(identity: {
1752
+ kind?: string;
1753
+ id?: string;
1754
+ instanceId?: string;
1755
+ } | null | undefined): string;
1756
+ /** instanceId 前 8 位,仅用于展示(永不作为比较依据)。 */
1757
+ declare function shortInstanceId(instanceId: string): string;
1758
+ /**
1759
+ * 归属校验的详细版:返回 `match` / `claimed` / `conflict` 以及两侧完整身份。
1760
+ *
1761
+ * 判定顺序(决定界面上的“原因”文案):
1762
+ * 1. 远端描述符读不到 → conflict(unreadable);
1763
+ * 2. `kind` 不同 → conflict(kind-mismatch);
1764
+ * 3. 远端有实例身份:与本地一致 → match;不一致 → conflict(
1765
+ * 本地 id 与远端不同 ? id-mismatch : instance-mismatch );
1766
+ * 4. 远端无身份(老仓库)→ 认领(保留远端已有的 kind/id/name)。
1767
+ */
1768
+ declare function bindRemoteGroupIdentityDetailed(remoteFS: any, identity: GroupIdentity): Promise<IdentityBindingResult>;
1769
+ /** 冲突解决动作。 */
1770
+ type IdentityResolutionMode =
1771
+ /** 只把本地实例身份对齐成远端的 instanceId(要求 kind 与 id 相同)。 */
1772
+ 'adopt-remote-instance'
1773
+ /** 把远端 `group.json` 改写成本组的 kind/id/instanceId(要求 kind 相同)。 */
1774
+ | 'rewrite-remote-identity';
1775
+ interface IdentityResolutionResult {
1776
+ mode: IdentityResolutionMode;
1777
+ ok: boolean;
1778
+ reason?: string;
1779
+ /** adopt-remote-instance 成功后应落盘到本地的 instanceId。 */
1780
+ instanceId?: string;
1781
+ remote?: RemoteIdentitySnapshot | null;
1782
+ }
1783
+ /**
1784
+ * 用户确认后的身份对齐(绝不静默执行)。
1785
+ *
1786
+ * - `adopt-remote-instance`:仅当远端 kind/id 与本组完全一致时,把远端 instanceId
1787
+ * 当作本组身份(本地库名、引导副本路径不变,无损)。
1788
+ * - `rewrite-remote-identity`:仅当 kind 相同时,把远端 `group.json` 改写成本组
1789
+ * 身份;会影响到共享同一个远端根的其它副本,调用方必须先警告用户。
1790
+ */
1791
+ declare function resolveRemoteIdentity(remoteFS: any, identity: GroupIdentity, mode: IdentityResolutionMode): Promise<IdentityResolutionResult>;
1792
+
1570
1793
  /**
1571
1794
  * zen-fs-config — Unified Connect Entry Point
1572
1795
  *
@@ -1823,4 +2046,4 @@ declare class ConflictStore {
1823
2046
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
1824
2047
  }
1825
2048
 
1826
- 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 };
2049
+ export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, 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 GroupIdentity, type IConfigRepo, type IdentityBindingResult, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, 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 PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, resolveRemoteIdentity, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };