zen-fs-config 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/index.d.mts +324 -2
- package/dist/index.d.ts +324 -2
- package/dist/index.js +879 -17
- package/dist/index.mjs +855 -17
- package/dist/zen-fs-config.js +854 -17
- package/package.json +1 -1
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
|
-
|
|
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,124 @@ declare class ConflictStore {
|
|
|
2385
2587
|
resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
|
|
2386
2588
|
}
|
|
2387
2589
|
|
|
2388
|
-
|
|
2590
|
+
/**
|
|
2591
|
+
* 数据组选择(跨 app 通用)
|
|
2592
|
+
*
|
|
2593
|
+
* 一个 appId 下可能存在多个数据同步组:历史 `default` 空组、换过后端的旧组、
|
|
2594
|
+
* 新建组。旧写法「取 `appDataGroups[0]`」会挂错组,数据写进空组、看起来像
|
|
2595
|
+
* 「没同步」。这一层解决「该挂哪个组」:
|
|
2596
|
+
*
|
|
2597
|
+
* 1. 用户在界面上显式选过的组(本机偏好,localStorage);
|
|
2598
|
+
* 2. 目标目录下确实已有内容的组;
|
|
2599
|
+
* 3. 带远端后端的组(唯一一个时直接用);
|
|
2600
|
+
* 4. 只有一个候选时用它。
|
|
2601
|
+
*
|
|
2602
|
+
* 多个候选且无法判定时返回 `null`,由界面列出来让用户选 —— 绝不静默择一。
|
|
2603
|
+
*
|
|
2604
|
+
* 这些逻辑与具体应用无关,所以放在库里;应用只提供 `appId` 与自己的数据目录
|
|
2605
|
+
* (如 `/golf`、`/bookkeeping`)。
|
|
2606
|
+
*
|
|
2607
|
+
* 作用对象既可以是 `ConfigRepo`,也可以是配置面板 `onConnected` 交出的
|
|
2608
|
+
* `{ repo, dataGroup }` 句柄:函数内部统一归一化,避免各应用各写一份适配。
|
|
2609
|
+
*/
|
|
2610
|
+
|
|
2611
|
+
/** 该后端类型是否只是本机存储(不参与跨设备同步)。 */
|
|
2612
|
+
declare function isLocalBackendType(type: string): boolean;
|
|
2613
|
+
/** 默认 localStorage 键前缀:`zen-fs-config:data-group:{appId}`。 */
|
|
2614
|
+
declare const DATA_GROUP_PREFERENCE_PREFIX = "zen-fs-config:data-group:";
|
|
2615
|
+
/** 最小 storage 形状(浏览器 localStorage / 测试替身)。 */
|
|
2616
|
+
interface PreferenceStorage {
|
|
2617
|
+
getItem(key: string): string | null;
|
|
2618
|
+
setItem(key: string, value: string): void;
|
|
2619
|
+
removeItem(key: string): void;
|
|
2620
|
+
}
|
|
2621
|
+
interface PreferenceOptions {
|
|
2622
|
+
storage?: PreferenceStorage;
|
|
2623
|
+
/** 写入用的键前缀,默认 {@link DATA_GROUP_PREFERENCE_PREFIX}。 */
|
|
2624
|
+
keyPrefix?: string;
|
|
2625
|
+
/**
|
|
2626
|
+
* 读取时依次尝试的键前缀(默认只用 `keyPrefix`)。
|
|
2627
|
+
* 迁移场景可把旧产品自己的键放进来,例如 `['zen-fs-config:data-group:', 'onenav:data-group:']`。
|
|
2628
|
+
*/
|
|
2629
|
+
readPrefixes?: string[];
|
|
2630
|
+
}
|
|
2631
|
+
/** 本机为该 appId 记住的数据组 id(没有则 `null`)。 */
|
|
2632
|
+
declare function getPreferredDataGroupId(appId: string, opts?: PreferenceOptions): string | null;
|
|
2633
|
+
/** 记住(`id === null` 时清除)本机为该 appId 选定的数据组。 */
|
|
2634
|
+
declare function setPreferredDataGroupId(appId: string, id: string | null, opts?: PreferenceOptions): void;
|
|
2635
|
+
/** 一个候选数据组(配置仓描述符 + 已实例化的组)。 */
|
|
2636
|
+
interface DataGroupCandidate {
|
|
2637
|
+
id: string;
|
|
2638
|
+
name?: string;
|
|
2639
|
+
group: AppDataGroup;
|
|
2640
|
+
/** 组里是否有非本地后端(即真能跨设备同步) */
|
|
2641
|
+
hasRemote: boolean;
|
|
2642
|
+
/** 后端类型列表,便于界面展示 */
|
|
2643
|
+
backendTypes: string[];
|
|
2644
|
+
/** 目标目录下是否已有内容(用于判断「哪个组才是真正装了数据的」) */
|
|
2645
|
+
hasData: boolean;
|
|
2646
|
+
/**
|
|
2647
|
+
* 该组的隐式本地主存储名(浏览器里是 IndexedDB)。
|
|
2648
|
+
*
|
|
2649
|
+
* 每个数据组都内置一个 local primary,它是组的本地 source / 离线缓存,
|
|
2650
|
+
* 不参与远端同步、也不出现在组描述符里;不能把它当成一个独立可选的数据组。
|
|
2651
|
+
*/
|
|
2652
|
+
localStore: string;
|
|
2653
|
+
}
|
|
2654
|
+
/** 数据组来源:`ConfigRepo` 本身,或配置面板 `onConnected` 交出的句柄。 */
|
|
2655
|
+
type DataGroupSource = IConfigRepo | {
|
|
2656
|
+
repo?: IConfigRepo | null;
|
|
2657
|
+
dataGroup?: AppDataGroup | null;
|
|
2658
|
+
};
|
|
2659
|
+
/** 组在 `path` 下是否至少有一个条目(读失败/未连接都算空)。 */
|
|
2660
|
+
declare function groupHasPath(group: AppDataGroup, path: string): Promise<boolean>;
|
|
2661
|
+
/**
|
|
2662
|
+
* 列出当前 appId 的所有数据组候选(带「是否有数据 / 是否有远端后端」)。
|
|
2663
|
+
*
|
|
2664
|
+
* @param source `ConfigRepo` 或 `{ repo, dataGroup }`
|
|
2665
|
+
* @param appId 应用 id(与 `connect()` 用的是同一个)
|
|
2666
|
+
* @param opts.path 判断「组里是否已有数据」的目录(通常是应用自己的数据目录)
|
|
2667
|
+
*/
|
|
2668
|
+
declare function listDataGroupCandidates(source: DataGroupSource, appId: string, opts?: {
|
|
2669
|
+
path?: string;
|
|
2670
|
+
}): Promise<DataGroupCandidate[]>;
|
|
2671
|
+
/** 兼容旧命名(应用侧曾叫 collectDataGroupCandidates)。 */
|
|
2672
|
+
declare const collectDataGroupCandidates: typeof listDataGroupCandidates;
|
|
2673
|
+
interface ResolveDataGroupOptions {
|
|
2674
|
+
/** 显式指定的组 id;缺省读本机偏好。 */
|
|
2675
|
+
preferGroupId?: string | null;
|
|
2676
|
+
/** 应用自己的数据目录,用于「哪个组里真有数据」的判定。 */
|
|
2677
|
+
path?: string;
|
|
2678
|
+
preference?: PreferenceOptions;
|
|
2679
|
+
}
|
|
2680
|
+
/**
|
|
2681
|
+
* 按「偏好 → 有数据 → 唯一远端 → 单候选」的顺序解析出要挂载的组。
|
|
2682
|
+
* 多个候选且无法判定时返回 `null`,交给界面让用户选。
|
|
2683
|
+
*/
|
|
2684
|
+
declare function resolveDataGroup(source: DataGroupSource, appId: string, opts?: ResolveDataGroupOptions): Promise<AppDataGroup | null>;
|
|
2685
|
+
interface EnsureDataGroupOptions extends ResolveDataGroupOptions {
|
|
2686
|
+
/** 是否允许在「一个描述符都没有」时补建本机默认组(默认允许)。 */
|
|
2687
|
+
allowCreateLocal?: boolean;
|
|
2688
|
+
}
|
|
2689
|
+
interface EnsureDataGroupResult {
|
|
2690
|
+
group: AppDataGroup | null;
|
|
2691
|
+
candidates: DataGroupCandidate[];
|
|
2692
|
+
/** 本次是否新建了本机默认组(界面据此提示「仅本地」) */
|
|
2693
|
+
created: boolean;
|
|
2694
|
+
/** 有描述符但一个都加载不出来(此时不建 default,避免与远端组冲突) */
|
|
2695
|
+
descriptorsUnavailable: boolean;
|
|
2696
|
+
}
|
|
2697
|
+
/**
|
|
2698
|
+
* 确保某个 appId **至少有一个可用的数据组实例**,没有就建一个本机默认组。
|
|
2699
|
+
*
|
|
2700
|
+
* 数据组不是「只有配了远端后端才有」:每个组都自带隐式本地主存储。应用要在
|
|
2701
|
+
* 数据组里读写就必须有一个组实例,否则页面只能停在「还没有数据组」。
|
|
2702
|
+
*
|
|
2703
|
+
* - 已有描述符:按 {@link resolveDataGroup} 的规则选;
|
|
2704
|
+
* - **一个描述符都没有**:`createAppDataGroup('default', [])`,得到一个只有
|
|
2705
|
+
* 隐式本地存储的组(不参与远端同步,之后可再加远端后端);
|
|
2706
|
+
* - **有描述符但都加载失败**:绝不建 default,返回 `descriptorsUnavailable`。
|
|
2707
|
+
*/
|
|
2708
|
+
declare function ensureDataGroup(source: DataGroupSource, appId: string, opts?: EnsureDataGroupOptions): Promise<EnsureDataGroupResult>;
|
|
2709
|
+
|
|
2710
|
+
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 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, 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 };
|