zen-fs-config 0.10.0 → 0.10.1

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
@@ -499,6 +499,27 @@ interface GroupDescriptor {
499
499
  */
500
500
  updatedAt?: number;
501
501
  }
502
+ /**
503
+ * `.meta/aliases/{instanceId}.json` — 共享远端根上的成员别名。
504
+ *
505
+ * 一个远端根只有一个 canonical 身份(`.meta/group.json` 的 `instanceId`)。
506
+ * 其它应用的数据组可以显式加入同一个根:各自保留自己的 `instanceId`,
507
+ * 在该根写一份 alias 文件。绑定阶段同时认 canonical 与 alias,因此不同
508
+ * `appId` / 不同 `groupId` 的组可以共享同一份数据,而不会互相改写身份。
509
+ *
510
+ * alias 文件必须一实例一文件:所有成员并发加入时各写各的文件,不存在
511
+ * read-modify-write 覆盖;`.meta/group.json` 始终由 canonical 组持有。
512
+ */
513
+ interface GroupAliasDescriptor {
514
+ schemaVersion: 2;
515
+ kind: 'data';
516
+ /** 成员组自己的 id(canonical 组的 id 不在这里)。 */
517
+ id: string;
518
+ /** 成员组自己的实例身份,同时是文件名。 */
519
+ instanceId: string;
520
+ /** 成员所属应用,仅用于界面展示与排查。 */
521
+ appId?: string;
522
+ }
502
523
  /**
503
524
  * One sync group = a local primary store + zero-or-more remote replicas +
504
525
  * the shared `.meta/` metadata area + that group's own backend definitions.
@@ -544,17 +565,29 @@ interface BackendConflictInfo {
544
565
  canAdoptRemoteInstance: boolean;
545
566
  /** 允许“把远端 group.json 改写成本组身份”(要求 kind 相同;会影响共享该根的副本)。 */
546
567
  canRewriteRemoteIdentity: boolean;
568
+ /**
569
+ * 允许“作为 alias 加入这个共享根”:远端已有 data 身份,本组身份也有效。
570
+ *
571
+ * 加入只写本组自己的 `.meta/aliases/{instanceId}.json`,不改远端
572
+ * `.meta/group.json`;canonical 组不受影响。必须由用户显式确认后调用
573
+ * `resolveBackendConflict(..., 'join-shared-root')`。
574
+ */
575
+ canJoinSharedRoot?: boolean;
547
576
  unreadable?: boolean;
548
577
  error?: string;
549
578
  }
550
579
  /** 用户确认后的冲突解决动作。 */
551
- type BackendConflictResolution = 'adopt-remote-instance' | 'rewrite-remote-identity';
580
+ type BackendConflictResolution = 'adopt-remote-instance' | 'rewrite-remote-identity'
581
+ /** 把本组身份写进远端 `.meta/aliases/`,加入已有数据根(不改 group.json)。 */
582
+ | 'join-shared-root';
552
583
  interface BackendConflictResolutionResult {
553
584
  mode: BackendConflictResolution;
554
585
  ok: boolean;
555
586
  reason?: string;
556
587
  /** adopt-remote-instance 成功后应落盘的本地 instanceId。 */
557
588
  instanceId?: string;
589
+ /** join-shared-root 成功后写入的 alias 实例身份。 */
590
+ aliasInstanceId?: string;
558
591
  }
559
592
  /** `instanceId` 的候选来源:本地描述符 / 共享引导副本 / 某个远端根。 */
560
593
  type IdentityCandidateSource = 'local' | 'bootstrap' | 'remote';
@@ -941,6 +974,12 @@ interface IConfigRepo {
941
974
  createAppDataGroup(id: string, backends: AppDataBackendDescriptor[], options?: {
942
975
  name?: string;
943
976
  features?: Partial<SyncGroupFeatures>;
977
+ /**
978
+ * 允许创建时先接入一个已被其它数据组占用的远端根:不在这里抛错,
979
+ * 由绑定阶段把冲突交给 UI,用户确认 `join-shared-root` 后再写 alias。
980
+ * 只放行 data/data 同端点;配置组或读不到身份仍然拒绝。
981
+ */
982
+ allowSharedRoot?: boolean;
944
983
  }): Promise<AppDataGroup>;
945
984
  /** Get an existing data-sync group handle. */
946
985
  getAppDataGroup(id: string): Promise<AppDataGroup>;
@@ -1792,8 +1831,12 @@ declare class ConfigRepo implements IConfigRepo {
1792
1831
  */
1793
1832
  private resolveAppDataGroupBackends;
1794
1833
  /**
1795
- * 由端点指纹派生后端 id:同类型 + 同身份参数(不含 token)+ 同组 → 同 id。
1796
- * 两个节点各自录入同一端点时,文件名一致,不会各写一份。
1834
+ * 由端点指纹派生后端 id:同类型 + 同身份参数(不含 token)→ 同 id。
1835
+ *
1836
+ * 不再混入 groupId:共享同一个远端根的几个应用组,必须落到同一个
1837
+ * `.meta/backends/{id}.json`,否则每个组都会把对方的 backend 当自己的候选,
1838
+ * 在同一根上建出重复同步对。不同组指向同一端点本来就会被共享根校验拦下,
1839
+ * 因此去掉 groupId 不会让非共享组发生文件名碰撞。
1797
1840
  */
1798
1841
  private deriveAppDataBackendId;
1799
1842
  /**
@@ -1822,6 +1865,7 @@ declare class ConfigRepo implements IConfigRepo {
1822
1865
  createAppDataGroup(id: string, backends: AppDataBackendDescriptor[], options?: {
1823
1866
  name?: string;
1824
1867
  features?: Partial<SyncGroupFeatures>;
1868
+ allowSharedRoot?: boolean;
1825
1869
  }): Promise<AppDataGroup>;
1826
1870
  /**
1827
1871
  * Rewrite an app data group's **bootstrap copy** at
@@ -2115,6 +2159,8 @@ interface GroupIdentity {
2115
2159
  kind: SyncGroupKind;
2116
2160
  id: string;
2117
2161
  instanceId: string;
2162
+ /** 数据组所属应用,写入 alias 文件时用于展示;配置组忽略。 */
2163
+ appId?: string;
2118
2164
  name?: string;
2119
2165
  /** 组能力位;认领老仓库时一并写入,避免与本地描述符产生字节差异。 */
2120
2166
  features?: GroupDescriptor['features'];
@@ -2165,6 +2211,8 @@ interface IdentityBindingResult {
2165
2211
  remote: RemoteIdentitySnapshot | null;
2166
2212
  local: GroupIdentity;
2167
2213
  conflict?: IdentityConflictReason;
2214
+ /** 命中方式:canonical(group.json)或 alias(.meta/aliases)。 */
2215
+ matchedVia?: 'canonical' | 'alias';
2168
2216
  /** 远端读不到(网络 / 权限),区别于“空仓库”。 */
2169
2217
  unreadable?: boolean;
2170
2218
  error?: string;
@@ -2200,13 +2248,17 @@ type IdentityResolutionMode =
2200
2248
  /** 只把本地实例身份对齐成远端的 instanceId(要求 kind 与 id 相同)。 */
2201
2249
  'adopt-remote-instance'
2202
2250
  /** 把远端 `group.json` 改写成本组的 kind/id/instanceId(要求 kind 相同)。 */
2203
- | 'rewrite-remote-identity';
2251
+ | 'rewrite-remote-identity'
2252
+ /** 把本组写成远端根的 alias 成员,保留两侧身份,不改 `group.json`。 */
2253
+ | 'join-shared-root';
2204
2254
  interface IdentityResolutionResult {
2205
2255
  mode: IdentityResolutionMode;
2206
2256
  ok: boolean;
2207
2257
  reason?: string;
2208
2258
  /** adopt-remote-instance 成功后应落盘到本地的 instanceId。 */
2209
2259
  instanceId?: string;
2260
+ /** join-shared-root 成功后写入的 alias 实例身份。 */
2261
+ aliasInstanceId?: string;
2210
2262
  remote?: RemoteIdentitySnapshot | null;
2211
2263
  }
2212
2264
  /**
@@ -2543,6 +2595,11 @@ declare function verifyOrRepairVersion(fs: SyncableFS, configFilePath: string, a
2543
2595
  declare const META_DIR = "/.meta";
2544
2596
  declare const GROUP_DESCRIPTOR_FILE = "/.meta/group.json";
2545
2597
  declare const TOMBSTONES_DIR = "/.meta/tombstones";
2598
+ /**
2599
+ * 共享远端根的成员别名目录。一个 alias 一个文件,按 instanceId 命名。
2600
+ * 与 `group.json` 分开,避免多个应用并发加入时 read-modify-write 丢成员。
2601
+ */
2602
+ declare const ALIASES_DIR = "/.meta/aliases";
2546
2603
  /**
2547
2604
  * 历史归档目录。仅作为常量保留(旧数据仍在远端,按普通内容对待):
2548
2605
  * 既不读取也不写入,删除状态只以 {@link TOMBSTONES_DIR} 为准。
@@ -2577,6 +2634,23 @@ declare function readGroupDescriptor(fs: MetaFS): Promise<GroupDescriptor | null
2577
2634
  * 的无限回环)。
2578
2635
  */
2579
2636
  declare function writeGroupDescriptor(fs: MetaFS, descriptor: GroupDescriptor): Promise<void>;
2637
+ /** alias 文件名直接使用 instanceId,必须先校验 UUID,避免路径逃逸。 */
2638
+ declare function groupAliasFilePath(instanceId: string): string;
2639
+ /** Read one alias by instanceId. Missing/corrupt returns null. */
2640
+ declare function readGroupAlias(fs: MetaFS, instanceId: string): Promise<GroupAliasDescriptor | null>;
2641
+ /**
2642
+ * Read every alias on a shared root.
2643
+ *
2644
+ * 目录不存在 = 尚未共享,返回空数组;目录存在但个别文件损坏时跳过损坏项,
2645
+ * 不让一个坏 alias 把整个根判成可写。
2646
+ */
2647
+ declare function readGroupAliases(fs: MetaFS): Promise<GroupAliasDescriptor[]>;
2648
+ /**
2649
+ * Write one member alias. Write-once per instanceId:
2650
+ * - 已存在同 instanceId 且 id 相同 → 幂等;
2651
+ * - 已存在同 instanceId 但 id 不同 → 拒绝,绝不覆盖别人的成员记录。
2652
+ */
2653
+ declare function writeGroupAlias(fs: MetaFS, alias: GroupAliasDescriptor): Promise<boolean>;
2580
2654
  interface TombstoneTarget {
2581
2655
  id: string;
2582
2656
  fs: any;
@@ -2809,4 +2883,4 @@ interface EnsureDataGroupResult {
2809
2883
  */
2810
2884
  declare function ensureDataGroup(source: DataGroupSource, appId: string, opts?: EnsureDataGroupOptions): Promise<EnsureDataGroupResult>;
2811
2885
 
2812
- export { type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, 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, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
2886
+ export { ALIASES_DIR, type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupAliasDescriptor, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, 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, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupAliasFilePath, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupAlias, readGroupAliases, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupAlias, writeGroupDescriptor, writeVersion };
package/dist/index.d.ts CHANGED
@@ -499,6 +499,27 @@ interface GroupDescriptor {
499
499
  */
500
500
  updatedAt?: number;
501
501
  }
502
+ /**
503
+ * `.meta/aliases/{instanceId}.json` — 共享远端根上的成员别名。
504
+ *
505
+ * 一个远端根只有一个 canonical 身份(`.meta/group.json` 的 `instanceId`)。
506
+ * 其它应用的数据组可以显式加入同一个根:各自保留自己的 `instanceId`,
507
+ * 在该根写一份 alias 文件。绑定阶段同时认 canonical 与 alias,因此不同
508
+ * `appId` / 不同 `groupId` 的组可以共享同一份数据,而不会互相改写身份。
509
+ *
510
+ * alias 文件必须一实例一文件:所有成员并发加入时各写各的文件,不存在
511
+ * read-modify-write 覆盖;`.meta/group.json` 始终由 canonical 组持有。
512
+ */
513
+ interface GroupAliasDescriptor {
514
+ schemaVersion: 2;
515
+ kind: 'data';
516
+ /** 成员组自己的 id(canonical 组的 id 不在这里)。 */
517
+ id: string;
518
+ /** 成员组自己的实例身份,同时是文件名。 */
519
+ instanceId: string;
520
+ /** 成员所属应用,仅用于界面展示与排查。 */
521
+ appId?: string;
522
+ }
502
523
  /**
503
524
  * One sync group = a local primary store + zero-or-more remote replicas +
504
525
  * the shared `.meta/` metadata area + that group's own backend definitions.
@@ -544,17 +565,29 @@ interface BackendConflictInfo {
544
565
  canAdoptRemoteInstance: boolean;
545
566
  /** 允许“把远端 group.json 改写成本组身份”(要求 kind 相同;会影响共享该根的副本)。 */
546
567
  canRewriteRemoteIdentity: boolean;
568
+ /**
569
+ * 允许“作为 alias 加入这个共享根”:远端已有 data 身份,本组身份也有效。
570
+ *
571
+ * 加入只写本组自己的 `.meta/aliases/{instanceId}.json`,不改远端
572
+ * `.meta/group.json`;canonical 组不受影响。必须由用户显式确认后调用
573
+ * `resolveBackendConflict(..., 'join-shared-root')`。
574
+ */
575
+ canJoinSharedRoot?: boolean;
547
576
  unreadable?: boolean;
548
577
  error?: string;
549
578
  }
550
579
  /** 用户确认后的冲突解决动作。 */
551
- type BackendConflictResolution = 'adopt-remote-instance' | 'rewrite-remote-identity';
580
+ type BackendConflictResolution = 'adopt-remote-instance' | 'rewrite-remote-identity'
581
+ /** 把本组身份写进远端 `.meta/aliases/`,加入已有数据根(不改 group.json)。 */
582
+ | 'join-shared-root';
552
583
  interface BackendConflictResolutionResult {
553
584
  mode: BackendConflictResolution;
554
585
  ok: boolean;
555
586
  reason?: string;
556
587
  /** adopt-remote-instance 成功后应落盘的本地 instanceId。 */
557
588
  instanceId?: string;
589
+ /** join-shared-root 成功后写入的 alias 实例身份。 */
590
+ aliasInstanceId?: string;
558
591
  }
559
592
  /** `instanceId` 的候选来源:本地描述符 / 共享引导副本 / 某个远端根。 */
560
593
  type IdentityCandidateSource = 'local' | 'bootstrap' | 'remote';
@@ -941,6 +974,12 @@ interface IConfigRepo {
941
974
  createAppDataGroup(id: string, backends: AppDataBackendDescriptor[], options?: {
942
975
  name?: string;
943
976
  features?: Partial<SyncGroupFeatures>;
977
+ /**
978
+ * 允许创建时先接入一个已被其它数据组占用的远端根:不在这里抛错,
979
+ * 由绑定阶段把冲突交给 UI,用户确认 `join-shared-root` 后再写 alias。
980
+ * 只放行 data/data 同端点;配置组或读不到身份仍然拒绝。
981
+ */
982
+ allowSharedRoot?: boolean;
944
983
  }): Promise<AppDataGroup>;
945
984
  /** Get an existing data-sync group handle. */
946
985
  getAppDataGroup(id: string): Promise<AppDataGroup>;
@@ -1792,8 +1831,12 @@ declare class ConfigRepo implements IConfigRepo {
1792
1831
  */
1793
1832
  private resolveAppDataGroupBackends;
1794
1833
  /**
1795
- * 由端点指纹派生后端 id:同类型 + 同身份参数(不含 token)+ 同组 → 同 id。
1796
- * 两个节点各自录入同一端点时,文件名一致,不会各写一份。
1834
+ * 由端点指纹派生后端 id:同类型 + 同身份参数(不含 token)→ 同 id。
1835
+ *
1836
+ * 不再混入 groupId:共享同一个远端根的几个应用组,必须落到同一个
1837
+ * `.meta/backends/{id}.json`,否则每个组都会把对方的 backend 当自己的候选,
1838
+ * 在同一根上建出重复同步对。不同组指向同一端点本来就会被共享根校验拦下,
1839
+ * 因此去掉 groupId 不会让非共享组发生文件名碰撞。
1797
1840
  */
1798
1841
  private deriveAppDataBackendId;
1799
1842
  /**
@@ -1822,6 +1865,7 @@ declare class ConfigRepo implements IConfigRepo {
1822
1865
  createAppDataGroup(id: string, backends: AppDataBackendDescriptor[], options?: {
1823
1866
  name?: string;
1824
1867
  features?: Partial<SyncGroupFeatures>;
1868
+ allowSharedRoot?: boolean;
1825
1869
  }): Promise<AppDataGroup>;
1826
1870
  /**
1827
1871
  * Rewrite an app data group's **bootstrap copy** at
@@ -2115,6 +2159,8 @@ interface GroupIdentity {
2115
2159
  kind: SyncGroupKind;
2116
2160
  id: string;
2117
2161
  instanceId: string;
2162
+ /** 数据组所属应用,写入 alias 文件时用于展示;配置组忽略。 */
2163
+ appId?: string;
2118
2164
  name?: string;
2119
2165
  /** 组能力位;认领老仓库时一并写入,避免与本地描述符产生字节差异。 */
2120
2166
  features?: GroupDescriptor['features'];
@@ -2165,6 +2211,8 @@ interface IdentityBindingResult {
2165
2211
  remote: RemoteIdentitySnapshot | null;
2166
2212
  local: GroupIdentity;
2167
2213
  conflict?: IdentityConflictReason;
2214
+ /** 命中方式:canonical(group.json)或 alias(.meta/aliases)。 */
2215
+ matchedVia?: 'canonical' | 'alias';
2168
2216
  /** 远端读不到(网络 / 权限),区别于“空仓库”。 */
2169
2217
  unreadable?: boolean;
2170
2218
  error?: string;
@@ -2200,13 +2248,17 @@ type IdentityResolutionMode =
2200
2248
  /** 只把本地实例身份对齐成远端的 instanceId(要求 kind 与 id 相同)。 */
2201
2249
  'adopt-remote-instance'
2202
2250
  /** 把远端 `group.json` 改写成本组的 kind/id/instanceId(要求 kind 相同)。 */
2203
- | 'rewrite-remote-identity';
2251
+ | 'rewrite-remote-identity'
2252
+ /** 把本组写成远端根的 alias 成员,保留两侧身份,不改 `group.json`。 */
2253
+ | 'join-shared-root';
2204
2254
  interface IdentityResolutionResult {
2205
2255
  mode: IdentityResolutionMode;
2206
2256
  ok: boolean;
2207
2257
  reason?: string;
2208
2258
  /** adopt-remote-instance 成功后应落盘到本地的 instanceId。 */
2209
2259
  instanceId?: string;
2260
+ /** join-shared-root 成功后写入的 alias 实例身份。 */
2261
+ aliasInstanceId?: string;
2210
2262
  remote?: RemoteIdentitySnapshot | null;
2211
2263
  }
2212
2264
  /**
@@ -2543,6 +2595,11 @@ declare function verifyOrRepairVersion(fs: SyncableFS, configFilePath: string, a
2543
2595
  declare const META_DIR = "/.meta";
2544
2596
  declare const GROUP_DESCRIPTOR_FILE = "/.meta/group.json";
2545
2597
  declare const TOMBSTONES_DIR = "/.meta/tombstones";
2598
+ /**
2599
+ * 共享远端根的成员别名目录。一个 alias 一个文件,按 instanceId 命名。
2600
+ * 与 `group.json` 分开,避免多个应用并发加入时 read-modify-write 丢成员。
2601
+ */
2602
+ declare const ALIASES_DIR = "/.meta/aliases";
2546
2603
  /**
2547
2604
  * 历史归档目录。仅作为常量保留(旧数据仍在远端,按普通内容对待):
2548
2605
  * 既不读取也不写入,删除状态只以 {@link TOMBSTONES_DIR} 为准。
@@ -2577,6 +2634,23 @@ declare function readGroupDescriptor(fs: MetaFS): Promise<GroupDescriptor | null
2577
2634
  * 的无限回环)。
2578
2635
  */
2579
2636
  declare function writeGroupDescriptor(fs: MetaFS, descriptor: GroupDescriptor): Promise<void>;
2637
+ /** alias 文件名直接使用 instanceId,必须先校验 UUID,避免路径逃逸。 */
2638
+ declare function groupAliasFilePath(instanceId: string): string;
2639
+ /** Read one alias by instanceId. Missing/corrupt returns null. */
2640
+ declare function readGroupAlias(fs: MetaFS, instanceId: string): Promise<GroupAliasDescriptor | null>;
2641
+ /**
2642
+ * Read every alias on a shared root.
2643
+ *
2644
+ * 目录不存在 = 尚未共享,返回空数组;目录存在但个别文件损坏时跳过损坏项,
2645
+ * 不让一个坏 alias 把整个根判成可写。
2646
+ */
2647
+ declare function readGroupAliases(fs: MetaFS): Promise<GroupAliasDescriptor[]>;
2648
+ /**
2649
+ * Write one member alias. Write-once per instanceId:
2650
+ * - 已存在同 instanceId 且 id 相同 → 幂等;
2651
+ * - 已存在同 instanceId 但 id 不同 → 拒绝,绝不覆盖别人的成员记录。
2652
+ */
2653
+ declare function writeGroupAlias(fs: MetaFS, alias: GroupAliasDescriptor): Promise<boolean>;
2580
2654
  interface TombstoneTarget {
2581
2655
  id: string;
2582
2656
  fs: any;
@@ -2809,4 +2883,4 @@ interface EnsureDataGroupResult {
2809
2883
  */
2810
2884
  declare function ensureDataGroup(source: DataGroupSource, appId: string, opts?: EnsureDataGroupOptions): Promise<EnsureDataGroupResult>;
2811
2885
 
2812
- export { type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, 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, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
2886
+ export { ALIASES_DIR, type AddBackendResult, type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type AppRepo, BackendAlreadyExistsError, type BackendConflictInfo, type BackendConflictReason, type BackendConflictResolution, type BackendConflictResolutionResult, type BackendDescriptor, BackendEndpointConflictError, type BackendFactory, BackendIdentityError, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, type ConfigBackendInput, ConfigNotReadyError, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, ConnectFailedError, type ConnectOptions, type ConnectResult, ConnectV2Error, type ConnectV2Options, DATA_GROUP_DEFAULT_FEATURES, DATA_GROUP_PREFERENCE_PREFIX, type DataBackendInput, type DataGroup, DataGroupBackendError, type DataGroupCandidate, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSource, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, type DerivedIdentityInput, type EnsureDataGroupOptions, type EnsureDataGroupResult, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupAliasDescriptor, type GroupDescriptor, type GroupIdentity, type GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, type IdentityConflictReason, type IdentityResolutionMode, type IdentityResolutionResult, InvalidBackendError, 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, NeedsInitError, type PreferenceOptions, type PreferenceStorage, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type ResolveDataGroupOptions, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, type UiConnection, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, bindRemoteGroupIdentity, bindRemoteGroupIdentityDetailed, collectDataGroupCandidates, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, deriveGroupInstanceId, encodeMetaPath, ensureDataGroup, getAccountFields, getBackendMetadata, getExtension, getPreferredDataGroupId, getUiConnection, groupAliasFilePath, groupHasPath, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalBackendType, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, listDataGroupCandidates, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupAlias, readGroupAliases, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveDataGroup, resolveLocalPrimary, resolveRemoteIdentity, setPreferredDataGroupId, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupAlias, writeGroupDescriptor, writeVersion };