zen-fs-config 0.5.51 → 0.6.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
@@ -385,18 +385,33 @@ interface SyncGroupFeatures {
385
385
  }
386
386
  /** Content of `.meta/group.json` — the unified group descriptor. */
387
387
  interface GroupDescriptor {
388
- schemaVersion: 1;
388
+ /**
389
+ * 2 = 规范化序列化 + 不再写 `updatedAt`。读取时 1 与 2 一视同仁;
390
+ * 1 的老文件会在下一次内容变化时被就地升级。
391
+ */
392
+ schemaVersion: 1 | 2;
389
393
  kind: SyncGroupKind;
390
394
  /** Group id (`config` for the config-sync group, the descriptor id otherwise). */
391
395
  id?: string;
392
396
  /** User-editable display name. */
393
397
  name?: string;
394
398
  features?: Partial<SyncGroupFeatures>;
399
+ /**
400
+ * @deprecated 不再写入、读取侧忽略。时间戳写进随同步走的内容会形成
401
+ * 「写 → 内容变 → 触发同步 → 对端再写」的无限回环,只允许放在本地存储。
402
+ */
395
403
  updatedAt?: number;
396
404
  }
397
405
  /**
398
- * Common handle shared by config-sync and data-sync groups.
399
- * The config group is the capability superset (see ConfigSyncGroupHandle).
406
+ * One sync group = a local primary store + zero-or-more remote replicas +
407
+ * the shared `.meta/` metadata area + that group's own backend definitions.
408
+ *
409
+ * 配置组与数据组是**同一基座上的两个能力位**,不是「配置组 ⊃ 数据组」:
410
+ * - 配置组 `configHost = true`:可承载 `.config`(数据组登记、引导副本、
411
+ * `group-type`),整棵 `/` 参与同步;
412
+ * - 数据组 `appData = true`:可被登记为数据组,同步时排除 `/.config`、
413
+ * `/nodes`、`/shared`。
414
+ * 两个能力位互不蕴含。
400
415
  */
401
416
  interface SyncGroupHandle {
402
417
  readonly groupId: string;
@@ -414,6 +429,14 @@ interface SyncGroupHandle {
414
429
  addBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
415
430
  removeBackend(id: string): Promise<void>;
416
431
  listBackends(): AppDataBackendDescriptor[];
432
+ /**
433
+ * 该组**声明**的后端列表(权威定义,允许尚未连接成功的条目)。
434
+ *
435
+ * 数据组读自自己的 `.meta/backends/`;配置组读自 `.config/backends/`。
436
+ * 与 `listBackends()`(已连接视图)不同,这个列表不会因为后端暂时不可达
437
+ * 而少显示条目。
438
+ */
439
+ listDeclaredBackends(): AppDataBackendDescriptor[];
417
440
  /** Update the display name only (descriptor-only). */
418
441
  rename(name: string): Promise<void>;
419
442
  /** Write a tombstone, delete the file + version record, trigger sync. */
@@ -1075,8 +1098,20 @@ declare class ConfigRepo implements IConfigRepo {
1075
1098
  * (they have no sync pair, so they never show up in getSyncStatuses()).
1076
1099
  */
1077
1100
  getBackendSyncStates(): Map<string, BackendSyncState>;
1101
+ /**
1102
+ * Mirror per-pair `sync:error` into `getBackendSyncStates()`.
1103
+ *
1104
+ * `SyncEngine.syncAll()` catches per-pair exceptions and substitutes an empty
1105
+ * result, so a failed replica otherwise only shows up as a missing
1106
+ * `lastResult`. Recording the real error lets callers report the actual
1107
+ * status (401/403/404/timeout) instead of guessing "remote unreachable or
1108
+ * invalid credentials".
1109
+ */
1110
+ private trackSyncErrors;
1078
1111
  /** Registered replica backend descriptors (excludes the implicit local primary). */
1079
1112
  listBackends(): AppDataBackendDescriptor[];
1113
+ /** 配置组的权威后端列表(`.config/backends/`),与 `listBackends()` 相同。 */
1114
+ listDeclaredBackends(): AppDataBackendDescriptor[];
1080
1115
  /** Update the config-sync group's display name only. */
1081
1116
  rename(name: string): Promise<void>;
1082
1117
  resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
@@ -1097,6 +1132,8 @@ declare class ConfigRepo implements IConfigRepo {
1097
1132
  private walkDir;
1098
1133
  writeMetaFile(path: string, data: unknown): Promise<void>;
1099
1134
  readMetaFile<T>(path: string): Promise<T | null>;
1135
+ /** Read a text file; `null` when absent (used for byte-compare-then-write). */
1136
+ private readTextIfExists;
1100
1137
  /** Path for a single backend descriptor: .config/backends/{id}.json */
1101
1138
  backendFilePath(id: string): string;
1102
1139
  /** Legacy path: .meta/backends/{id}.json (read + dual-write for one cycle). */
@@ -1116,6 +1153,9 @@ declare class ConfigRepo implements IConfigRepo {
1116
1153
  * Write a single backend descriptor to `.config/backends/{id}.json`,
1117
1154
  * mirroring to the legacy `.meta/backends/{id}.json` for one release cycle
1118
1155
  * so older clients still see the backend.
1156
+ *
1157
+ * Both files use the canonical serializer and are only written when their
1158
+ * bytes actually differ (no needless sync churn).
1119
1159
  */
1120
1160
  writeBackendDescriptor(desc: BackendDescriptor): Promise<void>;
1121
1161
  /** Remove a single backend descriptor file + its version sidecar (both layouts) */
@@ -1149,7 +1189,16 @@ declare class ConfigRepo implements IConfigRepo {
1149
1189
  private appDataGroupFilePath;
1150
1190
  /** Legacy descriptor path: .meta/app-data-groups/{appId}/{id}.json */
1151
1191
  private legacyAppDataGroupFilePath;
1152
- /** Write a data-group descriptor to the new path, mirroring to the legacy one. */
1192
+ /**
1193
+ * Write a data-group descriptor to `.config/` (bootstrap copy), mirroring to
1194
+ * the legacy `.meta/` path.
1195
+ *
1196
+ * 这份描述符是**引导副本**:它让只有配置组凭据的新设备知道有哪些数据组、
1197
+ * 远端在哪。权威定义在数据组自己的 `.meta/backends/`。
1198
+ *
1199
+ * 幂等:按规范化字节比较,相同则不写;`createdAt` 与磁盘现值取 `min`,
1200
+ * 因此时间戳差异不会让两台设备互相覆盖。
1201
+ */
1153
1202
  private writeAppDataGroupDescriptorFile;
1154
1203
  /**
1155
1204
  * Resolve a backend descriptor's options by merging account fields
@@ -1167,11 +1216,18 @@ declare class ConfigRepo implements IConfigRepo {
1167
1216
  features?: Partial<SyncGroupFeatures>;
1168
1217
  }): Promise<AppDataGroup>;
1169
1218
  /**
1170
- * Rewrite an app data group's descriptor (e.g. after addBackend/removeBackend)
1171
- * into .meta/app-data-groups/{appId}/{id}.json, keeping config-sync as the
1172
- * authoritative source of the data group's backend topology (FR2.3).
1219
+ * Rewrite an app data group's **bootstrap copy** at
1220
+ * `.config/app-data-groups/{appId}/{id}.json` (plus the legacy `.meta/`
1221
+ * mirror). The authoritative backend list lives in the data group's own
1222
+ * `.meta/backends/`; this file only lets a new device that has nothing but
1223
+ * the config group's credentials discover the data groups and their remotes.
1224
+ *
1225
+ * 幂等:投影字节相同则不写(见 `writeAppDataGroupDescriptorFile`)。
1173
1226
  */
1174
- updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[]): Promise<void>;
1227
+ updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[], meta?: {
1228
+ name?: string;
1229
+ features?: Partial<SyncGroupFeatures>;
1230
+ }): Promise<void>;
1175
1231
  /**
1176
1232
  * Change a data-sync group's display name only. `id`, backends, local stores
1177
1233
  * and remote data are untouched, so existing sync pairs keep working.
@@ -1240,6 +1296,13 @@ declare function isBrowserEnv(): boolean;
1240
1296
  interface LocalPrimaryOptions {
1241
1297
  idbStoreName?: string;
1242
1298
  folderPath?: string;
1299
+ /**
1300
+ * Data groups only: non-default groups live in an isolated directory
1301
+ * (`<base>/data/{appId}/{groupId}`) so two groups never share files.
1302
+ * `default` keeps the legacy `<base>/data/{appId}` path (lazy migration:
1303
+ * existing files are neither moved nor deleted).
1304
+ */
1305
+ groupId?: string;
1243
1306
  }
1244
1307
  /**
1245
1308
  * Resolve the local primary backend descriptor for the current environment.
@@ -1390,9 +1453,15 @@ type MetaFS = {
1390
1453
  * `/a/b.json` → `a__b++json`
1391
1454
  */
1392
1455
  declare function encodeMetaPath(filePath: string): string;
1393
- /** Read `.meta/group.json`. */
1456
+ /** Read `.meta/group.json`. `updatedAt` is deprecated and ignored on read. */
1394
1457
  declare function readGroupDescriptor(fs: MetaFS): Promise<GroupDescriptor | null>;
1395
- /** Write `.meta/group.json` (idempotent). */
1458
+ /**
1459
+ * Write `.meta/group.json`.
1460
+ *
1461
+ * 幂等:内容与磁盘现有内容字节相同则不写。`updatedAt` 是 deprecated 字段,
1462
+ * 不再写入(写进随同步走的内容会形成「写 → 内容变 → 触发同步 → 对端再写」
1463
+ * 的无限回环)。
1464
+ */
1396
1465
  declare function writeGroupDescriptor(fs: MetaFS, descriptor: GroupDescriptor): Promise<void>;
1397
1466
  interface TombstoneTarget {
1398
1467
  id: string;
package/dist/index.d.ts CHANGED
@@ -385,18 +385,33 @@ interface SyncGroupFeatures {
385
385
  }
386
386
  /** Content of `.meta/group.json` — the unified group descriptor. */
387
387
  interface GroupDescriptor {
388
- schemaVersion: 1;
388
+ /**
389
+ * 2 = 规范化序列化 + 不再写 `updatedAt`。读取时 1 与 2 一视同仁;
390
+ * 1 的老文件会在下一次内容变化时被就地升级。
391
+ */
392
+ schemaVersion: 1 | 2;
389
393
  kind: SyncGroupKind;
390
394
  /** Group id (`config` for the config-sync group, the descriptor id otherwise). */
391
395
  id?: string;
392
396
  /** User-editable display name. */
393
397
  name?: string;
394
398
  features?: Partial<SyncGroupFeatures>;
399
+ /**
400
+ * @deprecated 不再写入、读取侧忽略。时间戳写进随同步走的内容会形成
401
+ * 「写 → 内容变 → 触发同步 → 对端再写」的无限回环,只允许放在本地存储。
402
+ */
395
403
  updatedAt?: number;
396
404
  }
397
405
  /**
398
- * Common handle shared by config-sync and data-sync groups.
399
- * The config group is the capability superset (see ConfigSyncGroupHandle).
406
+ * One sync group = a local primary store + zero-or-more remote replicas +
407
+ * the shared `.meta/` metadata area + that group's own backend definitions.
408
+ *
409
+ * 配置组与数据组是**同一基座上的两个能力位**,不是「配置组 ⊃ 数据组」:
410
+ * - 配置组 `configHost = true`:可承载 `.config`(数据组登记、引导副本、
411
+ * `group-type`),整棵 `/` 参与同步;
412
+ * - 数据组 `appData = true`:可被登记为数据组,同步时排除 `/.config`、
413
+ * `/nodes`、`/shared`。
414
+ * 两个能力位互不蕴含。
400
415
  */
401
416
  interface SyncGroupHandle {
402
417
  readonly groupId: string;
@@ -414,6 +429,14 @@ interface SyncGroupHandle {
414
429
  addBackend(id: string, type: string, options: Record<string, unknown>, description?: string): Promise<void>;
415
430
  removeBackend(id: string): Promise<void>;
416
431
  listBackends(): AppDataBackendDescriptor[];
432
+ /**
433
+ * 该组**声明**的后端列表(权威定义,允许尚未连接成功的条目)。
434
+ *
435
+ * 数据组读自自己的 `.meta/backends/`;配置组读自 `.config/backends/`。
436
+ * 与 `listBackends()`(已连接视图)不同,这个列表不会因为后端暂时不可达
437
+ * 而少显示条目。
438
+ */
439
+ listDeclaredBackends(): AppDataBackendDescriptor[];
417
440
  /** Update the display name only (descriptor-only). */
418
441
  rename(name: string): Promise<void>;
419
442
  /** Write a tombstone, delete the file + version record, trigger sync. */
@@ -1075,8 +1098,20 @@ declare class ConfigRepo implements IConfigRepo {
1075
1098
  * (they have no sync pair, so they never show up in getSyncStatuses()).
1076
1099
  */
1077
1100
  getBackendSyncStates(): Map<string, BackendSyncState>;
1101
+ /**
1102
+ * Mirror per-pair `sync:error` into `getBackendSyncStates()`.
1103
+ *
1104
+ * `SyncEngine.syncAll()` catches per-pair exceptions and substitutes an empty
1105
+ * result, so a failed replica otherwise only shows up as a missing
1106
+ * `lastResult`. Recording the real error lets callers report the actual
1107
+ * status (401/403/404/timeout) instead of guessing "remote unreachable or
1108
+ * invalid credentials".
1109
+ */
1110
+ private trackSyncErrors;
1078
1111
  /** Registered replica backend descriptors (excludes the implicit local primary). */
1079
1112
  listBackends(): AppDataBackendDescriptor[];
1113
+ /** 配置组的权威后端列表(`.config/backends/`),与 `listBackends()` 相同。 */
1114
+ listDeclaredBackends(): AppDataBackendDescriptor[];
1080
1115
  /** Update the config-sync group's display name only. */
1081
1116
  rename(name: string): Promise<void>;
1082
1117
  resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
@@ -1097,6 +1132,8 @@ declare class ConfigRepo implements IConfigRepo {
1097
1132
  private walkDir;
1098
1133
  writeMetaFile(path: string, data: unknown): Promise<void>;
1099
1134
  readMetaFile<T>(path: string): Promise<T | null>;
1135
+ /** Read a text file; `null` when absent (used for byte-compare-then-write). */
1136
+ private readTextIfExists;
1100
1137
  /** Path for a single backend descriptor: .config/backends/{id}.json */
1101
1138
  backendFilePath(id: string): string;
1102
1139
  /** Legacy path: .meta/backends/{id}.json (read + dual-write for one cycle). */
@@ -1116,6 +1153,9 @@ declare class ConfigRepo implements IConfigRepo {
1116
1153
  * Write a single backend descriptor to `.config/backends/{id}.json`,
1117
1154
  * mirroring to the legacy `.meta/backends/{id}.json` for one release cycle
1118
1155
  * so older clients still see the backend.
1156
+ *
1157
+ * Both files use the canonical serializer and are only written when their
1158
+ * bytes actually differ (no needless sync churn).
1119
1159
  */
1120
1160
  writeBackendDescriptor(desc: BackendDescriptor): Promise<void>;
1121
1161
  /** Remove a single backend descriptor file + its version sidecar (both layouts) */
@@ -1149,7 +1189,16 @@ declare class ConfigRepo implements IConfigRepo {
1149
1189
  private appDataGroupFilePath;
1150
1190
  /** Legacy descriptor path: .meta/app-data-groups/{appId}/{id}.json */
1151
1191
  private legacyAppDataGroupFilePath;
1152
- /** Write a data-group descriptor to the new path, mirroring to the legacy one. */
1192
+ /**
1193
+ * Write a data-group descriptor to `.config/` (bootstrap copy), mirroring to
1194
+ * the legacy `.meta/` path.
1195
+ *
1196
+ * 这份描述符是**引导副本**:它让只有配置组凭据的新设备知道有哪些数据组、
1197
+ * 远端在哪。权威定义在数据组自己的 `.meta/backends/`。
1198
+ *
1199
+ * 幂等:按规范化字节比较,相同则不写;`createdAt` 与磁盘现值取 `min`,
1200
+ * 因此时间戳差异不会让两台设备互相覆盖。
1201
+ */
1153
1202
  private writeAppDataGroupDescriptorFile;
1154
1203
  /**
1155
1204
  * Resolve a backend descriptor's options by merging account fields
@@ -1167,11 +1216,18 @@ declare class ConfigRepo implements IConfigRepo {
1167
1216
  features?: Partial<SyncGroupFeatures>;
1168
1217
  }): Promise<AppDataGroup>;
1169
1218
  /**
1170
- * Rewrite an app data group's descriptor (e.g. after addBackend/removeBackend)
1171
- * into .meta/app-data-groups/{appId}/{id}.json, keeping config-sync as the
1172
- * authoritative source of the data group's backend topology (FR2.3).
1219
+ * Rewrite an app data group's **bootstrap copy** at
1220
+ * `.config/app-data-groups/{appId}/{id}.json` (plus the legacy `.meta/`
1221
+ * mirror). The authoritative backend list lives in the data group's own
1222
+ * `.meta/backends/`; this file only lets a new device that has nothing but
1223
+ * the config group's credentials discover the data groups and their remotes.
1224
+ *
1225
+ * 幂等:投影字节相同则不写(见 `writeAppDataGroupDescriptorFile`)。
1173
1226
  */
1174
- updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[]): Promise<void>;
1227
+ updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[], meta?: {
1228
+ name?: string;
1229
+ features?: Partial<SyncGroupFeatures>;
1230
+ }): Promise<void>;
1175
1231
  /**
1176
1232
  * Change a data-sync group's display name only. `id`, backends, local stores
1177
1233
  * and remote data are untouched, so existing sync pairs keep working.
@@ -1240,6 +1296,13 @@ declare function isBrowserEnv(): boolean;
1240
1296
  interface LocalPrimaryOptions {
1241
1297
  idbStoreName?: string;
1242
1298
  folderPath?: string;
1299
+ /**
1300
+ * Data groups only: non-default groups live in an isolated directory
1301
+ * (`<base>/data/{appId}/{groupId}`) so two groups never share files.
1302
+ * `default` keeps the legacy `<base>/data/{appId}` path (lazy migration:
1303
+ * existing files are neither moved nor deleted).
1304
+ */
1305
+ groupId?: string;
1243
1306
  }
1244
1307
  /**
1245
1308
  * Resolve the local primary backend descriptor for the current environment.
@@ -1390,9 +1453,15 @@ type MetaFS = {
1390
1453
  * `/a/b.json` → `a__b++json`
1391
1454
  */
1392
1455
  declare function encodeMetaPath(filePath: string): string;
1393
- /** Read `.meta/group.json`. */
1456
+ /** Read `.meta/group.json`. `updatedAt` is deprecated and ignored on read. */
1394
1457
  declare function readGroupDescriptor(fs: MetaFS): Promise<GroupDescriptor | null>;
1395
- /** Write `.meta/group.json` (idempotent). */
1458
+ /**
1459
+ * Write `.meta/group.json`.
1460
+ *
1461
+ * 幂等:内容与磁盘现有内容字节相同则不写。`updatedAt` 是 deprecated 字段,
1462
+ * 不再写入(写进随同步走的内容会形成「写 → 内容变 → 触发同步 → 对端再写」
1463
+ * 的无限回环)。
1464
+ */
1396
1465
  declare function writeGroupDescriptor(fs: MetaFS, descriptor: GroupDescriptor): Promise<void>;
1397
1466
  interface TombstoneTarget {
1398
1467
  id: string;