zen-fs-config 0.9.3 → 0.9.4

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/README.md CHANGED
@@ -232,6 +232,36 @@ const summary = await result.whenReplicasReady?.();
232
232
  - No pair is created before verification succeeds. That removes the "create then tear down on conflict" window (and any need to gate syncing behind a flag); the price is that consumers must honour the two signals.
233
233
  - `dispose()` and `flush()` await the background setup, so a late pair can never attach to a disposed engine and `flush()` never runs against zero pairs.
234
234
 
235
+ ## V2 entry point: `connectV2()`
236
+
237
+ `connectV2()` is the small app-facing surface. The legacy `connect()` stays available and is called internally; V2 does not create a second connection pool.
238
+
239
+ ```typescript
240
+ import { connectV2 } from 'zen-fs-config';
241
+
242
+ const repo = await connectV2('golf'); // AppRepo
243
+ const group = await repo.getDefaultDataGroup(); // existing local group, or local `default`
244
+
245
+ await group.fs.promises.writeFile('/golf/state.json', json);
246
+ await group.addBackend({
247
+ type: 'Gitee',
248
+ options: { owner, repo, token, path: 'golf-data' },
249
+ });
250
+
251
+ const off = group.onSyncEvent((event) => {
252
+ if (event.type === 'sync:start') showSyncing(event.backendId);
253
+ if (event.type === 'sync:end') showDone(event.result);
254
+ });
255
+ ```
256
+
257
+ - `AppRepo` exposes `appId`, `getDefaultDataGroup()`, `listDataGroups()`, and `getDataGroup(id)`.
258
+ - `DataGroup` exposes `id`, `fs`, `addBackend()`, `flush()`, `deleteFile()`, `onSyncEvent()`.
259
+ - `listDataGroups()` returns lightweight `{ id, name, hasRemote }` entries; `getDataGroup(id)` only loads an existing group.
260
+ - `flush()` syncs all pairs now and returns one result per `pairId`; `deleteFile(path)` goes through the tombstone path so a deletion cannot be resurrected by the next sync.
261
+ - The default group is the first group already on this device (`default` first, otherwise the first one); an empty local `default` is created only when no group exists.
262
+ - `connectV2()` does not accept `dataBackends`; data backends belong to a `DataGroup`.
263
+ - `onSyncEvent()` currently forwards `sync:start` / `sync:end` / `sync:error` / `conflict`. Per-file `sync:progress` needs upstream `zen-fs-sync` support and is not faked.
264
+
235
265
  ## App data group path semantics
236
266
 
237
267
  `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.
package/dist/index.d.mts CHANGED
@@ -409,7 +409,11 @@ interface BackendSyncState {
409
409
  * 里的计数过滤自己关心的变更;`sync:error` 只在整轮抛错时发。
410
410
  */
411
411
  interface SyncGroupSyncEvent {
412
- type: 'sync:end' | 'sync:error';
412
+ /**
413
+ * `sync:progress` 由未来的 zen-fs-sync 逐文件进度回调提供;当前上游没有,
414
+ * 库不会伪造这个事件。
415
+ */
416
+ type: 'sync:start' | 'sync:progress' | 'sync:end' | 'sync:error' | 'conflict';
413
417
  /** 事件所属组的类型。 */
414
418
  groupKind: SyncGroupKind;
415
419
  /** 配置组固定为 `config`;数据组为其 groupId。 */
@@ -422,6 +426,18 @@ interface SyncGroupSyncEvent {
422
426
  result?: SyncResult;
423
427
  /** `sync:error` 时的错误消息。 */
424
428
  error?: string;
429
+ /**
430
+ * 逐文件进度。上游 `zen-fs-sync` 尚未提供,保留字段供后续透传。
431
+ * 调用方不能假设它一定存在,也不能据此伪造百分比。
432
+ */
433
+ progress?: {
434
+ processed: number;
435
+ total?: number;
436
+ currentPath?: string;
437
+ phase?: string;
438
+ };
439
+ /** `conflict` 时的上游冲突详情。 */
440
+ conflict?: unknown;
425
441
  }
426
442
  /** Structural discriminator for a sync group. */
427
443
  type SyncGroupKind = 'config' | 'data';
@@ -1704,6 +1720,18 @@ declare class ConfigRepo implements IConfigRepo {
1704
1720
  * from the referenced config-sync backend (if accountBackendId is set).
1705
1721
  */
1706
1722
  private resolveAppDataBackendOptions;
1723
+ /**
1724
+ * 读一个数据组后端根上的 `.meta/group.json`(只读,不写、不建同步对)。
1725
+ *
1726
+ * `null` = 空仓库(可以认领);抛错 = 读不到(调用方必须 fail-closed)。
1727
+ * 复用的实例由调用方负责 dispose。
1728
+ */
1729
+ private readRemoteGroupDescriptor;
1730
+ /**
1731
+ * 同一个远端目录只能归一个组。`.meta/group.json` 里的 `kind`/`id` 就是归属
1732
+ * 记录 —— 它与「本地方知不知道这个组」无关,描述符丢了也照样能判定。
1733
+ */
1734
+ private assertRemoteNotOwnedByOthers;
1707
1735
  /**
1708
1736
  * Reject two groups pointing at the exact same remote endpoint. Two groups
1709
1737
  * syncing the same files independently would fight over deletions and
@@ -2159,6 +2187,180 @@ declare function probeGroupTypeDetailed(type: string, options: Record<string, un
2159
2187
  */
2160
2188
  declare function connect(appId: string, options?: ConnectOptions): Promise<ConnectResult>;
2161
2189
 
2190
+ interface DataBackendInput {
2191
+ /** Stable backend id. Omit to auto-generate. */
2192
+ id?: string;
2193
+ type: string;
2194
+ options: Record<string, unknown>;
2195
+ description?: string;
2196
+ }
2197
+ interface AddBackendResult {
2198
+ backendId: string;
2199
+ /** false when the same id or endpoint was already present (idempotent). */
2200
+ addedBackend: boolean;
2201
+ }
2202
+ /** One data-sync pair's result, mirrored from `SyncResult`. */
2203
+ interface DataGroupSyncResult {
2204
+ filesCreated: number;
2205
+ filesUpdated: number;
2206
+ filesDeleted: number;
2207
+ filesSkipped: number;
2208
+ conflicts: unknown[];
2209
+ errors: unknown[];
2210
+ durationMs: number;
2211
+ }
2212
+ /** One pair's result from an explicit `flush()`, including its pair id. */
2213
+ interface DataGroupFlushResult extends DataGroupSyncResult {
2214
+ pairId: string;
2215
+ }
2216
+ /** Lightweight group list entry; no descriptors or backend credentials. */
2217
+ interface DataGroupInfo {
2218
+ id: string;
2219
+ name: string;
2220
+ /** true when the group declares at least one remote backend. */
2221
+ hasRemote: boolean;
2222
+ }
2223
+ interface DataGroupSyncProgress {
2224
+ processed: number;
2225
+ total?: number;
2226
+ currentPath?: string;
2227
+ phase?: string;
2228
+ }
2229
+ type DataGroupSyncEvent = {
2230
+ type: 'sync:start';
2231
+ groupId: string;
2232
+ backendId: string;
2233
+ pairId: string;
2234
+ timestamp: number;
2235
+ } | {
2236
+ type: 'sync:progress';
2237
+ groupId: string;
2238
+ backendId: string;
2239
+ pairId: string;
2240
+ timestamp: number;
2241
+ progress: DataGroupSyncProgress;
2242
+ } | {
2243
+ type: 'sync:end';
2244
+ groupId: string;
2245
+ backendId: string;
2246
+ pairId: string;
2247
+ timestamp: number;
2248
+ result: DataGroupSyncResult;
2249
+ } | {
2250
+ type: 'sync:error';
2251
+ groupId: string;
2252
+ backendId: string;
2253
+ pairId: string;
2254
+ timestamp: number;
2255
+ error: string;
2256
+ } | {
2257
+ type: 'conflict';
2258
+ groupId: string;
2259
+ backendId: string;
2260
+ pairId: string;
2261
+ timestamp: number;
2262
+ conflict: unknown;
2263
+ };
2264
+ interface DataGroup {
2265
+ readonly id: string;
2266
+ readonly fs: AppDataGroup['fs'];
2267
+ addBackend(input: DataBackendInput): Promise<AddBackendResult>;
2268
+ /** Sync this group's pairs now and return one result per pair. */
2269
+ flush(): Promise<DataGroupFlushResult[]>;
2270
+ /**
2271
+ * Delete a group-relative path through the group's tombstone-aware path.
2272
+ * Prefer this over fs.promises.unlink so the deletion propagates and cannot
2273
+ * be resurrected by the next sync.
2274
+ */
2275
+ deleteFile(path: string): Promise<void>;
2276
+ onSyncEvent(handler: (event: DataGroupSyncEvent) => void): () => void;
2277
+ }
2278
+ interface AppRepo {
2279
+ readonly appId: string;
2280
+ getDefaultDataGroup(): Promise<DataGroup>;
2281
+ /** Load an existing group by id. Never creates a group. */
2282
+ getDataGroup(id: string): Promise<DataGroup>;
2283
+ /** Existing groups on this device, for an app-side group picker. */
2284
+ listDataGroups(): Promise<DataGroupInfo[]>;
2285
+ }
2286
+ interface ConfigBackendInput {
2287
+ id?: string;
2288
+ type: string;
2289
+ options: Record<string, unknown>;
2290
+ description?: string;
2291
+ }
2292
+ /**
2293
+ * connectV2 keeps the config-sync options of the legacy connect() but never
2294
+ * accepts data backends: data backends belong to a DataGroup and are added via
2295
+ * DataGroup.addBackend().
2296
+ */
2297
+ interface ConnectV2Options extends Omit<ConnectOptions, 'backendInfo'> {
2298
+ backendInfo?: {
2299
+ type: string;
2300
+ options: Record<string, unknown>;
2301
+ };
2302
+ /** Extra config-sync replicas. The first one becomes the primary replica. */
2303
+ configBackends?: ConfigBackendInput[];
2304
+ /** Must not be used with connectV2; kept out of the type on purpose. */
2305
+ dataBackends?: never;
2306
+ }
2307
+ /** A raw connection carrying the appId needed to wrap it as an AppRepo. */
2308
+ type UiConnection = ConnectResult & {
2309
+ appId: string;
2310
+ };
2311
+ declare class ConnectV2Error extends Error {
2312
+ readonly code: string;
2313
+ constructor(message: string, code: string);
2314
+ }
2315
+ declare class ConnectFailedError extends ConnectV2Error {
2316
+ constructor(message: string);
2317
+ }
2318
+ declare class ConfigNotReadyError extends ConnectV2Error {
2319
+ constructor(message: string);
2320
+ }
2321
+ declare class InvalidBackendError extends ConnectV2Error {
2322
+ constructor(message: string);
2323
+ }
2324
+ declare class BackendAlreadyExistsError extends ConnectV2Error {
2325
+ constructor(message: string);
2326
+ }
2327
+ declare class BackendEndpointConflictError extends ConnectV2Error {
2328
+ constructor(message: string);
2329
+ }
2330
+ declare class BackendIdentityError extends ConnectV2Error {
2331
+ constructor(message: string);
2332
+ }
2333
+ declare class DataGroupCreateError extends ConnectV2Error {
2334
+ constructor(message: string);
2335
+ }
2336
+ declare class DataGroupBackendError extends ConnectV2Error {
2337
+ constructor(message: string);
2338
+ }
2339
+ declare class DataGroupNotFoundError extends ConnectV2Error {
2340
+ constructor(message: string);
2341
+ }
2342
+ declare class DataGroupOperationError extends ConnectV2Error {
2343
+ constructor(message: string);
2344
+ }
2345
+ /**
2346
+ * Wrap a raw connect() result as an AppRepo, preserving object identity: the
2347
+ * same connection always yields the same AppRepo wrapper.
2348
+ */
2349
+ declare function connectionToAppRepo(connection: UiConnection): AppRepo;
2350
+ /**
2351
+ * Get the raw connection behind an AppRepo. Intended for zen-fs-config-ui;
2352
+ * product code should only use AppRepo.
2353
+ */
2354
+ declare function getUiConnection(repo: AppRepo): UiConnection;
2355
+ /**
2356
+ * Connect as a config-sync repo and return the small AppRepo surface.
2357
+ *
2358
+ * Internally calls the legacy connect() once; there is no separate pool. The
2359
+ * cache key includes appId + connection options so repeated calls with the
2360
+ * same topology share the same repo instance.
2361
+ */
2362
+ declare function connectV2(appId: string, options?: ConnectV2Options): Promise<AppRepo>;
2363
+
2162
2364
  /**
2163
2365
  * zen-fs-config — Sidecar Version File Management
2164
2366
  *
@@ -2385,4 +2587,4 @@ declare class ConflictStore {
2385
2587
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
2386
2588
  }
2387
2589
 
2388
- 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 GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, 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, NeedsInitError, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, 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, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, resolveRemoteIdentity, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
2590
+ 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, type DataBackendInput, type DataGroup, DataGroupBackendError, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, 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 PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, 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, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, getUiConnection, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, resolveRemoteIdentity, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
package/dist/index.d.ts CHANGED
@@ -409,7 +409,11 @@ interface BackendSyncState {
409
409
  * 里的计数过滤自己关心的变更;`sync:error` 只在整轮抛错时发。
410
410
  */
411
411
  interface SyncGroupSyncEvent {
412
- type: 'sync:end' | 'sync:error';
412
+ /**
413
+ * `sync:progress` 由未来的 zen-fs-sync 逐文件进度回调提供;当前上游没有,
414
+ * 库不会伪造这个事件。
415
+ */
416
+ type: 'sync:start' | 'sync:progress' | 'sync:end' | 'sync:error' | 'conflict';
413
417
  /** 事件所属组的类型。 */
414
418
  groupKind: SyncGroupKind;
415
419
  /** 配置组固定为 `config`;数据组为其 groupId。 */
@@ -422,6 +426,18 @@ interface SyncGroupSyncEvent {
422
426
  result?: SyncResult;
423
427
  /** `sync:error` 时的错误消息。 */
424
428
  error?: string;
429
+ /**
430
+ * 逐文件进度。上游 `zen-fs-sync` 尚未提供,保留字段供后续透传。
431
+ * 调用方不能假设它一定存在,也不能据此伪造百分比。
432
+ */
433
+ progress?: {
434
+ processed: number;
435
+ total?: number;
436
+ currentPath?: string;
437
+ phase?: string;
438
+ };
439
+ /** `conflict` 时的上游冲突详情。 */
440
+ conflict?: unknown;
425
441
  }
426
442
  /** Structural discriminator for a sync group. */
427
443
  type SyncGroupKind = 'config' | 'data';
@@ -1704,6 +1720,18 @@ declare class ConfigRepo implements IConfigRepo {
1704
1720
  * from the referenced config-sync backend (if accountBackendId is set).
1705
1721
  */
1706
1722
  private resolveAppDataBackendOptions;
1723
+ /**
1724
+ * 读一个数据组后端根上的 `.meta/group.json`(只读,不写、不建同步对)。
1725
+ *
1726
+ * `null` = 空仓库(可以认领);抛错 = 读不到(调用方必须 fail-closed)。
1727
+ * 复用的实例由调用方负责 dispose。
1728
+ */
1729
+ private readRemoteGroupDescriptor;
1730
+ /**
1731
+ * 同一个远端目录只能归一个组。`.meta/group.json` 里的 `kind`/`id` 就是归属
1732
+ * 记录 —— 它与「本地方知不知道这个组」无关,描述符丢了也照样能判定。
1733
+ */
1734
+ private assertRemoteNotOwnedByOthers;
1707
1735
  /**
1708
1736
  * Reject two groups pointing at the exact same remote endpoint. Two groups
1709
1737
  * syncing the same files independently would fight over deletions and
@@ -2159,6 +2187,180 @@ declare function probeGroupTypeDetailed(type: string, options: Record<string, un
2159
2187
  */
2160
2188
  declare function connect(appId: string, options?: ConnectOptions): Promise<ConnectResult>;
2161
2189
 
2190
+ interface DataBackendInput {
2191
+ /** Stable backend id. Omit to auto-generate. */
2192
+ id?: string;
2193
+ type: string;
2194
+ options: Record<string, unknown>;
2195
+ description?: string;
2196
+ }
2197
+ interface AddBackendResult {
2198
+ backendId: string;
2199
+ /** false when the same id or endpoint was already present (idempotent). */
2200
+ addedBackend: boolean;
2201
+ }
2202
+ /** One data-sync pair's result, mirrored from `SyncResult`. */
2203
+ interface DataGroupSyncResult {
2204
+ filesCreated: number;
2205
+ filesUpdated: number;
2206
+ filesDeleted: number;
2207
+ filesSkipped: number;
2208
+ conflicts: unknown[];
2209
+ errors: unknown[];
2210
+ durationMs: number;
2211
+ }
2212
+ /** One pair's result from an explicit `flush()`, including its pair id. */
2213
+ interface DataGroupFlushResult extends DataGroupSyncResult {
2214
+ pairId: string;
2215
+ }
2216
+ /** Lightweight group list entry; no descriptors or backend credentials. */
2217
+ interface DataGroupInfo {
2218
+ id: string;
2219
+ name: string;
2220
+ /** true when the group declares at least one remote backend. */
2221
+ hasRemote: boolean;
2222
+ }
2223
+ interface DataGroupSyncProgress {
2224
+ processed: number;
2225
+ total?: number;
2226
+ currentPath?: string;
2227
+ phase?: string;
2228
+ }
2229
+ type DataGroupSyncEvent = {
2230
+ type: 'sync:start';
2231
+ groupId: string;
2232
+ backendId: string;
2233
+ pairId: string;
2234
+ timestamp: number;
2235
+ } | {
2236
+ type: 'sync:progress';
2237
+ groupId: string;
2238
+ backendId: string;
2239
+ pairId: string;
2240
+ timestamp: number;
2241
+ progress: DataGroupSyncProgress;
2242
+ } | {
2243
+ type: 'sync:end';
2244
+ groupId: string;
2245
+ backendId: string;
2246
+ pairId: string;
2247
+ timestamp: number;
2248
+ result: DataGroupSyncResult;
2249
+ } | {
2250
+ type: 'sync:error';
2251
+ groupId: string;
2252
+ backendId: string;
2253
+ pairId: string;
2254
+ timestamp: number;
2255
+ error: string;
2256
+ } | {
2257
+ type: 'conflict';
2258
+ groupId: string;
2259
+ backendId: string;
2260
+ pairId: string;
2261
+ timestamp: number;
2262
+ conflict: unknown;
2263
+ };
2264
+ interface DataGroup {
2265
+ readonly id: string;
2266
+ readonly fs: AppDataGroup['fs'];
2267
+ addBackend(input: DataBackendInput): Promise<AddBackendResult>;
2268
+ /** Sync this group's pairs now and return one result per pair. */
2269
+ flush(): Promise<DataGroupFlushResult[]>;
2270
+ /**
2271
+ * Delete a group-relative path through the group's tombstone-aware path.
2272
+ * Prefer this over fs.promises.unlink so the deletion propagates and cannot
2273
+ * be resurrected by the next sync.
2274
+ */
2275
+ deleteFile(path: string): Promise<void>;
2276
+ onSyncEvent(handler: (event: DataGroupSyncEvent) => void): () => void;
2277
+ }
2278
+ interface AppRepo {
2279
+ readonly appId: string;
2280
+ getDefaultDataGroup(): Promise<DataGroup>;
2281
+ /** Load an existing group by id. Never creates a group. */
2282
+ getDataGroup(id: string): Promise<DataGroup>;
2283
+ /** Existing groups on this device, for an app-side group picker. */
2284
+ listDataGroups(): Promise<DataGroupInfo[]>;
2285
+ }
2286
+ interface ConfigBackendInput {
2287
+ id?: string;
2288
+ type: string;
2289
+ options: Record<string, unknown>;
2290
+ description?: string;
2291
+ }
2292
+ /**
2293
+ * connectV2 keeps the config-sync options of the legacy connect() but never
2294
+ * accepts data backends: data backends belong to a DataGroup and are added via
2295
+ * DataGroup.addBackend().
2296
+ */
2297
+ interface ConnectV2Options extends Omit<ConnectOptions, 'backendInfo'> {
2298
+ backendInfo?: {
2299
+ type: string;
2300
+ options: Record<string, unknown>;
2301
+ };
2302
+ /** Extra config-sync replicas. The first one becomes the primary replica. */
2303
+ configBackends?: ConfigBackendInput[];
2304
+ /** Must not be used with connectV2; kept out of the type on purpose. */
2305
+ dataBackends?: never;
2306
+ }
2307
+ /** A raw connection carrying the appId needed to wrap it as an AppRepo. */
2308
+ type UiConnection = ConnectResult & {
2309
+ appId: string;
2310
+ };
2311
+ declare class ConnectV2Error extends Error {
2312
+ readonly code: string;
2313
+ constructor(message: string, code: string);
2314
+ }
2315
+ declare class ConnectFailedError extends ConnectV2Error {
2316
+ constructor(message: string);
2317
+ }
2318
+ declare class ConfigNotReadyError extends ConnectV2Error {
2319
+ constructor(message: string);
2320
+ }
2321
+ declare class InvalidBackendError extends ConnectV2Error {
2322
+ constructor(message: string);
2323
+ }
2324
+ declare class BackendAlreadyExistsError extends ConnectV2Error {
2325
+ constructor(message: string);
2326
+ }
2327
+ declare class BackendEndpointConflictError extends ConnectV2Error {
2328
+ constructor(message: string);
2329
+ }
2330
+ declare class BackendIdentityError extends ConnectV2Error {
2331
+ constructor(message: string);
2332
+ }
2333
+ declare class DataGroupCreateError extends ConnectV2Error {
2334
+ constructor(message: string);
2335
+ }
2336
+ declare class DataGroupBackendError extends ConnectV2Error {
2337
+ constructor(message: string);
2338
+ }
2339
+ declare class DataGroupNotFoundError extends ConnectV2Error {
2340
+ constructor(message: string);
2341
+ }
2342
+ declare class DataGroupOperationError extends ConnectV2Error {
2343
+ constructor(message: string);
2344
+ }
2345
+ /**
2346
+ * Wrap a raw connect() result as an AppRepo, preserving object identity: the
2347
+ * same connection always yields the same AppRepo wrapper.
2348
+ */
2349
+ declare function connectionToAppRepo(connection: UiConnection): AppRepo;
2350
+ /**
2351
+ * Get the raw connection behind an AppRepo. Intended for zen-fs-config-ui;
2352
+ * product code should only use AppRepo.
2353
+ */
2354
+ declare function getUiConnection(repo: AppRepo): UiConnection;
2355
+ /**
2356
+ * Connect as a config-sync repo and return the small AppRepo surface.
2357
+ *
2358
+ * Internally calls the legacy connect() once; there is no separate pool. The
2359
+ * cache key includes appId + connection options so repeated calls with the
2360
+ * same topology share the same repo instance.
2361
+ */
2362
+ declare function connectV2(appId: string, options?: ConnectV2Options): Promise<AppRepo>;
2363
+
2162
2364
  /**
2163
2365
  * zen-fs-config — Sidecar Version File Management
2164
2366
  *
@@ -2385,4 +2587,4 @@ declare class ConflictStore {
2385
2587
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
2386
2588
  }
2387
2589
 
2388
- 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 GroupInstanceIdRootResult, type GroupProbeResult, type GroupProbeState, type IConfigRepo, type IdentityBindingResult, type IdentityCandidate, type IdentityCandidateSource, 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, NeedsInitError, type PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, type SetGroupInstanceIdOptions, type SetGroupInstanceIdResult, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupSyncEvent, 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, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, resolveRemoteIdentity, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
2590
+ 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, type DataBackendInput, type DataGroup, DataGroupBackendError, DataGroupCreateError, type DataGroupFlushResult, type DataGroupInfo, DataGroupNotFoundError, DataGroupOperationError, type DataGroupSyncEvent, type DataGroupSyncProgress, type DataGroupSyncResult, 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 PurgeKeepOptions, type PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type RemoteIdentitySnapshot, type RemoteIdentityState, RemoteUnreachableError, type ReplicaSetupSummary, 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, configKeyToFilePath, connect, connectV2, connectionToAppRepo, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, deleteIndexedDbStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, getUiConnection, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, isValidGroupInstanceId, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, newGroupInstanceId, probeGroupTypeDetailed, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, resolveRemoteIdentity, sha256, shortInstanceId, summarizeIdentity, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };