zen-fs-config 0.9.5 → 0.9.6

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
@@ -1247,6 +1247,11 @@ declare class ConfigRepo implements IConfigRepo {
1247
1247
  * 就是这么来的)。这里在同一轮变更后合并触发一次 flush,把描述符立刻推上去。
1248
1248
  */
1249
1249
  private descriptorPushTimer?;
1250
+ /**
1251
+ * 已做过「凭据回填」的端点去重键。同一进程内每个端点只回填一次,
1252
+ * 避免每次建对都重写一遍别人的描述符。
1253
+ */
1254
+ private credentialBackfillDone;
1250
1255
  /** 后台建对(deferReplicaSetup)的状态,见 `whenReplicasReady()`。 */
1251
1256
  private replicaSetupPromise;
1252
1257
  private replicaSetupSummary;
@@ -1606,6 +1611,19 @@ declare class ConfigRepo implements IConfigRepo {
1606
1611
  * (including their version sidecar files).
1607
1612
  */
1608
1613
  readAllBackendDescriptors(): Promise<BackendDescriptor[]>;
1614
+ /**
1615
+ * 把「连得上的凭据」回填到同一端点的重复描述符里。
1616
+ *
1617
+ * 背景:RemoteStorage 的 `token` 不进 `identityFields`(见 admin 的后端注册),
1618
+ * 同一 `href`+`basePath` 只会被当成一个端点;但历史上按 token 判重时,每次
1619
+ * 重新授权都会新增一个 `remotestorage-<时间戳>` 描述符,旧描述符仍留在
1620
+ * `.meta/backends/` 里。读时去重按 mtime 保留最早的一份,如果那份的 token
1621
+ * 已经失效,这个端点就会永远连不上。这里在某个描述符成功建对之后,把它的
1622
+ * token 写回同键的其它描述符,保证「留下的那份」凭据是可用的。
1623
+ *
1624
+ * 只改 token 一个字段,不新增/删除描述符,也不影响 id 与 mtime 之外的内容。
1625
+ */
1626
+ private backfillDuplicateBackendCredentials;
1609
1627
  /**
1610
1628
  * Write a single backend descriptor to `.meta/backends/{id}.json`.
1611
1629
  *
package/dist/index.d.ts CHANGED
@@ -1247,6 +1247,11 @@ declare class ConfigRepo implements IConfigRepo {
1247
1247
  * 就是这么来的)。这里在同一轮变更后合并触发一次 flush,把描述符立刻推上去。
1248
1248
  */
1249
1249
  private descriptorPushTimer?;
1250
+ /**
1251
+ * 已做过「凭据回填」的端点去重键。同一进程内每个端点只回填一次,
1252
+ * 避免每次建对都重写一遍别人的描述符。
1253
+ */
1254
+ private credentialBackfillDone;
1250
1255
  /** 后台建对(deferReplicaSetup)的状态,见 `whenReplicasReady()`。 */
1251
1256
  private replicaSetupPromise;
1252
1257
  private replicaSetupSummary;
@@ -1606,6 +1611,19 @@ declare class ConfigRepo implements IConfigRepo {
1606
1611
  * (including their version sidecar files).
1607
1612
  */
1608
1613
  readAllBackendDescriptors(): Promise<BackendDescriptor[]>;
1614
+ /**
1615
+ * 把「连得上的凭据」回填到同一端点的重复描述符里。
1616
+ *
1617
+ * 背景:RemoteStorage 的 `token` 不进 `identityFields`(见 admin 的后端注册),
1618
+ * 同一 `href`+`basePath` 只会被当成一个端点;但历史上按 token 判重时,每次
1619
+ * 重新授权都会新增一个 `remotestorage-<时间戳>` 描述符,旧描述符仍留在
1620
+ * `.meta/backends/` 里。读时去重按 mtime 保留最早的一份,如果那份的 token
1621
+ * 已经失效,这个端点就会永远连不上。这里在某个描述符成功建对之后,把它的
1622
+ * token 写回同键的其它描述符,保证「留下的那份」凭据是可用的。
1623
+ *
1624
+ * 只改 token 一个字段,不新增/删除描述符,也不影响 id 与 mtime 之外的内容。
1625
+ */
1626
+ private backfillDuplicateBackendCredentials;
1609
1627
  /**
1610
1628
  * Write a single backend descriptor to `.meta/backends/{id}.json`.
1611
1629
  *
package/dist/index.js CHANGED
@@ -3113,6 +3113,11 @@ var ConfigRepo = class _ConfigRepo {
3113
3113
  * 就是这么来的)。这里在同一轮变更后合并触发一次 flush,把描述符立刻推上去。
3114
3114
  */
3115
3115
  descriptorPushTimer;
3116
+ /**
3117
+ * 已做过「凭据回填」的端点去重键。同一进程内每个端点只回填一次,
3118
+ * 避免每次建对都重写一遍别人的描述符。
3119
+ */
3120
+ credentialBackfillDone = /* @__PURE__ */ new Set();
3116
3121
  /** 后台建对(deferReplicaSetup)的状态,见 `whenReplicasReady()`。 */
3117
3122
  replicaSetupPromise = null;
3118
3123
  replicaSetupSummary = null;
@@ -4377,6 +4382,9 @@ var ConfigRepo = class _ConfigRepo {
4377
4382
  );
4378
4383
  this.replicaBackends.set(desc.id, { instance: fsInstance, syncable, pairId: pair.pairId });
4379
4384
  this.backendStates.set(desc.id, { backendId: desc.id, pairId: pair.pairId });
4385
+ void this.backfillDuplicateBackendCredentials(desc).catch((err) => {
4386
+ log5.warn("[ConfigRepo] backfill duplicate backend credentials failed:", err);
4387
+ });
4380
4388
  const conflictHandler = (event) => {
4381
4389
  this.handleConflict(event);
4382
4390
  };
@@ -4721,6 +4729,50 @@ var ConfigRepo = class _ConfigRepo {
4721
4729
  this.backendDescriptorCache = [...result];
4722
4730
  return result;
4723
4731
  }
4732
+ /**
4733
+ * 把「连得上的凭据」回填到同一端点的重复描述符里。
4734
+ *
4735
+ * 背景:RemoteStorage 的 `token` 不进 `identityFields`(见 admin 的后端注册),
4736
+ * 同一 `href`+`basePath` 只会被当成一个端点;但历史上按 token 判重时,每次
4737
+ * 重新授权都会新增一个 `remotestorage-<时间戳>` 描述符,旧描述符仍留在
4738
+ * `.meta/backends/` 里。读时去重按 mtime 保留最早的一份,如果那份的 token
4739
+ * 已经失效,这个端点就会永远连不上。这里在某个描述符成功建对之后,把它的
4740
+ * token 写回同键的其它描述符,保证「留下的那份」凭据是可用的。
4741
+ *
4742
+ * 只改 token 一个字段,不新增/删除描述符,也不影响 id 与 mtime 之外的内容。
4743
+ */
4744
+ async backfillDuplicateBackendCredentials(desc) {
4745
+ const options = desc.options;
4746
+ const mine = options?.token;
4747
+ if (typeof mine !== "string" || mine.length === 0) return;
4748
+ const key = backendDedupKey(desc);
4749
+ if (this.credentialBackfillDone.has(key)) return;
4750
+ this.credentialBackfillDone.add(key);
4751
+ let items;
4752
+ try {
4753
+ items = (await this.readBackendDescriptorsFrom(BACKENDS_DIR)).items;
4754
+ } catch (err) {
4755
+ log5.warn("[ConfigRepo] backfill credentials: read descriptors failed:", err);
4756
+ return;
4757
+ }
4758
+ for (const item of items) {
4759
+ if (item.desc.id === desc.id) continue;
4760
+ if (backendDedupKey(item.desc) !== key) continue;
4761
+ const theirs = item.desc.options?.token;
4762
+ if (typeof theirs !== "string" || theirs === mine) continue;
4763
+ try {
4764
+ await this.writeBackendDescriptor({
4765
+ ...item.desc,
4766
+ options: { ...item.desc.options, token: mine }
4767
+ });
4768
+ log5.log(
4769
+ `[ConfigRepo] backfilled working credential into duplicate descriptor ${item.desc.id} (endpoint ${key})`
4770
+ );
4771
+ } catch (err) {
4772
+ log5.warn(`[ConfigRepo] backfill credentials: write ${item.desc.id} failed:`, err);
4773
+ }
4774
+ }
4775
+ }
4724
4776
  /**
4725
4777
  * Write a single backend descriptor to `.meta/backends/{id}.json`.
4726
4778
  *
package/dist/index.mjs CHANGED
@@ -2325,6 +2325,11 @@ var ConfigRepo = class _ConfigRepo {
2325
2325
  * 就是这么来的)。这里在同一轮变更后合并触发一次 flush,把描述符立刻推上去。
2326
2326
  */
2327
2327
  descriptorPushTimer;
2328
+ /**
2329
+ * 已做过「凭据回填」的端点去重键。同一进程内每个端点只回填一次,
2330
+ * 避免每次建对都重写一遍别人的描述符。
2331
+ */
2332
+ credentialBackfillDone = /* @__PURE__ */ new Set();
2328
2333
  /** 后台建对(deferReplicaSetup)的状态,见 `whenReplicasReady()`。 */
2329
2334
  replicaSetupPromise = null;
2330
2335
  replicaSetupSummary = null;
@@ -3589,6 +3594,9 @@ var ConfigRepo = class _ConfigRepo {
3589
3594
  );
3590
3595
  this.replicaBackends.set(desc.id, { instance: fsInstance, syncable, pairId: pair.pairId });
3591
3596
  this.backendStates.set(desc.id, { backendId: desc.id, pairId: pair.pairId });
3597
+ void this.backfillDuplicateBackendCredentials(desc).catch((err) => {
3598
+ log5.warn("[ConfigRepo] backfill duplicate backend credentials failed:", err);
3599
+ });
3592
3600
  const conflictHandler = (event) => {
3593
3601
  this.handleConflict(event);
3594
3602
  };
@@ -3933,6 +3941,50 @@ var ConfigRepo = class _ConfigRepo {
3933
3941
  this.backendDescriptorCache = [...result];
3934
3942
  return result;
3935
3943
  }
3944
+ /**
3945
+ * 把「连得上的凭据」回填到同一端点的重复描述符里。
3946
+ *
3947
+ * 背景:RemoteStorage 的 `token` 不进 `identityFields`(见 admin 的后端注册),
3948
+ * 同一 `href`+`basePath` 只会被当成一个端点;但历史上按 token 判重时,每次
3949
+ * 重新授权都会新增一个 `remotestorage-<时间戳>` 描述符,旧描述符仍留在
3950
+ * `.meta/backends/` 里。读时去重按 mtime 保留最早的一份,如果那份的 token
3951
+ * 已经失效,这个端点就会永远连不上。这里在某个描述符成功建对之后,把它的
3952
+ * token 写回同键的其它描述符,保证「留下的那份」凭据是可用的。
3953
+ *
3954
+ * 只改 token 一个字段,不新增/删除描述符,也不影响 id 与 mtime 之外的内容。
3955
+ */
3956
+ async backfillDuplicateBackendCredentials(desc) {
3957
+ const options = desc.options;
3958
+ const mine = options?.token;
3959
+ if (typeof mine !== "string" || mine.length === 0) return;
3960
+ const key = backendDedupKey(desc);
3961
+ if (this.credentialBackfillDone.has(key)) return;
3962
+ this.credentialBackfillDone.add(key);
3963
+ let items;
3964
+ try {
3965
+ items = (await this.readBackendDescriptorsFrom(BACKENDS_DIR)).items;
3966
+ } catch (err) {
3967
+ log5.warn("[ConfigRepo] backfill credentials: read descriptors failed:", err);
3968
+ return;
3969
+ }
3970
+ for (const item of items) {
3971
+ if (item.desc.id === desc.id) continue;
3972
+ if (backendDedupKey(item.desc) !== key) continue;
3973
+ const theirs = item.desc.options?.token;
3974
+ if (typeof theirs !== "string" || theirs === mine) continue;
3975
+ try {
3976
+ await this.writeBackendDescriptor({
3977
+ ...item.desc,
3978
+ options: { ...item.desc.options, token: mine }
3979
+ });
3980
+ log5.log(
3981
+ `[ConfigRepo] backfilled working credential into duplicate descriptor ${item.desc.id} (endpoint ${key})`
3982
+ );
3983
+ } catch (err) {
3984
+ log5.warn(`[ConfigRepo] backfill credentials: write ${item.desc.id} failed:`, err);
3985
+ }
3986
+ }
3987
+ }
3936
3988
  /**
3937
3989
  * Write a single backend descriptor to `.meta/backends/{id}.json`.
3938
3990
  *
@@ -29071,6 +29071,11 @@ var ZenFSConfig = (() => {
29071
29071
  * 就是这么来的)。这里在同一轮变更后合并触发一次 flush,把描述符立刻推上去。
29072
29072
  */
29073
29073
  __publicField(this, "descriptorPushTimer");
29074
+ /**
29075
+ * 已做过「凭据回填」的端点去重键。同一进程内每个端点只回填一次,
29076
+ * 避免每次建对都重写一遍别人的描述符。
29077
+ */
29078
+ __publicField(this, "credentialBackfillDone", /* @__PURE__ */ new Set());
29074
29079
  /** 后台建对(deferReplicaSetup)的状态,见 `whenReplicasReady()`。 */
29075
29080
  __publicField(this, "replicaSetupPromise", null);
29076
29081
  __publicField(this, "replicaSetupSummary", null);
@@ -30320,6 +30325,9 @@ var ZenFSConfig = (() => {
30320
30325
  );
30321
30326
  this.replicaBackends.set(desc.id, { instance: fsInstance, syncable, pairId: pair.pairId });
30322
30327
  this.backendStates.set(desc.id, { backendId: desc.id, pairId: pair.pairId });
30328
+ void this.backfillDuplicateBackendCredentials(desc).catch((err2) => {
30329
+ log9.warn("[ConfigRepo] backfill duplicate backend credentials failed:", err2);
30330
+ });
30323
30331
  const conflictHandler = (event) => {
30324
30332
  this.handleConflict(event);
30325
30333
  };
@@ -30664,6 +30672,50 @@ var ZenFSConfig = (() => {
30664
30672
  this.backendDescriptorCache = [...result];
30665
30673
  return result;
30666
30674
  }
30675
+ /**
30676
+ * 把「连得上的凭据」回填到同一端点的重复描述符里。
30677
+ *
30678
+ * 背景:RemoteStorage 的 `token` 不进 `identityFields`(见 admin 的后端注册),
30679
+ * 同一 `href`+`basePath` 只会被当成一个端点;但历史上按 token 判重时,每次
30680
+ * 重新授权都会新增一个 `remotestorage-<时间戳>` 描述符,旧描述符仍留在
30681
+ * `.meta/backends/` 里。读时去重按 mtime 保留最早的一份,如果那份的 token
30682
+ * 已经失效,这个端点就会永远连不上。这里在某个描述符成功建对之后,把它的
30683
+ * token 写回同键的其它描述符,保证「留下的那份」凭据是可用的。
30684
+ *
30685
+ * 只改 token 一个字段,不新增/删除描述符,也不影响 id 与 mtime 之外的内容。
30686
+ */
30687
+ async backfillDuplicateBackendCredentials(desc) {
30688
+ const options = desc.options;
30689
+ const mine = options?.token;
30690
+ if (typeof mine !== "string" || mine.length === 0) return;
30691
+ const key = backendDedupKey(desc);
30692
+ if (this.credentialBackfillDone.has(key)) return;
30693
+ this.credentialBackfillDone.add(key);
30694
+ let items;
30695
+ try {
30696
+ items = (await this.readBackendDescriptorsFrom(BACKENDS_DIR)).items;
30697
+ } catch (err2) {
30698
+ log9.warn("[ConfigRepo] backfill credentials: read descriptors failed:", err2);
30699
+ return;
30700
+ }
30701
+ for (const item of items) {
30702
+ if (item.desc.id === desc.id) continue;
30703
+ if (backendDedupKey(item.desc) !== key) continue;
30704
+ const theirs = item.desc.options?.token;
30705
+ if (typeof theirs !== "string" || theirs === mine) continue;
30706
+ try {
30707
+ await this.writeBackendDescriptor({
30708
+ ...item.desc,
30709
+ options: { ...item.desc.options, token: mine }
30710
+ });
30711
+ log9.log(
30712
+ `[ConfigRepo] backfilled working credential into duplicate descriptor ${item.desc.id} (endpoint ${key})`
30713
+ );
30714
+ } catch (err2) {
30715
+ log9.warn(`[ConfigRepo] backfill credentials: write ${item.desc.id} failed:`, err2);
30716
+ }
30717
+ }
30718
+ }
30667
30719
  /**
30668
30720
  * Write a single backend descriptor to `.meta/backends/{id}.json`.
30669
30721
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
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",