zen-fs-config 0.5.50 → 0.6.0
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 +69 -10
- package/dist/index.d.ts +69 -10
- package/dist/index.js +409 -61
- package/dist/index.mjs +409 -61
- package/dist/zen-fs-config.js +409 -61
- package/package.json +1 -1
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
|
-
|
|
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
|
-
*
|
|
399
|
-
*
|
|
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. */
|
|
@@ -1077,6 +1100,8 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1077
1100
|
getBackendSyncStates(): Map<string, BackendSyncState>;
|
|
1078
1101
|
/** Registered replica backend descriptors (excludes the implicit local primary). */
|
|
1079
1102
|
listBackends(): AppDataBackendDescriptor[];
|
|
1103
|
+
/** 配置组的权威后端列表(`.config/backends/`),与 `listBackends()` 相同。 */
|
|
1104
|
+
listDeclaredBackends(): AppDataBackendDescriptor[];
|
|
1080
1105
|
/** Update the config-sync group's display name only. */
|
|
1081
1106
|
rename(name: string): Promise<void>;
|
|
1082
1107
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
@@ -1097,6 +1122,8 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1097
1122
|
private walkDir;
|
|
1098
1123
|
writeMetaFile(path: string, data: unknown): Promise<void>;
|
|
1099
1124
|
readMetaFile<T>(path: string): Promise<T | null>;
|
|
1125
|
+
/** Read a text file; `null` when absent (used for byte-compare-then-write). */
|
|
1126
|
+
private readTextIfExists;
|
|
1100
1127
|
/** Path for a single backend descriptor: .config/backends/{id}.json */
|
|
1101
1128
|
backendFilePath(id: string): string;
|
|
1102
1129
|
/** Legacy path: .meta/backends/{id}.json (read + dual-write for one cycle). */
|
|
@@ -1116,6 +1143,9 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1116
1143
|
* Write a single backend descriptor to `.config/backends/{id}.json`,
|
|
1117
1144
|
* mirroring to the legacy `.meta/backends/{id}.json` for one release cycle
|
|
1118
1145
|
* so older clients still see the backend.
|
|
1146
|
+
*
|
|
1147
|
+
* Both files use the canonical serializer and are only written when their
|
|
1148
|
+
* bytes actually differ (no needless sync churn).
|
|
1119
1149
|
*/
|
|
1120
1150
|
writeBackendDescriptor(desc: BackendDescriptor): Promise<void>;
|
|
1121
1151
|
/** Remove a single backend descriptor file + its version sidecar (both layouts) */
|
|
@@ -1149,7 +1179,16 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1149
1179
|
private appDataGroupFilePath;
|
|
1150
1180
|
/** Legacy descriptor path: .meta/app-data-groups/{appId}/{id}.json */
|
|
1151
1181
|
private legacyAppDataGroupFilePath;
|
|
1152
|
-
/**
|
|
1182
|
+
/**
|
|
1183
|
+
* Write a data-group descriptor to `.config/` (bootstrap copy), mirroring to
|
|
1184
|
+
* the legacy `.meta/` path.
|
|
1185
|
+
*
|
|
1186
|
+
* 这份描述符是**引导副本**:它让只有配置组凭据的新设备知道有哪些数据组、
|
|
1187
|
+
* 远端在哪。权威定义在数据组自己的 `.meta/backends/`。
|
|
1188
|
+
*
|
|
1189
|
+
* 幂等:按规范化字节比较,相同则不写;`createdAt` 与磁盘现值取 `min`,
|
|
1190
|
+
* 因此时间戳差异不会让两台设备互相覆盖。
|
|
1191
|
+
*/
|
|
1153
1192
|
private writeAppDataGroupDescriptorFile;
|
|
1154
1193
|
/**
|
|
1155
1194
|
* Resolve a backend descriptor's options by merging account fields
|
|
@@ -1167,11 +1206,18 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1167
1206
|
features?: Partial<SyncGroupFeatures>;
|
|
1168
1207
|
}): Promise<AppDataGroup>;
|
|
1169
1208
|
/**
|
|
1170
|
-
* Rewrite an app data group's
|
|
1171
|
-
*
|
|
1172
|
-
* authoritative
|
|
1209
|
+
* Rewrite an app data group's **bootstrap copy** at
|
|
1210
|
+
* `.config/app-data-groups/{appId}/{id}.json` (plus the legacy `.meta/`
|
|
1211
|
+
* mirror). The authoritative backend list lives in the data group's own
|
|
1212
|
+
* `.meta/backends/`; this file only lets a new device that has nothing but
|
|
1213
|
+
* the config group's credentials discover the data groups and their remotes.
|
|
1214
|
+
*
|
|
1215
|
+
* 幂等:投影字节相同则不写(见 `writeAppDataGroupDescriptorFile`)。
|
|
1173
1216
|
*/
|
|
1174
|
-
updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[]
|
|
1217
|
+
updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[], meta?: {
|
|
1218
|
+
name?: string;
|
|
1219
|
+
features?: Partial<SyncGroupFeatures>;
|
|
1220
|
+
}): Promise<void>;
|
|
1175
1221
|
/**
|
|
1176
1222
|
* Change a data-sync group's display name only. `id`, backends, local stores
|
|
1177
1223
|
* and remote data are untouched, so existing sync pairs keep working.
|
|
@@ -1240,6 +1286,13 @@ declare function isBrowserEnv(): boolean;
|
|
|
1240
1286
|
interface LocalPrimaryOptions {
|
|
1241
1287
|
idbStoreName?: string;
|
|
1242
1288
|
folderPath?: string;
|
|
1289
|
+
/**
|
|
1290
|
+
* Data groups only: non-default groups live in an isolated directory
|
|
1291
|
+
* (`<base>/data/{appId}/{groupId}`) so two groups never share files.
|
|
1292
|
+
* `default` keeps the legacy `<base>/data/{appId}` path (lazy migration:
|
|
1293
|
+
* existing files are neither moved nor deleted).
|
|
1294
|
+
*/
|
|
1295
|
+
groupId?: string;
|
|
1243
1296
|
}
|
|
1244
1297
|
/**
|
|
1245
1298
|
* Resolve the local primary backend descriptor for the current environment.
|
|
@@ -1390,9 +1443,15 @@ type MetaFS = {
|
|
|
1390
1443
|
* `/a/b.json` → `a__b++json`
|
|
1391
1444
|
*/
|
|
1392
1445
|
declare function encodeMetaPath(filePath: string): string;
|
|
1393
|
-
/** Read `.meta/group.json`. */
|
|
1446
|
+
/** Read `.meta/group.json`. `updatedAt` is deprecated and ignored on read. */
|
|
1394
1447
|
declare function readGroupDescriptor(fs: MetaFS): Promise<GroupDescriptor | null>;
|
|
1395
|
-
/**
|
|
1448
|
+
/**
|
|
1449
|
+
* Write `.meta/group.json`.
|
|
1450
|
+
*
|
|
1451
|
+
* 幂等:内容与磁盘现有内容字节相同则不写。`updatedAt` 是 deprecated 字段,
|
|
1452
|
+
* 不再写入(写进随同步走的内容会形成「写 → 内容变 → 触发同步 → 对端再写」
|
|
1453
|
+
* 的无限回环)。
|
|
1454
|
+
*/
|
|
1396
1455
|
declare function writeGroupDescriptor(fs: MetaFS, descriptor: GroupDescriptor): Promise<void>;
|
|
1397
1456
|
interface TombstoneTarget {
|
|
1398
1457
|
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
|
-
|
|
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
|
-
*
|
|
399
|
-
*
|
|
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. */
|
|
@@ -1077,6 +1100,8 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1077
1100
|
getBackendSyncStates(): Map<string, BackendSyncState>;
|
|
1078
1101
|
/** Registered replica backend descriptors (excludes the implicit local primary). */
|
|
1079
1102
|
listBackends(): AppDataBackendDescriptor[];
|
|
1103
|
+
/** 配置组的权威后端列表(`.config/backends/`),与 `listBackends()` 相同。 */
|
|
1104
|
+
listDeclaredBackends(): AppDataBackendDescriptor[];
|
|
1080
1105
|
/** Update the config-sync group's display name only. */
|
|
1081
1106
|
rename(name: string): Promise<void>;
|
|
1082
1107
|
resolveConflict(conflictId: string, mergedContent: unknown): Promise<void>;
|
|
@@ -1097,6 +1122,8 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1097
1122
|
private walkDir;
|
|
1098
1123
|
writeMetaFile(path: string, data: unknown): Promise<void>;
|
|
1099
1124
|
readMetaFile<T>(path: string): Promise<T | null>;
|
|
1125
|
+
/** Read a text file; `null` when absent (used for byte-compare-then-write). */
|
|
1126
|
+
private readTextIfExists;
|
|
1100
1127
|
/** Path for a single backend descriptor: .config/backends/{id}.json */
|
|
1101
1128
|
backendFilePath(id: string): string;
|
|
1102
1129
|
/** Legacy path: .meta/backends/{id}.json (read + dual-write for one cycle). */
|
|
@@ -1116,6 +1143,9 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1116
1143
|
* Write a single backend descriptor to `.config/backends/{id}.json`,
|
|
1117
1144
|
* mirroring to the legacy `.meta/backends/{id}.json` for one release cycle
|
|
1118
1145
|
* so older clients still see the backend.
|
|
1146
|
+
*
|
|
1147
|
+
* Both files use the canonical serializer and are only written when their
|
|
1148
|
+
* bytes actually differ (no needless sync churn).
|
|
1119
1149
|
*/
|
|
1120
1150
|
writeBackendDescriptor(desc: BackendDescriptor): Promise<void>;
|
|
1121
1151
|
/** Remove a single backend descriptor file + its version sidecar (both layouts) */
|
|
@@ -1149,7 +1179,16 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1149
1179
|
private appDataGroupFilePath;
|
|
1150
1180
|
/** Legacy descriptor path: .meta/app-data-groups/{appId}/{id}.json */
|
|
1151
1181
|
private legacyAppDataGroupFilePath;
|
|
1152
|
-
/**
|
|
1182
|
+
/**
|
|
1183
|
+
* Write a data-group descriptor to `.config/` (bootstrap copy), mirroring to
|
|
1184
|
+
* the legacy `.meta/` path.
|
|
1185
|
+
*
|
|
1186
|
+
* 这份描述符是**引导副本**:它让只有配置组凭据的新设备知道有哪些数据组、
|
|
1187
|
+
* 远端在哪。权威定义在数据组自己的 `.meta/backends/`。
|
|
1188
|
+
*
|
|
1189
|
+
* 幂等:按规范化字节比较,相同则不写;`createdAt` 与磁盘现值取 `min`,
|
|
1190
|
+
* 因此时间戳差异不会让两台设备互相覆盖。
|
|
1191
|
+
*/
|
|
1153
1192
|
private writeAppDataGroupDescriptorFile;
|
|
1154
1193
|
/**
|
|
1155
1194
|
* Resolve a backend descriptor's options by merging account fields
|
|
@@ -1167,11 +1206,18 @@ declare class ConfigRepo implements IConfigRepo {
|
|
|
1167
1206
|
features?: Partial<SyncGroupFeatures>;
|
|
1168
1207
|
}): Promise<AppDataGroup>;
|
|
1169
1208
|
/**
|
|
1170
|
-
* Rewrite an app data group's
|
|
1171
|
-
*
|
|
1172
|
-
* authoritative
|
|
1209
|
+
* Rewrite an app data group's **bootstrap copy** at
|
|
1210
|
+
* `.config/app-data-groups/{appId}/{id}.json` (plus the legacy `.meta/`
|
|
1211
|
+
* mirror). The authoritative backend list lives in the data group's own
|
|
1212
|
+
* `.meta/backends/`; this file only lets a new device that has nothing but
|
|
1213
|
+
* the config group's credentials discover the data groups and their remotes.
|
|
1214
|
+
*
|
|
1215
|
+
* 幂等:投影字节相同则不写(见 `writeAppDataGroupDescriptorFile`)。
|
|
1173
1216
|
*/
|
|
1174
|
-
updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[]
|
|
1217
|
+
updateAppDataGroupDescriptor(id: string, backends: AppDataBackendDescriptor[], meta?: {
|
|
1218
|
+
name?: string;
|
|
1219
|
+
features?: Partial<SyncGroupFeatures>;
|
|
1220
|
+
}): Promise<void>;
|
|
1175
1221
|
/**
|
|
1176
1222
|
* Change a data-sync group's display name only. `id`, backends, local stores
|
|
1177
1223
|
* and remote data are untouched, so existing sync pairs keep working.
|
|
@@ -1240,6 +1286,13 @@ declare function isBrowserEnv(): boolean;
|
|
|
1240
1286
|
interface LocalPrimaryOptions {
|
|
1241
1287
|
idbStoreName?: string;
|
|
1242
1288
|
folderPath?: string;
|
|
1289
|
+
/**
|
|
1290
|
+
* Data groups only: non-default groups live in an isolated directory
|
|
1291
|
+
* (`<base>/data/{appId}/{groupId}`) so two groups never share files.
|
|
1292
|
+
* `default` keeps the legacy `<base>/data/{appId}` path (lazy migration:
|
|
1293
|
+
* existing files are neither moved nor deleted).
|
|
1294
|
+
*/
|
|
1295
|
+
groupId?: string;
|
|
1243
1296
|
}
|
|
1244
1297
|
/**
|
|
1245
1298
|
* Resolve the local primary backend descriptor for the current environment.
|
|
@@ -1390,9 +1443,15 @@ type MetaFS = {
|
|
|
1390
1443
|
* `/a/b.json` → `a__b++json`
|
|
1391
1444
|
*/
|
|
1392
1445
|
declare function encodeMetaPath(filePath: string): string;
|
|
1393
|
-
/** Read `.meta/group.json`. */
|
|
1446
|
+
/** Read `.meta/group.json`. `updatedAt` is deprecated and ignored on read. */
|
|
1394
1447
|
declare function readGroupDescriptor(fs: MetaFS): Promise<GroupDescriptor | null>;
|
|
1395
|
-
/**
|
|
1448
|
+
/**
|
|
1449
|
+
* Write `.meta/group.json`.
|
|
1450
|
+
*
|
|
1451
|
+
* 幂等:内容与磁盘现有内容字节相同则不写。`updatedAt` 是 deprecated 字段,
|
|
1452
|
+
* 不再写入(写进随同步走的内容会形成「写 → 内容变 → 触发同步 → 对端再写」
|
|
1453
|
+
* 的无限回环)。
|
|
1454
|
+
*/
|
|
1396
1455
|
declare function writeGroupDescriptor(fs: MetaFS, descriptor: GroupDescriptor): Promise<void>;
|
|
1397
1456
|
interface TombstoneTarget {
|
|
1398
1457
|
id: string;
|