@ghostlytools/cli 1.13.1 → 1.13.2

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.
Files changed (93) hide show
  1. package/README.md +6 -4
  2. package/dist/assets/api-DV52o7A8.js +3 -0
  3. package/dist/assets/{api-Dnq86JAA.js → api-O57SNJcb.js} +375 -77
  4. package/dist/assets/api-O57SNJcb.js.map +1 -0
  5. package/dist/assets/{apiKit-nLK4jeTq.js → apiKit-CPTFJHA7.js} +39 -7
  6. package/dist/assets/{apiKit-nLK4jeTq.js.map → apiKit-CPTFJHA7.js.map} +1 -1
  7. package/dist/assets/{appFetch-wqBWi3Ry.js → appFetch-Ca9DNQQ2.js} +2 -2
  8. package/dist/assets/{appFetch-wqBWi3Ry.js.map → appFetch-Ca9DNQQ2.js.map} +1 -1
  9. package/dist/assets/{apps-DBVhKpfe.js → apps-gXpGFPiv.js} +11 -9
  10. package/dist/assets/apps-gXpGFPiv.js.map +1 -0
  11. package/dist/assets/{apps-nLtyhC2f.js → apps-uZTu5FlR.js} +1 -1
  12. package/dist/assets/{arkade-DryM-q5n.js → arkade-B6UNf5HI.js} +2 -2
  13. package/dist/assets/{arkade-DryM-q5n.js.map → arkade-B6UNf5HI.js.map} +1 -1
  14. package/dist/assets/{backup-Bczllmzf.js → backup-CxH3auHB.js} +8 -6
  15. package/dist/assets/backup-CxH3auHB.js.map +1 -0
  16. package/dist/assets/{backup-D6s0LQdg.js → backup-Di2U6QVH.js} +1 -1
  17. package/dist/assets/{bitcoind-DML_-Xbv.js → bitcoind-BpZn3bRN.js} +2 -2
  18. package/dist/assets/{bitcoind-DML_-Xbv.js.map → bitcoind-BpZn3bRN.js.map} +1 -1
  19. package/dist/assets/{buttons-B3C3vdhH.js → buttons-D4udKEvT.js} +4 -4
  20. package/dist/assets/{buttons-B3C3vdhH.js.map → buttons-D4udKEvT.js.map} +1 -1
  21. package/dist/assets/buttons-YTYEqvGC.js +1 -0
  22. package/dist/assets/{client-B7jRrSnb.js → client-DGx7E8b3.js} +2 -2
  23. package/dist/assets/{client-B7jRrSnb.js.map → client-DGx7E8b3.js.map} +1 -1
  24. package/dist/assets/{engineErrors--9hfgKlK.js → engineErrors-wWlLy54D.js} +11 -3
  25. package/dist/assets/engineErrors-wWlLy54D.js.map +1 -0
  26. package/dist/assets/{fixedHosts-H3i6o9Iy.js → fixedHosts-CODN2pTL.js} +3 -3
  27. package/dist/assets/{fixedHosts-H3i6o9Iy.js.map → fixedHosts-CODN2pTL.js.map} +1 -1
  28. package/dist/assets/{groupMeta--fxSh792.js → groupMeta-CeZpqVVC.js} +105 -36
  29. package/dist/assets/groupMeta-CeZpqVVC.js.map +1 -0
  30. package/dist/assets/{host-CGzVFfMz.js → host-CRA7h5A2.js} +113 -40
  31. package/dist/assets/host-CRA7h5A2.js.map +1 -0
  32. package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js → hyperdhtRelay-B34Zhz4P.js} +2 -2
  33. package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js.map → hyperdhtRelay-B34Zhz4P.js.map} +1 -1
  34. package/dist/assets/{hyperdhtRelay-B4_wdCtx.js → hyperdhtRelay-DDwU5b4P.js} +2 -2
  35. package/dist/assets/{hyperdhtRelay-B4_wdCtx.js.map → hyperdhtRelay-DDwU5b4P.js.map} +1 -1
  36. package/dist/assets/{identityProofs-Cksc_K7_.js → identityProofs-B8zCp5_0.js} +140 -27
  37. package/dist/assets/identityProofs-B8zCp5_0.js.map +1 -0
  38. package/dist/assets/{irohWeb-Dp1i8v6n.js → irohWeb-mnOi2Jp7.js} +10832 -4832
  39. package/dist/assets/irohWeb-mnOi2Jp7.js.map +1 -0
  40. package/dist/assets/{linkPreview-DdMf-YAc.js → linkPreview-5kHmKUTN.js} +20 -8
  41. package/dist/assets/linkPreview-5kHmKUTN.js.map +1 -0
  42. package/dist/assets/{main-C8J53SwH.js → main-Chc871HV.js} +72 -39
  43. package/dist/assets/main-Chc871HV.js.map +1 -0
  44. package/dist/assets/{mainline-DY95WbuK.js → mainline-CDUXtV-I.js} +2 -2
  45. package/dist/assets/{mainline-DY95WbuK.js.map → mainline-CDUXtV-I.js.map} +1 -1
  46. package/dist/assets/{networkReason-Be-hMghr.js → networkReason-DYlPZS5M.js} +2 -2
  47. package/dist/assets/{networkReason-Be-hMghr.js.map → networkReason-DYlPZS5M.js.map} +1 -1
  48. package/dist/assets/{ownDid-oa-T2vmZ.js → ownDid-BOuSlDv-.js} +4 -4
  49. package/dist/assets/{ownDid-oa-T2vmZ.js.map → ownDid-BOuSlDv-.js.map} +1 -1
  50. package/dist/assets/{ownStatus-Bc08eNJY.js → ownStatus-CLA1VPkL.js} +3 -3
  51. package/dist/assets/{ownStatus-Bc08eNJY.js.map → ownStatus-CLA1VPkL.js.map} +1 -1
  52. package/dist/assets/{pairedTransports-Dppn8lUN.js → pairedTransports-DAzupLYo.js} +21 -15
  53. package/dist/assets/pairedTransports-DAzupLYo.js.map +1 -0
  54. package/dist/assets/{paymentIntent-DySU3Ajm.js → paymentIntent-Cr3uZa_0.js} +2 -2
  55. package/dist/assets/{paymentIntent-DySU3Ajm.js.map → paymentIntent-Cr3uZa_0.js.map} +1 -1
  56. package/dist/assets/{profiles-B2uy04ph.js → profiles-BH1bH9aE.js} +2 -2
  57. package/dist/assets/{profiles-B2uy04ph.js.map → profiles-BH1bH9aE.js.map} +1 -1
  58. package/dist/assets/{registry-bLIfG619.js → registry-DAq16T-V.js} +1 -1
  59. package/dist/assets/{registry-DbTLLs3y.js → registry-DP_-RA-v.js} +5 -5
  60. package/dist/assets/{registry-DbTLLs3y.js.map → registry-DP_-RA-v.js.map} +1 -1
  61. package/dist/assets/{relay-CHWg5hpZ.js → relay-gJTOYQJZ.js} +93 -7
  62. package/dist/assets/relay-gJTOYQJZ.js.map +1 -0
  63. package/dist/assets/{resolve-DNX-eecG.js → resolve-B1eQ4dVQ.js} +3 -3
  64. package/dist/assets/{resolve-DNX-eecG.js.map → resolve-B1eQ4dVQ.js.map} +1 -1
  65. package/dist/assets/{server-DWJ4RzJn.js → server-Bd2ofxc1.js} +717 -6389
  66. package/dist/assets/server-Bd2ofxc1.js.map +1 -0
  67. package/dist/assets/{sshForges-BnvwmNj-.js → sshForges-As7dbGXM.js} +2 -2
  68. package/dist/assets/{sshForges-BnvwmNj-.js.map → sshForges-As7dbGXM.js.map} +1 -1
  69. package/dist/assets/{translate-CHj_PdLg.js → translate-DnuQMfj0.js} +10 -4
  70. package/dist/assets/translate-DnuQMfj0.js.map +1 -0
  71. package/dist/assets/{usdt-CBJ4Q5Ji.js → usdt-DLmtf8F9.js} +4 -4
  72. package/dist/assets/{usdt-CBJ4Q5Ji.js.map → usdt-DLmtf8F9.js.map} +1 -1
  73. package/dist/assets/{waitNotice-Cvz5CiKR.js → waitNotice-BHuMofaH.js} +2 -2
  74. package/dist/assets/{waitNotice-Cvz5CiKR.js.map → waitNotice-BHuMofaH.js.map} +1 -1
  75. package/dist/ghostly.mjs +1 -1
  76. package/npm-shrinkwrap.json +2 -2
  77. package/package.json +1 -1
  78. package/dist/assets/api-DF36rBJK.js +0 -3
  79. package/dist/assets/api-Dnq86JAA.js.map +0 -1
  80. package/dist/assets/apps-DBVhKpfe.js.map +0 -1
  81. package/dist/assets/backup-Bczllmzf.js.map +0 -1
  82. package/dist/assets/buttons-DaY5FYlV.js +0 -1
  83. package/dist/assets/engineErrors--9hfgKlK.js.map +0 -1
  84. package/dist/assets/groupMeta--fxSh792.js.map +0 -1
  85. package/dist/assets/host-CGzVFfMz.js.map +0 -1
  86. package/dist/assets/identityProofs-Cksc_K7_.js.map +0 -1
  87. package/dist/assets/irohWeb-Dp1i8v6n.js.map +0 -1
  88. package/dist/assets/linkPreview-DdMf-YAc.js.map +0 -1
  89. package/dist/assets/main-C8J53SwH.js.map +0 -1
  90. package/dist/assets/pairedTransports-Dppn8lUN.js.map +0 -1
  91. package/dist/assets/relay-CHWg5hpZ.js.map +0 -1
  92. package/dist/assets/server-DWJ4RzJn.js.map +0 -1
  93. package/dist/assets/translate-CHj_PdLg.js.map +0 -1
@@ -1,15 +1,15 @@
1
1
  import { p as fileStore } from "./idb-ewvbqyDI.js";
2
- import { _ as groupPayTwins, d as servedApps, f as nodeLocalFetch, g as groupMessageJson, h as groupJson, l as paymentJson, m as chatMessageJson, p as chatJson, r as callApi, u as reportAppFrames, v as resumeHolds, y as flushCardUpdates } from "./api-Dnq86JAA.js";
3
- import { N as sinceSeq, s as findChat, u as findOwnNamedChat } from "./apiKit-nLK4jeTq.js";
2
+ import { _ as groupJson, b as resumeHolds, d as reportAppFrames, f as servedApps, g as chatMessageJson, h as chatJson, p as nodeLocalFetch, r as callApi, u as paymentJson, v as groupMessageJson, x as flushCardUpdates, y as groupPayTwins } from "./api-O57SNJcb.js";
3
+ import { I as sinceSeq, s as findChat, u as findOwnNamedChat } from "./apiKit-CPTFJHA7.js";
4
4
  import { o as shownValue, r as asCliError, t as CliError } from "./errors-JVJsO8Iu.js";
5
- import { C as ownFolder, D as runtimePath, E as privateFolder, n as RESTORED_MARK, r as acquireLock, w as ownProfile, x as startingPath } from "./profiles-B2uy04ph.js";
6
- import { _ as frameBytes, b as monotonic, d as proof, f as removeDaemonSecret, g as bytesToMs, h as PlaybackQueue, l as greeting, m as DEFAULT_RATE, u as newDaemonSecret, v as frameSamples, y as isCallRate } from "./client-B7jRrSnb.js";
7
- import { Ci as DAEMON_WATCH_PEER_IDLE_MS, Gi as callSignalHeardAt, Hi as answersOffer, Ji as parseCallSignal, Qt as checkPushEndpoint, St as STATUS_IDLE_AFTER_MS, Ui as buildSdpFromSignal, Vi as RTC_CONFIG, Wi as callRtcConfig, Yi as signalHasVideo, _n as ACTIVE_DHT_POLL_MS, qi as extractParamsFromSdp, zi as CALL_SIGNAL_MAX_AGE_MS } from "./groupMeta--fxSh792.js";
8
- import { d as parsePayLink, r as irohRelayProblem } from "./irohWeb-Dp1i8v6n.js";
5
+ import { C as ownFolder, D as runtimePath, E as privateFolder, n as RESTORED_MARK, r as acquireLock, w as ownProfile, x as startingPath } from "./profiles-BH1bH9aE.js";
6
+ import { _ as frameBytes, b as monotonic, d as proof, f as removeDaemonSecret, g as bytesToMs, h as PlaybackQueue, l as greeting, m as DEFAULT_RATE, u as newDaemonSecret, v as frameSamples, y as isCallRate } from "./client-DGx7E8b3.js";
7
+ import { Ci as DAEMON_WATCH_PEER_IDLE_MS, Gi as callSignalHeardAt, Hi as answersOffer, Ji as parseCallSignal, Qt as checkPushEndpoint, St as STATUS_IDLE_AFTER_MS, Ui as buildSdpFromSignal, Vi as RTC_CONFIG, Wi as callRtcConfig, Yi as signalHasVideo, _n as ACTIVE_DHT_POLL_MS, qi as extractParamsFromSdp, zi as CALL_SIGNAL_MAX_AGE_MS } from "./groupMeta-CeZpqVVC.js";
8
+ import { g as parsePayLink, r as irohRelayProblem } from "./irohWeb-mnOi2Jp7.js";
9
9
  import { i as fromBase64Url } from "./bytes-C1DNGY18.js";
10
- import { u as setLinkTraceSink } from "./relay-CHWg5hpZ.js";
10
+ import { u as setLinkTraceSink } from "./relay-gJTOYQJZ.js";
11
11
  import { b as setPublicKeyFastPath } from "./pkarr-BQo4PcCg.js";
12
- import { p as nativePublicKey } from "./apps-DBVhKpfe.js";
12
+ import { p as nativePublicKey } from "./apps-gXpGFPiv.js";
13
13
  import { n as fedimintSdkOn } from "./fedimintSdk-D-6H9Pe7.js";
14
14
  import { s as isPublicAddress } from "./domainProofs-b3Y1Gj9g.js";
15
15
  import { createRequire } from "node:module";
@@ -1289,7 +1289,7 @@ var CallManager = class {
1289
1289
  this.held.delete(chat);
1290
1290
  this.bursts.delete(chat);
1291
1291
  const link = this.link(chat);
1292
- const call = this.add(chat, "in", this.auto.rate);
1292
+ const call = this.add(chat, "in", DEFAULT_RATE);
1293
1293
  call.offer = offer;
1294
1294
  call.video = signalHasVideo(offer);
1295
1295
  this.arm(call, Math.max(1e3, callSignalHeardAt(offer) + CALL_SIGNAL_MAX_AGE_MS - this.now), "missed", false);
@@ -1301,7 +1301,7 @@ var CallManager = class {
1301
1301
  auto: this.autoFor(chat)
1302
1302
  });
1303
1303
  this.prepare(call);
1304
- if (this.host.answers !== false && this.autoFor(chat)) this.answer(call.id, {}).catch((error) => process.stderr.write(`ghostly: auto-answer failed: ${error instanceof Error ? error.message : String(error)}\n`));
1304
+ if (this.host.answers !== false && this.autoFor(chat)) this.answer(call.id, { rate: this.auto.rate }).catch((error) => process.stderr.write(`ghostly: auto-answer failed: ${error instanceof Error ? error.message : String(error)}\n`));
1305
1305
  }
1306
1306
  accepted(call, answer) {
1307
1307
  call.offering = false;
@@ -1464,7 +1464,7 @@ var CallManager = class {
1464
1464
  throw new CliError("busy", "The contact is calling: their call rings here");
1465
1465
  }
1466
1466
  this.paced(link.id);
1467
- const rate = rateOf(options.rate, this.auto.rate);
1467
+ const rate = rateOf(options.rate, DEFAULT_RATE);
1468
1468
  const stack = await this.stack();
1469
1469
  if (this.byChat(link.id)) throw new CliError("busy", "A call is already on in this chat");
1470
1470
  const call = this.add(link.id, "out", rate);
@@ -1896,12 +1896,25 @@ var CallManager = class {
1896
1896
  byChat(chat) {
1897
1897
  for (const call of this.calls.values()) if (call.chat === chat) return call;
1898
1898
  }
1899
- /** A call by its id, or by its chat; with no ref, the only call (or the only one `prefer` picks). */
1899
+ /**
1900
+ * A call by its id, or by its chat; with no ref, the only call (or the only one `prefer` picks). A ref shaped as a
1901
+ * call's id (`CALL_ID`) that names no call on now and no chat says so as a call: it ended (hung up twice, or a
1902
+ * command racing the call's end) or never was one. It said `No chat "<id>"`, sending a script to the chat list. A
1903
+ * chat whose id or label has that shape is still found as a chat first. An ended call is not kept (`end`), so
1904
+ * whether it ended or never was is not known here.
1905
+ */
1900
1906
  find(ref, prefer) {
1901
1907
  if (ref) {
1902
1908
  const byId = this.calls.get(ref);
1903
1909
  if (byId) return byId;
1904
- const call = this.byChat(this.chatOf(ref).id);
1910
+ let chat;
1911
+ try {
1912
+ chat = this.chatOf(ref);
1913
+ } catch (error) {
1914
+ if (CALL_ID.test(ref) && error instanceof CliError && error.code === "not_found" && !error.details) throw new CliError("not_found", `No call ${ref}: it ended or never existed (ghostly call list)`);
1915
+ throw error;
1916
+ }
1917
+ const call = this.byChat(chat.id);
1905
1918
  if (!call) throw new CliError("not_found", `No call in chat ${ref}`);
1906
1919
  return call;
1907
1920
  }
@@ -1942,6 +1955,8 @@ var CallManager = class {
1942
1955
  return this.auto.on && (this.auto.from.length === 0 || this.auto.from.includes(chat));
1943
1956
  }
1944
1957
  };
1958
+ /** A call's id as `add` makes it: 6 random bytes in lowercase hex. */
1959
+ var CALL_ID = /^[0-9a-f]{12}$/;
1945
1960
  var CALLS_NEED_DAEMON = "Calls need the daemon (a call outlives this command): start it with `ghostly daemon --detach`";
1946
1961
  /** The engine's `callsUnavailable` for a chat with no live session (ghostlink's, or node.ts's with no link running). */
1947
1962
  var CALLS_NEED_LIVE = "Calls need a live connection";
@@ -4418,15 +4433,25 @@ var TreeFile = class {
4418
4433
  abort(owner) {
4419
4434
  for (const tree of this.live) tree.abort(owner);
4420
4435
  }
4421
- /** The layers of the journal's entries up to `upTo` into SQLite, in one transaction that says so (`applied`). */
4422
- apply(upTo) {
4436
+ /** The name of the snapshot that the last fold's `apply` went with (`storage.ts`). */
4437
+ snapshot() {
4438
+ const row = this.db.prepare("SELECT value FROM meta WHERE name = 'snapshot'").get();
4439
+ return row ? String(row.value) : void 0;
4440
+ }
4441
+ /**
4442
+ * The layers of the journal's entries up to `upTo` into SQLite, in one transaction that says so (`applied`). `snapshot`:
4443
+ * the fold's, written whole before this and put in place after; recorded with them, so a process killed between the
4444
+ * two comes back to it, not to the snapshot before it with these transactions half there.
4445
+ */
4446
+ apply(upTo, snapshot) {
4423
4447
  const due = [...this.live].filter((tree) => tree.due(upTo));
4424
- if (!due.length) return;
4448
+ if (!due.length && snapshot === void 0) return;
4425
4449
  this.db.exec("BEGIN");
4426
4450
  try {
4427
4451
  let top = 0;
4428
4452
  for (const tree of due) top = Math.max(top, tree.write(upTo));
4429
4453
  this.db.prepare("INSERT OR REPLACE INTO meta (name, value) VALUES ('applied', max(?, coalesce((SELECT value FROM meta WHERE name = 'applied'), 0)))").run(top);
4454
+ if (snapshot !== void 0) this.db.prepare("INSERT OR REPLACE INTO meta (name, value) VALUES ('snapshot', ?)").run(snapshot);
4430
4455
  this.db.exec("COMMIT");
4431
4456
  } catch (error) {
4432
4457
  rollback(this.db);
@@ -4948,11 +4973,23 @@ async function openPersistentIndexedDb(dir, options = {}) {
4948
4973
  let holdsRatchet = false;
4949
4974
  /** The journal holds a delete of a chat or a message (or a settings write), and what came before it with it. */
4950
4975
  let holdsDelete = false;
4976
+ /** The exports under way (a backup's), each holding rows.db as it was when it began (`openTreeReader`). */
4977
+ const exporting = /* @__PURE__ */ new Set();
4978
+ /** The scrub's fold asked for that has not begun yet: a scrub asked meanwhile is that one (`compact`). */
4979
+ let nextScrub = null;
4951
4980
  const pending = /* @__PURE__ */ new WeakMap();
4952
4981
  const snapshotPath = join(dir, SNAPSHOT);
4953
4982
  const journalPath = join(dir, JOURNAL);
4983
+ const temporaryPath = snapshotPath + ".tmp";
4984
+ /** The last entry the snapshot on disk holds: one that waited behind its fold is not written to the journal after it. */
4985
+ let foldedUpTo = 0;
4954
4986
  const ratchetDue = () => holdsRatchet && Date.now() - (statSync(snapshotPath, { throwIfNoEntry: false })?.mtimeMs ?? 0) >= RATCHET_FOLD_MS;
4955
4987
  const deleteDue = () => holdsDelete && Date.now() - (statSync(snapshotPath, { throwIfNoEntry: false })?.mtimeMs ?? 0) >= DELETE_FOLD_MS;
4988
+ const foldedTo = trees?.snapshot();
4989
+ if (foldedTo !== void 0 && existsSync(temporaryPath) && journalNamed(temporaryPath) === foldedTo) {
4990
+ renameSync(temporaryPath, snapshotPath);
4991
+ rmSync(journalPath, { force: true });
4992
+ }
4956
4993
  const snapshotFound = existsSync(snapshotPath), journalFound = existsSync(journalPath);
4957
4994
  const saved = snapshotFound ? deserialize(readFileSync(snapshotPath)) : null;
4958
4995
  const rows = sqlite && saved?.format === 2 && rowsFound ? openRowFile(sqlite, rowsPath) : null;
@@ -5157,6 +5194,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
5157
5194
  held++;
5158
5195
  enqueue(async () => {
5159
5196
  try {
5197
+ if (entry <= foldedUpTo) return;
5160
5198
  if (writeEntry(serialize(await Promise.all(ops.map(async (op) => op.kind === "put" ? {
5161
5199
  ...op,
5162
5200
  value: await blobsToDisk(op.value)
@@ -5480,7 +5518,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
5480
5518
  out.begin("A", count);
5481
5519
  let written = 0;
5482
5520
  for (const record of Array.isArray(records) ? records : records.getAllRecords()) {
5483
- let value = Array.isArray(records) ? await blobsToDisk(record.value) : record.value;
5521
+ let value = Array.isArray(records) || hasBlob(record.value) ? await blobsToDisk(record.value) : record.value;
5484
5522
  if (meta.name === "links" && value && typeof value === "object" && "ratchetState" in value) {
5485
5523
  const { ratchetState: _ratchet, ...link } = value;
5486
5524
  value = link;
@@ -5512,20 +5550,21 @@ async function openPersistentIndexedDb(dir, options = {}) {
5512
5550
  const { snapshot, upTo } = await capture(name);
5513
5551
  const live = trees ? liveTrees() : null;
5514
5552
  unsaved = false;
5515
- const temporary = snapshotPath + ".tmp";
5516
- const file = await open(temporary, "w", 384);
5553
+ const file = await open(temporaryPath, "w", 384);
5517
5554
  try {
5518
5555
  await writeSnapshotTo(file, snapshot);
5519
5556
  await file.sync();
5520
5557
  } finally {
5521
5558
  await file.close();
5522
5559
  }
5560
+ while (scrub && trees && exporting.size) await Promise.allSettled(exporting);
5523
5561
  if (trees) {
5524
- trees.apply(upTo);
5562
+ trees.apply(upTo, name);
5525
5563
  if (scrub) trees.scrub();
5526
5564
  trees.sync();
5527
5565
  }
5528
- renameSync(temporary, snapshotPath);
5566
+ renameSync(temporaryPath, snapshotPath);
5567
+ foldedUpTo = upTo;
5529
5568
  try {
5530
5569
  if (live) trees.sweep(/* @__PURE__ */ new Set([...live, ...liveTrees()]));
5531
5570
  } catch (error) {
@@ -5586,12 +5625,22 @@ async function openPersistentIndexedDb(dir, options = {}) {
5586
5625
  flush: () => queue,
5587
5626
  async compact(options) {
5588
5627
  await settled();
5589
- let thrown = null;
5590
- await enqueue(() => writeSnapshot(options?.scrub).catch((error) => {
5591
- thrown = { error };
5592
- throw error;
5593
- }));
5594
- if (thrown) throw thrown.error;
5628
+ const scrub = options?.scrub === true;
5629
+ if (scrub && nextScrub) return nextScrub;
5630
+ const fold = (async () => {
5631
+ while (scrub && exporting.size) await Promise.allSettled(exporting);
5632
+ let thrown = null;
5633
+ await enqueue(() => {
5634
+ if (scrub) nextScrub = null;
5635
+ return writeSnapshot(scrub).catch((error) => {
5636
+ thrown = { error };
5637
+ throw error;
5638
+ });
5639
+ });
5640
+ if (thrown) throw thrown.error;
5641
+ })();
5642
+ if (scrub) nextScrub = fold;
5643
+ return fold;
5595
5644
  },
5596
5645
  async close() {
5597
5646
  if (!writing) return;
@@ -5608,12 +5657,20 @@ async function openPersistentIndexedDb(dir, options = {}) {
5608
5657
  journalBytes,
5609
5658
  async exportSnapshot(path) {
5610
5659
  await settled();
5611
- const file = await open(path, "w", 384);
5660
+ const run = (async () => {
5661
+ const file = await open(path, "w", 384);
5662
+ try {
5663
+ await exportTo(file);
5664
+ await file.sync();
5665
+ } finally {
5666
+ await file.close();
5667
+ }
5668
+ })();
5669
+ exporting.add(run);
5612
5670
  try {
5613
- await exportTo(file);
5614
- await file.sync();
5671
+ await run;
5615
5672
  } finally {
5616
- await file.close();
5673
+ exporting.delete(run);
5617
5674
  }
5618
5675
  }
5619
5676
  };
@@ -5779,6 +5836,14 @@ function follows(journal) {
5779
5836
  return;
5780
5837
  }
5781
5838
  }
5839
+ /** The name a snapshot file gives the journal after it; undefined for one cut short (a fold killed while it wrote it). */
5840
+ function journalNamed(path) {
5841
+ try {
5842
+ return deserialize(readFileSync(path)).journal;
5843
+ } catch {
5844
+ return;
5845
+ }
5846
+ }
5782
5847
  /** fake-indexeddb's raw classes, from a throwaway database (they are not exported). */
5783
5848
  async function probeClasses(factory) {
5784
5849
  const db = await new Promise((resolve, reject) => {
@@ -6346,6 +6411,7 @@ function keyFromDisk(key) {
6346
6411
  if (range.upper === void 0) return IDBKeyRange$1.lowerBound(range.lower, range.lowerOpen);
6347
6412
  return IDBKeyRange$1.bound(range.lower, range.upper, range.lowerOpen, range.upperOpen);
6348
6413
  }
6414
+ /** A Blob, or an object of the app's that has the marker's key itself (`blobsToDisk`): what goes to disk changed. */
6349
6415
  function hasBlob(value, depth = 0) {
6350
6416
  if (value instanceof Blob) return true;
6351
6417
  if (!value || typeof value !== "object" || depth > 32 || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return false;
@@ -6353,10 +6419,14 @@ function hasBlob(value, depth = 0) {
6353
6419
  for (const [k, v] of value) if (hasBlob(k, depth + 1) || hasBlob(v, depth + 1)) return true;
6354
6420
  return false;
6355
6421
  }
6422
+ if (Object.hasOwn(value, BLOB)) return true;
6356
6423
  for (const item of Object.values(value)) if (hasBlob(item, depth + 1)) return true;
6357
6424
  return false;
6358
6425
  }
6359
- /** v8 cannot serialize a Blob: it goes to disk as its bytes and type, and comes back a Blob. */
6426
+ /**
6427
+ * v8 cannot serialize a Blob: it goes to disk as its bytes and type, and comes back a Blob. An object of the app's
6428
+ * that has the marker's key itself (a contact's data can) goes in a marker too, as it is, so it never comes back a Blob.
6429
+ */
6360
6430
  async function blobsToDisk(value, depth = 0) {
6361
6431
  if (!hasBlob(value, depth)) return value;
6362
6432
  if (value instanceof Blob) return { [BLOB]: {
@@ -6367,17 +6437,20 @@ async function blobsToDisk(value, depth = 0) {
6367
6437
  if (value instanceof Map) return new Map(await Promise.all([...value].map(async ([k, v]) => [k, await blobsToDisk(v, depth + 1)])));
6368
6438
  const out = {};
6369
6439
  for (const [k, v] of Object.entries(value)) out[k] = await blobsToDisk(v, depth + 1);
6370
- return out;
6440
+ return Object.hasOwn(out, BLOB) ? { [BLOB]: { kept: out } } : out;
6371
6441
  }
6442
+ /** Only a marker this store wrote is one: its key alone, holding bytes (which no JSON makes) or an object it kept. */
6372
6443
  function blobsFromDisk(value, depth = 0) {
6373
6444
  if (!value || typeof value !== "object" || depth > 32 || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return value;
6374
- const blob = value[BLOB];
6375
- if (blob) return new Blob([blob.bytes], { type: blob.type });
6376
6445
  if (Array.isArray(value)) return value.map((item) => blobsFromDisk(item, depth + 1));
6377
6446
  if (value instanceof Map) return new Map([...value].map(([k, v]) => [k, blobsFromDisk(v, depth + 1)]));
6378
6447
  if (Object.getPrototypeOf(value) !== Object.prototype) return value;
6448
+ const marker = Object.keys(value).length === 1 ? value[BLOB] : void 0;
6449
+ const { type, bytes, kept } = marker && typeof marker === "object" ? marker : {};
6450
+ if (bytes instanceof Uint8Array && typeof type === "string") return new Blob([bytes], { type });
6451
+ const fields = kept && typeof kept === "object" && Object.getPrototypeOf(kept) === Object.prototype ? kept : value;
6379
6452
  const out = {};
6380
- for (const [k, v] of Object.entries(value)) out[k] = blobsFromDisk(v, depth + 1);
6453
+ for (const [k, v] of Object.entries(fields)) out[k] = blobsFromDisk(v, depth + 1);
6381
6454
  return out;
6382
6455
  }
6383
6456
  /**
@@ -6716,8 +6789,8 @@ async function startRuntime(paths, options = {}) {
6716
6789
  const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-CCKbwqG_.js"), import("./fileBytes-tj6-VZcB.js")]);
6717
6790
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
6718
6791
  if (await (await import("./blobFiles-DDs34n0r.js")).moveBlobFiles()) await store.compact();
6719
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-DWJ4RzJn.js"), import("./endpoint-Cvu-taMs.js")]);
6720
- const mainline = dht.off ? null : new (await (import("./mainline-DY95WbuK.js"))).Mainline({
6792
+ const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-Bd2ofxc1.js"), import("./endpoint-Cvu-taMs.js")]);
6793
+ const mainline = dht.off ? null : new (await (import("./mainline-CDUXtV-I.js"))).Mainline({
6721
6794
  bootstrap: dht.bootstrap,
6722
6795
  host: dht.host
6723
6796
  });
@@ -6725,7 +6798,7 @@ async function startRuntime(paths, options = {}) {
6725
6798
  ...pinned ? { relays: pinned } : {},
6726
6799
  ...relayBudgetForTests()
6727
6800
  };
6728
- const transport = mainline || pinned ? new (await (import("./mainline-DY95WbuK.js"))).RelaysAndDht(mainline, relayOptions, !!pinned) : null;
6801
+ const transport = mainline || pinned ? new (await (import("./mainline-CDUXtV-I.js"))).RelaysAndDht(mainline, relayOptions, !!pinned) : null;
6729
6802
  const apps = servedApps(paths.dir).length > 0;
6730
6803
  const server = new EngineServer({
6731
6804
  ...transport ? { transport } : {},
@@ -7187,4 +7260,4 @@ function connection(ctx, socket, secret, answering) {
7187
7260
  }
7188
7261
  export { BASELINE_NEWEST, MAX_UNREAD, STOP_ANSWERS_MS, keepServing, openHost, serve };
7189
7262
 
7190
- //# sourceMappingURL=host-CGzVFfMz.js.map
7263
+ //# sourceMappingURL=host-CRA7h5A2.js.map