@unicitylabs/sphere-sdk 0.17.5 → 0.17.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.
@@ -23886,6 +23886,7 @@ var FileStorageProvider = class {
23886
23886
  isTxtMode;
23887
23887
  network;
23888
23888
  data = {};
23889
+ loading = null;
23889
23890
  status = "disconnected";
23890
23891
  _identity = null;
23891
23892
  constructor(config) {
@@ -23950,9 +23951,25 @@ var FileStorageProvider = class {
23950
23951
  this.status = "connected";
23951
23952
  }
23952
23953
  async disconnect() {
23953
- await this.save();
23954
+ if (this.status === "connected") {
23955
+ await this.save();
23956
+ }
23954
23957
  this.status = "disconnected";
23955
23958
  }
23959
+ /**
23960
+ * `data` holds the file's contents only after connect() has read them. Used before
23961
+ * that, this provider answered reads from an empty map and — worse — save() rewrote
23962
+ * the WHOLE file from it, so one set() on a never-connected provider erased the wallet
23963
+ * and every payment journal (#811). Every data method now loads the file first; an
23964
+ * explicit connect() stays the normal path and this is the safety net under it.
23965
+ */
23966
+ async ensureLoaded() {
23967
+ if (this.status === "connected") return;
23968
+ this.loading ??= this.connect().finally(() => {
23969
+ this.loading = null;
23970
+ });
23971
+ await this.loading;
23972
+ }
23956
23973
  isConnected() {
23957
23974
  return this.status === "connected";
23958
23975
  }
@@ -23960,24 +23977,29 @@ var FileStorageProvider = class {
23960
23977
  return this.status;
23961
23978
  }
23962
23979
  async get(key) {
23980
+ await this.ensureLoaded();
23963
23981
  const fullKey = this.getFullKey(key);
23964
23982
  return this.data[fullKey] ?? null;
23965
23983
  }
23966
23984
  async set(key, value) {
23985
+ await this.ensureLoaded();
23967
23986
  const fullKey = this.getFullKey(key);
23968
23987
  this.data[fullKey] = value;
23969
23988
  await this.save();
23970
23989
  }
23971
23990
  async remove(key) {
23991
+ await this.ensureLoaded();
23972
23992
  const fullKey = this.getFullKey(key);
23973
23993
  delete this.data[fullKey];
23974
23994
  await this.save();
23975
23995
  }
23976
23996
  async has(key) {
23997
+ await this.ensureLoaded();
23977
23998
  const fullKey = this.getFullKey(key);
23978
23999
  return fullKey in this.data;
23979
24000
  }
23980
24001
  async keys(prefix) {
24002
+ await this.ensureLoaded();
23981
24003
  const allKeys = Object.keys(this.data);
23982
24004
  if (prefix) {
23983
24005
  return allKeys.filter((k) => k.startsWith(prefix));
@@ -23985,6 +24007,7 @@ var FileStorageProvider = class {
23985
24007
  return allKeys;
23986
24008
  }
23987
24009
  async clear(prefix) {
24010
+ await this.ensureLoaded();
23988
24011
  if (prefix) {
23989
24012
  const keysToDelete = Object.keys(this.data).filter((k) => k.startsWith(prefix));
23990
24013
  for (const key of keysToDelete) {