zen-fs-config 0.9.2 → 0.9.3

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
@@ -1286,6 +1286,14 @@ declare class ConfigRepo implements IConfigRepo {
1286
1286
  private backendConflicts;
1287
1287
  /** Last known backend descriptors, for the synchronous unified handle API. */
1288
1288
  private backendDescriptorCache;
1289
+ /**
1290
+ * 本会话内被用户**显式**清空后端的数据组 id。
1291
+ *
1292
+ * 只有这类组允许把「0 个后端」的引导副本推给远端;启动时读到的空副本
1293
+ * (历史脏数据、或「清空本页配置」后本地新建的空组)绝不覆盖远端既有拓扑,
1294
+ * 见 `healEmptyBootstrapDescriptors()`。
1295
+ */
1296
+ private explicitEmptyDescriptors;
1289
1297
  /**
1290
1298
  * Tracks the background initial sync started by createConfigRepo().
1291
1299
  * `flush()` and `dispose()` will await this if it hasn't completed yet,
@@ -1761,6 +1769,18 @@ declare class ConfigRepo implements IConfigRepo {
1761
1769
  */
1762
1770
  private syncBootstrapDescriptor;
1763
1771
  listAppDataGroups(): Promise<AppDataGroupDescriptor[]>;
1772
+ /**
1773
+ * 「引导副本只升不降」:本地 `.config/app-data-groups/{appId}/{id}.json` 若声明
1774
+ * **0 个后端**,而任何副本上同一路径还带着非空后端列表,就采用远端那份。
1775
+ *
1776
+ * 为什么必须做:本页「清除同步组配置」后本地库被重建,应用会先建一个只有隐式
1777
+ * 本地存储的空 default 组并写下 `backends: []`;配置组后端一接上,首轮双向同步
1778
+ * 以本地为准,这份空副本就会把远端登记的真实拓扑抹平(2026-11-24 线上实际发生)。
1779
+ *
1780
+ * 例外:本会话内用户显式清空后端(`updateAppDataGroupDescriptor(id, [])`)是
1781
+ * 真实意图,允许推送空副本,不参与自愈。
1782
+ */
1783
+ private healEmptyBootstrapDescriptors;
1764
1784
  removeAppDataGroup(id: string): Promise<void>;
1765
1785
  listAccountBackends(): Promise<BackendDescriptor[]>;
1766
1786
  private tryParse;
package/dist/index.d.ts CHANGED
@@ -1286,6 +1286,14 @@ declare class ConfigRepo implements IConfigRepo {
1286
1286
  private backendConflicts;
1287
1287
  /** Last known backend descriptors, for the synchronous unified handle API. */
1288
1288
  private backendDescriptorCache;
1289
+ /**
1290
+ * 本会话内被用户**显式**清空后端的数据组 id。
1291
+ *
1292
+ * 只有这类组允许把「0 个后端」的引导副本推给远端;启动时读到的空副本
1293
+ * (历史脏数据、或「清空本页配置」后本地新建的空组)绝不覆盖远端既有拓扑,
1294
+ * 见 `healEmptyBootstrapDescriptors()`。
1295
+ */
1296
+ private explicitEmptyDescriptors;
1289
1297
  /**
1290
1298
  * Tracks the background initial sync started by createConfigRepo().
1291
1299
  * `flush()` and `dispose()` will await this if it hasn't completed yet,
@@ -1761,6 +1769,18 @@ declare class ConfigRepo implements IConfigRepo {
1761
1769
  */
1762
1770
  private syncBootstrapDescriptor;
1763
1771
  listAppDataGroups(): Promise<AppDataGroupDescriptor[]>;
1772
+ /**
1773
+ * 「引导副本只升不降」:本地 `.config/app-data-groups/{appId}/{id}.json` 若声明
1774
+ * **0 个后端**,而任何副本上同一路径还带着非空后端列表,就采用远端那份。
1775
+ *
1776
+ * 为什么必须做:本页「清除同步组配置」后本地库被重建,应用会先建一个只有隐式
1777
+ * 本地存储的空 default 组并写下 `backends: []`;配置组后端一接上,首轮双向同步
1778
+ * 以本地为准,这份空副本就会把远端登记的真实拓扑抹平(2026-11-24 线上实际发生)。
1779
+ *
1780
+ * 例外:本会话内用户显式清空后端(`updateAppDataGroupDescriptor(id, [])`)是
1781
+ * 真实意图,允许推送空副本,不参与自愈。
1782
+ */
1783
+ private healEmptyBootstrapDescriptors;
1764
1784
  removeAppDataGroup(id: string): Promise<void>;
1765
1785
  listAccountBackends(): Promise<BackendDescriptor[]>;
1766
1786
  private tryParse;
package/dist/index.js CHANGED
@@ -3140,6 +3140,14 @@ var ConfigRepo = class _ConfigRepo {
3140
3140
  backendConflicts = /* @__PURE__ */ new Map();
3141
3141
  /** Last known backend descriptors, for the synchronous unified handle API. */
3142
3142
  backendDescriptorCache = [];
3143
+ /**
3144
+ * 本会话内被用户**显式**清空后端的数据组 id。
3145
+ *
3146
+ * 只有这类组允许把「0 个后端」的引导副本推给远端;启动时读到的空副本
3147
+ * (历史脏数据、或「清空本页配置」后本地新建的空组)绝不覆盖远端既有拓扑,
3148
+ * 见 `healEmptyBootstrapDescriptors()`。
3149
+ */
3150
+ explicitEmptyDescriptors = /* @__PURE__ */ new Set();
3143
3151
  /**
3144
3152
  * Tracks the background initial sync started by createConfigRepo().
3145
3153
  * `flush()` and `dispose()` will await this if it hasn't completed yet,
@@ -3319,6 +3327,7 @@ var ConfigRepo = class _ConfigRepo {
3319
3327
  this.initialSyncPromise = null;
3320
3328
  }
3321
3329
  await this.processTombstones();
3330
+ await this.healEmptyBootstrapDescriptors();
3322
3331
  const resultsMap = await this.syncEngine.syncAll();
3323
3332
  this.invalidateTombstoneCache();
3324
3333
  await this.readAllBackendDescriptors();
@@ -3826,6 +3835,7 @@ var ConfigRepo = class _ConfigRepo {
3826
3835
  */
3827
3836
  async initialSyncAndDedup() {
3828
3837
  this.syncEngine.unwatchAll();
3838
+ await this.healEmptyBootstrapDescriptors();
3829
3839
  await this.syncEngine.syncAll();
3830
3840
  await this.readAllBackendDescriptors();
3831
3841
  await this.processTombstones();
@@ -5486,6 +5496,8 @@ var ConfigRepo = class _ConfigRepo {
5486
5496
  ...features ? { features } : {},
5487
5497
  backends
5488
5498
  };
5499
+ if (backends.length === 0) this.explicitEmptyDescriptors.add(id);
5500
+ else this.explicitEmptyDescriptors.delete(id);
5489
5501
  await this.writeAppDataGroupDescriptorFile(id, descriptor);
5490
5502
  this.scheduleDescriptorPush();
5491
5503
  }
@@ -5734,6 +5746,59 @@ var ConfigRepo = class _ConfigRepo {
5734
5746
  }
5735
5747
  return Array.from(byId.values());
5736
5748
  }
5749
+ /**
5750
+ * 「引导副本只升不降」:本地 `.config/app-data-groups/{appId}/{id}.json` 若声明
5751
+ * **0 个后端**,而任何副本上同一路径还带着非空后端列表,就采用远端那份。
5752
+ *
5753
+ * 为什么必须做:本页「清除同步组配置」后本地库被重建,应用会先建一个只有隐式
5754
+ * 本地存储的空 default 组并写下 `backends: []`;配置组后端一接上,首轮双向同步
5755
+ * 以本地为准,这份空副本就会把远端登记的真实拓扑抹平(2026-11-24 线上实际发生)。
5756
+ *
5757
+ * 例外:本会话内用户显式清空后端(`updateAppDataGroupDescriptor(id, [])`)是
5758
+ * 真实意图,允许推送空副本,不参与自愈。
5759
+ */
5760
+ async healEmptyBootstrapDescriptors() {
5761
+ if (this.replicaBackends.size === 0) return;
5762
+ let localDescriptors;
5763
+ try {
5764
+ localDescriptors = await this.listAppDataGroups();
5765
+ } catch {
5766
+ return;
5767
+ }
5768
+ for (const descriptor of localDescriptors) {
5769
+ if ((descriptor.backends?.length ?? 0) > 0) continue;
5770
+ if (this.explicitEmptyDescriptors.has(descriptor.id)) continue;
5771
+ const descPath = this.appDataGroupFilePath(descriptor.id);
5772
+ for (const [replicaId, replica] of this.replicaBackends) {
5773
+ let remote;
5774
+ try {
5775
+ const raw = await withTimeout(
5776
+ replica.instance.readFile(descPath),
5777
+ REPLICA_SETUP_TIMEOUT_MS,
5778
+ `${replicaId} \u8BFB\u53D6\u5F15\u5BFC\u526F\u672C`
5779
+ );
5780
+ remote = JSON.parse(new TextDecoder().decode(toUint8Array2(raw)));
5781
+ } catch {
5782
+ continue;
5783
+ }
5784
+ if (!remote || remote.id !== descriptor.id || remote.groupType !== "data-sync") continue;
5785
+ const remoteBackends = Array.isArray(remote.backends) ? remote.backends : [];
5786
+ if (remoteBackends.length === 0) continue;
5787
+ await this.writeAppDataGroupDescriptorFile(descriptor.id, {
5788
+ id: descriptor.id,
5789
+ groupType: "data-sync",
5790
+ ...remote.instanceId ? { instanceId: remote.instanceId } : {},
5791
+ ...remote.name ? { name: remote.name } : {},
5792
+ ...remote.features ? { features: remote.features } : {},
5793
+ backends: remoteBackends
5794
+ });
5795
+ log5.warn(
5796
+ `[ConfigRepo] ${descriptor.id}: \u672C\u5730\u5F15\u5BFC\u526F\u672C\u4E3A\u7A7A\uFF0C\u91C7\u7528\u8FDC\u7AEF\u62D3\u6251\uFF08${remoteBackends.length} \u4E2A\u540E\u7AEF\uFF09\uFF0C\u907F\u514D\u8986\u76D6\u8FDC\u7AEF\u8BBE\u7F6E`
5797
+ );
5798
+ break;
5799
+ }
5800
+ }
5801
+ }
5737
5802
  async removeAppDataGroup(id) {
5738
5803
  this.assertNotDisposed();
5739
5804
  const group = this.appDataGroups.get(id);
package/dist/index.mjs CHANGED
@@ -2375,6 +2375,14 @@ var ConfigRepo = class _ConfigRepo {
2375
2375
  backendConflicts = /* @__PURE__ */ new Map();
2376
2376
  /** Last known backend descriptors, for the synchronous unified handle API. */
2377
2377
  backendDescriptorCache = [];
2378
+ /**
2379
+ * 本会话内被用户**显式**清空后端的数据组 id。
2380
+ *
2381
+ * 只有这类组允许把「0 个后端」的引导副本推给远端;启动时读到的空副本
2382
+ * (历史脏数据、或「清空本页配置」后本地新建的空组)绝不覆盖远端既有拓扑,
2383
+ * 见 `healEmptyBootstrapDescriptors()`。
2384
+ */
2385
+ explicitEmptyDescriptors = /* @__PURE__ */ new Set();
2378
2386
  /**
2379
2387
  * Tracks the background initial sync started by createConfigRepo().
2380
2388
  * `flush()` and `dispose()` will await this if it hasn't completed yet,
@@ -2554,6 +2562,7 @@ var ConfigRepo = class _ConfigRepo {
2554
2562
  this.initialSyncPromise = null;
2555
2563
  }
2556
2564
  await this.processTombstones();
2565
+ await this.healEmptyBootstrapDescriptors();
2557
2566
  const resultsMap = await this.syncEngine.syncAll();
2558
2567
  this.invalidateTombstoneCache();
2559
2568
  await this.readAllBackendDescriptors();
@@ -3061,6 +3070,7 @@ var ConfigRepo = class _ConfigRepo {
3061
3070
  */
3062
3071
  async initialSyncAndDedup() {
3063
3072
  this.syncEngine.unwatchAll();
3073
+ await this.healEmptyBootstrapDescriptors();
3064
3074
  await this.syncEngine.syncAll();
3065
3075
  await this.readAllBackendDescriptors();
3066
3076
  await this.processTombstones();
@@ -4721,6 +4731,8 @@ var ConfigRepo = class _ConfigRepo {
4721
4731
  ...features ? { features } : {},
4722
4732
  backends
4723
4733
  };
4734
+ if (backends.length === 0) this.explicitEmptyDescriptors.add(id);
4735
+ else this.explicitEmptyDescriptors.delete(id);
4724
4736
  await this.writeAppDataGroupDescriptorFile(id, descriptor);
4725
4737
  this.scheduleDescriptorPush();
4726
4738
  }
@@ -4969,6 +4981,59 @@ var ConfigRepo = class _ConfigRepo {
4969
4981
  }
4970
4982
  return Array.from(byId.values());
4971
4983
  }
4984
+ /**
4985
+ * 「引导副本只升不降」:本地 `.config/app-data-groups/{appId}/{id}.json` 若声明
4986
+ * **0 个后端**,而任何副本上同一路径还带着非空后端列表,就采用远端那份。
4987
+ *
4988
+ * 为什么必须做:本页「清除同步组配置」后本地库被重建,应用会先建一个只有隐式
4989
+ * 本地存储的空 default 组并写下 `backends: []`;配置组后端一接上,首轮双向同步
4990
+ * 以本地为准,这份空副本就会把远端登记的真实拓扑抹平(2026-11-24 线上实际发生)。
4991
+ *
4992
+ * 例外:本会话内用户显式清空后端(`updateAppDataGroupDescriptor(id, [])`)是
4993
+ * 真实意图,允许推送空副本,不参与自愈。
4994
+ */
4995
+ async healEmptyBootstrapDescriptors() {
4996
+ if (this.replicaBackends.size === 0) return;
4997
+ let localDescriptors;
4998
+ try {
4999
+ localDescriptors = await this.listAppDataGroups();
5000
+ } catch {
5001
+ return;
5002
+ }
5003
+ for (const descriptor of localDescriptors) {
5004
+ if ((descriptor.backends?.length ?? 0) > 0) continue;
5005
+ if (this.explicitEmptyDescriptors.has(descriptor.id)) continue;
5006
+ const descPath = this.appDataGroupFilePath(descriptor.id);
5007
+ for (const [replicaId, replica] of this.replicaBackends) {
5008
+ let remote;
5009
+ try {
5010
+ const raw = await withTimeout(
5011
+ replica.instance.readFile(descPath),
5012
+ REPLICA_SETUP_TIMEOUT_MS,
5013
+ `${replicaId} \u8BFB\u53D6\u5F15\u5BFC\u526F\u672C`
5014
+ );
5015
+ remote = JSON.parse(new TextDecoder().decode(toUint8Array2(raw)));
5016
+ } catch {
5017
+ continue;
5018
+ }
5019
+ if (!remote || remote.id !== descriptor.id || remote.groupType !== "data-sync") continue;
5020
+ const remoteBackends = Array.isArray(remote.backends) ? remote.backends : [];
5021
+ if (remoteBackends.length === 0) continue;
5022
+ await this.writeAppDataGroupDescriptorFile(descriptor.id, {
5023
+ id: descriptor.id,
5024
+ groupType: "data-sync",
5025
+ ...remote.instanceId ? { instanceId: remote.instanceId } : {},
5026
+ ...remote.name ? { name: remote.name } : {},
5027
+ ...remote.features ? { features: remote.features } : {},
5028
+ backends: remoteBackends
5029
+ });
5030
+ log5.warn(
5031
+ `[ConfigRepo] ${descriptor.id}: \u672C\u5730\u5F15\u5BFC\u526F\u672C\u4E3A\u7A7A\uFF0C\u91C7\u7528\u8FDC\u7AEF\u62D3\u6251\uFF08${remoteBackends.length} \u4E2A\u540E\u7AEF\uFF09\uFF0C\u907F\u514D\u8986\u76D6\u8FDC\u7AEF\u8BBE\u7F6E`
5032
+ );
5033
+ break;
5034
+ }
5035
+ }
5036
+ }
4972
5037
  async removeAppDataGroup(id) {
4973
5038
  this.assertNotDisposed();
4974
5039
  const group = this.appDataGroups.get(id);
@@ -29080,6 +29080,14 @@ var ZenFSConfig = (() => {
29080
29080
  __publicField(this, "backendConflicts", /* @__PURE__ */ new Map());
29081
29081
  /** Last known backend descriptors, for the synchronous unified handle API. */
29082
29082
  __publicField(this, "backendDescriptorCache", []);
29083
+ /**
29084
+ * 本会话内被用户**显式**清空后端的数据组 id。
29085
+ *
29086
+ * 只有这类组允许把「0 个后端」的引导副本推给远端;启动时读到的空副本
29087
+ * (历史脏数据、或「清空本页配置」后本地新建的空组)绝不覆盖远端既有拓扑,
29088
+ * 见 `healEmptyBootstrapDescriptors()`。
29089
+ */
29090
+ __publicField(this, "explicitEmptyDescriptors", /* @__PURE__ */ new Set());
29083
29091
  /**
29084
29092
  * Tracks the background initial sync started by createConfigRepo().
29085
29093
  * `flush()` and `dispose()` will await this if it hasn't completed yet,
@@ -29268,6 +29276,7 @@ var ZenFSConfig = (() => {
29268
29276
  this.initialSyncPromise = null;
29269
29277
  }
29270
29278
  await this.processTombstones();
29279
+ await this.healEmptyBootstrapDescriptors();
29271
29280
  const resultsMap = await this.syncEngine.syncAll();
29272
29281
  this.invalidateTombstoneCache();
29273
29282
  await this.readAllBackendDescriptors();
@@ -29769,6 +29778,7 @@ var ZenFSConfig = (() => {
29769
29778
  */
29770
29779
  async initialSyncAndDedup() {
29771
29780
  this.syncEngine.unwatchAll();
29781
+ await this.healEmptyBootstrapDescriptors();
29772
29782
  await this.syncEngine.syncAll();
29773
29783
  await this.readAllBackendDescriptors();
29774
29784
  await this.processTombstones();
@@ -31425,6 +31435,8 @@ var ZenFSConfig = (() => {
31425
31435
  ...features ? { features } : {},
31426
31436
  backends
31427
31437
  };
31438
+ if (backends.length === 0) this.explicitEmptyDescriptors.add(id);
31439
+ else this.explicitEmptyDescriptors.delete(id);
31428
31440
  await this.writeAppDataGroupDescriptorFile(id, descriptor);
31429
31441
  this.scheduleDescriptorPush();
31430
31442
  }
@@ -31673,6 +31685,59 @@ var ZenFSConfig = (() => {
31673
31685
  }
31674
31686
  return Array.from(byId.values());
31675
31687
  }
31688
+ /**
31689
+ * 「引导副本只升不降」:本地 `.config/app-data-groups/{appId}/{id}.json` 若声明
31690
+ * **0 个后端**,而任何副本上同一路径还带着非空后端列表,就采用远端那份。
31691
+ *
31692
+ * 为什么必须做:本页「清除同步组配置」后本地库被重建,应用会先建一个只有隐式
31693
+ * 本地存储的空 default 组并写下 `backends: []`;配置组后端一接上,首轮双向同步
31694
+ * 以本地为准,这份空副本就会把远端登记的真实拓扑抹平(2026-11-24 线上实际发生)。
31695
+ *
31696
+ * 例外:本会话内用户显式清空后端(`updateAppDataGroupDescriptor(id, [])`)是
31697
+ * 真实意图,允许推送空副本,不参与自愈。
31698
+ */
31699
+ async healEmptyBootstrapDescriptors() {
31700
+ if (this.replicaBackends.size === 0) return;
31701
+ let localDescriptors;
31702
+ try {
31703
+ localDescriptors = await this.listAppDataGroups();
31704
+ } catch {
31705
+ return;
31706
+ }
31707
+ for (const descriptor of localDescriptors) {
31708
+ if ((descriptor.backends?.length ?? 0) > 0) continue;
31709
+ if (this.explicitEmptyDescriptors.has(descriptor.id)) continue;
31710
+ const descPath = this.appDataGroupFilePath(descriptor.id);
31711
+ for (const [replicaId, replica] of this.replicaBackends) {
31712
+ let remote;
31713
+ try {
31714
+ const raw = await withTimeout(
31715
+ replica.instance.readFile(descPath),
31716
+ REPLICA_SETUP_TIMEOUT_MS,
31717
+ `${replicaId} \u8BFB\u53D6\u5F15\u5BFC\u526F\u672C`
31718
+ );
31719
+ remote = JSON.parse(new TextDecoder().decode(toUint8Array2(raw)));
31720
+ } catch {
31721
+ continue;
31722
+ }
31723
+ if (!remote || remote.id !== descriptor.id || remote.groupType !== "data-sync") continue;
31724
+ const remoteBackends = Array.isArray(remote.backends) ? remote.backends : [];
31725
+ if (remoteBackends.length === 0) continue;
31726
+ await this.writeAppDataGroupDescriptorFile(descriptor.id, {
31727
+ id: descriptor.id,
31728
+ groupType: "data-sync",
31729
+ ...remote.instanceId ? { instanceId: remote.instanceId } : {},
31730
+ ...remote.name ? { name: remote.name } : {},
31731
+ ...remote.features ? { features: remote.features } : {},
31732
+ backends: remoteBackends
31733
+ });
31734
+ log9.warn(
31735
+ `[ConfigRepo] ${descriptor.id}: \u672C\u5730\u5F15\u5BFC\u526F\u672C\u4E3A\u7A7A\uFF0C\u91C7\u7528\u8FDC\u7AEF\u62D3\u6251\uFF08${remoteBackends.length} \u4E2A\u540E\u7AEF\uFF09\uFF0C\u907F\u514D\u8986\u76D6\u8FDC\u7AEF\u8BBE\u7F6E`
31736
+ );
31737
+ break;
31738
+ }
31739
+ }
31740
+ }
31676
31741
  async removeAppDataGroup(id) {
31677
31742
  this.assertNotDisposed();
31678
31743
  const group = this.appDataGroups.get(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Distributed config management library built on ZenFS, zen-fs-cache, and zen-fs-sync",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",