@ghostlytools/cli 1.12.1 → 1.13.1

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 (91) hide show
  1. package/README.md +8 -7
  2. package/dist/assets/{api-jRUXnBdX.js → api-DF36rBJK.js} +2 -2
  3. package/dist/assets/{api-BwEgbvvK.js → api-Dnq86JAA.js} +139 -41
  4. package/dist/assets/api-Dnq86JAA.js.map +1 -0
  5. package/dist/assets/{apiKit-BlsNk-Cx.js → apiKit-nLK4jeTq.js} +3 -3
  6. package/dist/assets/{apiKit-BlsNk-Cx.js.map → apiKit-nLK4jeTq.js.map} +1 -1
  7. package/dist/assets/{appFetch-CW9fJPHh.js → appFetch-wqBWi3Ry.js} +2 -2
  8. package/dist/assets/{appFetch-CW9fJPHh.js.map → appFetch-wqBWi3Ry.js.map} +1 -1
  9. package/dist/assets/{apps-CL8TXHhu.js → apps-DBVhKpfe.js} +10 -10
  10. package/dist/assets/apps-DBVhKpfe.js.map +1 -0
  11. package/dist/assets/{apps-BcG4u6SM.js → apps-nLtyhC2f.js} +1 -1
  12. package/dist/assets/{backup-BA41EDvh.js → backup-Bczllmzf.js} +4 -4
  13. package/dist/assets/{backup-BA41EDvh.js.map → backup-Bczllmzf.js.map} +1 -1
  14. package/dist/assets/{backup-xZfV-ytw.js → backup-D6s0LQdg.js} +1 -1
  15. package/dist/assets/{bitcoind-Dh7n9amb.js → bitcoind-DML_-Xbv.js} +2 -2
  16. package/dist/assets/{bitcoind-Dh7n9amb.js.map → bitcoind-DML_-Xbv.js.map} +1 -1
  17. package/dist/assets/{buttons-SH1tNRh7.js → buttons-B3C3vdhH.js} +30 -9
  18. package/dist/assets/buttons-B3C3vdhH.js.map +1 -0
  19. package/dist/assets/buttons-DaY5FYlV.js +1 -0
  20. package/dist/assets/{client-DGS-atRu.js → client-B7jRrSnb.js} +3 -3
  21. package/dist/assets/{client-DGS-atRu.js.map → client-B7jRrSnb.js.map} +1 -1
  22. package/dist/assets/{domainProofs-BDNP1dIy.js → domainProofs-b3Y1Gj9g.js} +6 -2
  23. package/dist/assets/{domainProofs-BDNP1dIy.js.map → domainProofs-b3Y1Gj9g.js.map} +1 -1
  24. package/dist/assets/{errors-DDLFO4Gf.js → errors-JVJsO8Iu.js} +18 -2
  25. package/dist/assets/errors-JVJsO8Iu.js.map +1 -0
  26. package/dist/assets/{fixedHosts-CPSsGOI2.js → fixedHosts-H3i6o9Iy.js} +2 -2
  27. package/dist/assets/{fixedHosts-CPSsGOI2.js.map → fixedHosts-H3i6o9Iy.js.map} +1 -1
  28. package/dist/assets/{ghostly_iroh_web-DIj5xGmR.js → ghostly_iroh_web-9VOwZcJQ.js} +30 -35
  29. package/dist/assets/ghostly_iroh_web-9VOwZcJQ.js.map +1 -0
  30. package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
  31. package/dist/assets/{groupMeta-DxuJzko_.js → groupMeta--fxSh792.js} +165 -20
  32. package/dist/assets/groupMeta--fxSh792.js.map +1 -0
  33. package/dist/assets/{host-BxM-HMr0.js → host-CGzVFfMz.js} +211 -58
  34. package/dist/assets/host-CGzVFfMz.js.map +1 -0
  35. package/dist/assets/{hyperdhtRelay-bjNGacf5.js → hyperdhtRelay-B4_wdCtx.js} +2 -2
  36. package/dist/assets/{hyperdhtRelay-bjNGacf5.js.map → hyperdhtRelay-B4_wdCtx.js.map} +1 -1
  37. package/dist/assets/{hyperdhtRelay-DLUiwfnt.js → hyperdhtRelay-Ce-gWsRY.js} +2 -2
  38. package/dist/assets/{hyperdhtRelay-DLUiwfnt.js.map → hyperdhtRelay-Ce-gWsRY.js.map} +1 -1
  39. package/dist/assets/{irohWeb-CbnGtUo6.js → irohWeb-Dp1i8v6n.js} +13 -12
  40. package/dist/assets/irohWeb-Dp1i8v6n.js.map +1 -0
  41. package/dist/assets/{main-CwTaepxR.js → main-C8J53SwH.js} +68 -63
  42. package/dist/assets/main-C8J53SwH.js.map +1 -0
  43. package/dist/assets/{mainline-CVrd0C1n.js → mainline-DY95WbuK.js} +2 -2
  44. package/dist/assets/{mainline-CVrd0C1n.js.map → mainline-DY95WbuK.js.map} +1 -1
  45. package/dist/assets/{ownDid-DY3rYqDI.js → ownDid-oa-T2vmZ.js} +9 -5
  46. package/dist/assets/ownDid-oa-T2vmZ.js.map +1 -0
  47. package/dist/assets/{ownStatus-DtzIllg2.js → ownStatus-Bc08eNJY.js} +7 -6
  48. package/dist/assets/ownStatus-Bc08eNJY.js.map +1 -0
  49. package/dist/assets/{pairedTransports-BKmvlKz1.js → pairedTransports-Dppn8lUN.js} +3 -3
  50. package/dist/assets/pairedTransports-Dppn8lUN.js.map +1 -0
  51. package/dist/assets/{profiles-BOYGlmu2.js → profiles-B2uy04ph.js} +3 -3
  52. package/dist/assets/{profiles-BOYGlmu2.js.map → profiles-B2uy04ph.js.map} +1 -1
  53. package/dist/assets/{registry-Bep4umOM.js → registry-DbTLLs3y.js} +9 -5
  54. package/dist/assets/registry-DbTLLs3y.js.map +1 -0
  55. package/dist/assets/{registry-4W1LGlCF.js → registry-bLIfG619.js} +1 -1
  56. package/dist/assets/{relay-Cjfmdec0.js → relay-CHWg5hpZ.js} +73 -11
  57. package/dist/assets/relay-CHWg5hpZ.js.map +1 -0
  58. package/dist/assets/{resolve-CIc3KZMV.js → resolve-DNX-eecG.js} +9 -4
  59. package/dist/assets/resolve-DNX-eecG.js.map +1 -0
  60. package/dist/assets/secretGuard-Bh11MPdI.js +1 -0
  61. package/dist/assets/{secretGuard-BrATm_gl.js → secretGuard-oz_3hBfW.js} +19 -2
  62. package/dist/assets/{secretGuard-BrATm_gl.js.map → secretGuard-oz_3hBfW.js.map} +1 -1
  63. package/dist/assets/{server-D4gf-LnD.js → server-DWJ4RzJn.js} +748 -222
  64. package/dist/assets/server-DWJ4RzJn.js.map +1 -0
  65. package/dist/assets/{translate-BcbSWkuq.js → translate-CHj_PdLg.js} +13 -8
  66. package/dist/assets/translate-CHj_PdLg.js.map +1 -0
  67. package/dist/assets/{waitNotice-DQvZgz2T.js → waitNotice-Cvz5CiKR.js} +57 -3
  68. package/dist/assets/waitNotice-Cvz5CiKR.js.map +1 -0
  69. package/dist/ghostly.mjs +1 -1
  70. package/npm-shrinkwrap.json +2 -2
  71. package/package.json +1 -1
  72. package/dist/assets/api-BwEgbvvK.js.map +0 -1
  73. package/dist/assets/apps-CL8TXHhu.js.map +0 -1
  74. package/dist/assets/buttons-CsGdQNnR.js +0 -1
  75. package/dist/assets/buttons-SH1tNRh7.js.map +0 -1
  76. package/dist/assets/errors-DDLFO4Gf.js.map +0 -1
  77. package/dist/assets/ghostly_iroh_web-DIj5xGmR.js.map +0 -1
  78. package/dist/assets/groupMeta-DxuJzko_.js.map +0 -1
  79. package/dist/assets/host-BxM-HMr0.js.map +0 -1
  80. package/dist/assets/irohWeb-CbnGtUo6.js.map +0 -1
  81. package/dist/assets/main-CwTaepxR.js.map +0 -1
  82. package/dist/assets/ownDid-DY3rYqDI.js.map +0 -1
  83. package/dist/assets/ownStatus-DtzIllg2.js.map +0 -1
  84. package/dist/assets/pairedTransports-BKmvlKz1.js.map +0 -1
  85. package/dist/assets/registry-Bep4umOM.js.map +0 -1
  86. package/dist/assets/relay-Cjfmdec0.js.map +0 -1
  87. package/dist/assets/resolve-CIc3KZMV.js.map +0 -1
  88. package/dist/assets/secretGuard-Bm6nci0I.js +0 -1
  89. package/dist/assets/server-D4gf-LnD.js.map +0 -1
  90. package/dist/assets/translate-BcbSWkuq.js.map +0 -1
  91. package/dist/assets/waitNotice-DQvZgz2T.js.map +0 -1
@@ -1,17 +1,17 @@
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-BwEgbvvK.js";
3
- import { N as sinceSeq, s as findChat, u as findOwnNamedChat } from "./apiKit-BlsNk-Cx.js";
4
- import { r as asCliError, t as CliError } from "./errors-DDLFO4Gf.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-BOYGlmu2.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-DGS-atRu.js";
7
- import { Bi as buildSdpFromSignal, Gi as parseCallSignal, Hi as callSignalHeardAt, Ii as CALL_SIGNAL_MAX_AGE_MS, Ki as signalHasVideo, Ri as RTC_CONFIG, Vi as callRtcConfig, Wi as extractParamsFromSdp, Zt as checkPushEndpoint, bi as DAEMON_WATCH_PEER_IDLE_MS, gn as ACTIVE_DHT_POLL_MS, xt as STATUS_IDLE_AFTER_MS, zi as answersOffer } from "./groupMeta-DxuJzko_.js";
8
- import { d as parsePayLink, r as irohRelayProblem } from "./irohWeb-CbnGtUo6.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";
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";
9
9
  import { i as fromBase64Url } from "./bytes-C1DNGY18.js";
10
- import { u as setLinkTraceSink } from "./relay-Cjfmdec0.js";
10
+ import { u as setLinkTraceSink } from "./relay-CHWg5hpZ.js";
11
11
  import { b as setPublicKeyFastPath } from "./pkarr-BQo4PcCg.js";
12
- import { p as nativePublicKey } from "./apps-CL8TXHhu.js";
12
+ import { p as nativePublicKey } from "./apps-DBVhKpfe.js";
13
13
  import { n as fedimintSdkOn } from "./fedimintSdk-D-6H9Pe7.js";
14
- import { s as isPublicAddress } from "./domainProofs-BDNP1dIy.js";
14
+ import { s as isPublicAddress } from "./domainProofs-b3Y1Gj9g.js";
15
15
  import { createRequire } from "node:module";
16
16
  import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, truncateSync, writeFileSync, writeSync } from "node:fs";
17
17
  import { open, readFile } from "node:fs/promises";
@@ -658,7 +658,7 @@ function envSwitch(name, fallback, env = process.env) {
658
658
  if (value === void 0 || value.trim() === "") return fallback;
659
659
  if (OFF.test(value.trim())) return false;
660
660
  if (ON.test(value.trim())) return true;
661
- throw new CliError("usage", `${name} takes 0 or 1 (or false/true, off/on, no/yes), not ${JSON.stringify(value)}`);
661
+ throw new CliError("usage", `${name} takes 0 or 1 (or false/true, off/on, no/yes), not ${shownValue(value)}`);
662
662
  }
663
663
  // src/runtime/rtcThreads.ts
664
664
  /**
@@ -1232,6 +1232,11 @@ var CallManager = class {
1232
1232
  if (signal.ts <= (this.lastSignal.get(chat) ?? 0)) return;
1233
1233
  const call = this.byChat(chat);
1234
1234
  if (signal.t === "r" || signal.t === "a" && signal.re !== void 0) return;
1235
+ if (signal.t === "o" && call?.state === "connected") {
1236
+ this.lastSignal.set(chat, signal.ts);
1237
+ this.yieldTo(call, signal, "remote-hangup");
1238
+ return;
1239
+ }
1235
1240
  if (call?.state === "connected" && signal.t !== "h" && signal.t !== "v") return;
1236
1241
  if (signal.t === "o" && !call) {
1237
1242
  this.lastSignal.set(chat, signal.ts);
@@ -1271,11 +1276,12 @@ var CallManager = class {
1271
1276
  }
1272
1277
  }
1273
1278
  /**
1274
- * The contact's offer won a glare: our call ends as `crossed`, sending nothing (a hang-up would end the contact's
1275
- * call, and clearing our signal could drop an answer we are about to give), and the contact's call rings here.
1279
+ * The contact's offer won a glare (`crossed`), or came from their app starting over on a connected call
1280
+ * (`remote-hangup`): our call ends, sending no hang-up (it would end the contact's call; a glare's also keeps our
1281
+ * signal, as clearing it could drop an answer we are about to give), and the contact's call rings here.
1276
1282
  */
1277
- async yieldTo(call, offer) {
1278
- await this.end(call, "crossed", false);
1283
+ async yieldTo(call, offer, reason = "crossed") {
1284
+ await this.end(call, reason, false);
1279
1285
  if (this.lastSignal.get(call.chat) !== offer.ts || this.byChat(call.chat) || this.stopping) return;
1280
1286
  this.incoming(call.chat, offer);
1281
1287
  }
@@ -3688,7 +3694,8 @@ var GroupAutoJoin = class {
3688
3694
  * every change of the engine's state. One whose accept fails (the contact is not connected yet) is tried again on a
3689
3695
  * later change. Another contact who knows the group's id may have invited first: the engine then keeps the granted
3690
3696
  * one beside it (`others`), and it is the one taken (`switchGroup`, which tells the other contact no), as long as the
3691
- * group held is only an invitation not answered yet. One beside a group joined or accepted waits for the person.
3697
+ * group held is only an invitation not answered yet. One beside a group joined or accepted, or beside an invitation
3698
+ * that keeps a group this device was in (`kept`: switching would delete its history), waits for the person.
3692
3699
  */
3693
3700
  check(state) {
3694
3701
  if (!this.host.joins || !this.grants.length) return;
@@ -3713,7 +3720,7 @@ var GroupAutoJoin = class {
3713
3720
  const other = group.others?.find((o) => "linkId" in o && granted(o.linkId));
3714
3721
  if (!other || !("linkId" in other)) continue;
3715
3722
  const held = group.invitation;
3716
- if (group.status === void 0 && held && !held.accepted && !held.viaLink) {
3723
+ if (group.status === void 0 && held && !held.accepted && !held.viaLink && !held.kept) {
3717
3724
  this.accept(group.id, other.linkId, true);
3718
3725
  continue;
3719
3726
  }
@@ -4010,6 +4017,46 @@ async function nodePushSend(push, lookup = publicOnlyLookup) {
4010
4017
  req.end(push.body);
4011
4018
  });
4012
4019
  }
4020
+ // src/runtime/groupCallFetch.ts
4021
+ /**
4022
+ * How the CLI asks a group's call node (WISP 602 § The token request, § Moderation) at the origin the group's admin
4023
+ * named: an HTTPS POST only at a public address, or at a name whose every address is public, checked when the
4024
+ * connection is made, as an identity's proof is read (./publicFetch.ts). No redirect is followed (one is answered as it
4025
+ * came: the engine takes only a 2xx), no proxy, no cookie. The engine bounds the time and the size of the reply.
4026
+ */
4027
+ function nodeGroupCallFetch(lookup = publicOnlyLookup) {
4028
+ return async (input, init) => {
4029
+ const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
4030
+ if (url.protocol !== "https:") throw new TypeError("Only HTTPS is sent");
4031
+ if ((init?.method ?? "GET").toUpperCase() !== "POST") throw new TypeError("Only POST is sent");
4032
+ const host = url.hostname.replace(/^\[|\]$/g, "");
4033
+ if (isIP(host) && !isPublicIp(host)) throw new TypeError(`${host} is not a public address`);
4034
+ const body = typeof init?.body === "string" ? init.body : "";
4035
+ const headers = {
4036
+ ...Object.fromEntries(new Headers(init?.headers)),
4037
+ "content-length": String(Buffer.byteLength(body))
4038
+ };
4039
+ return new Promise((resolve, reject) => {
4040
+ const req = request(url, {
4041
+ method: "POST",
4042
+ headers,
4043
+ lookup,
4044
+ agent: false,
4045
+ signal: init?.signal ?? void 0
4046
+ }, (res) => {
4047
+ const out = new Headers();
4048
+ for (const [name, value] of Object.entries(res.headers)) if (typeof value === "string") out.set(name, value);
4049
+ const status = res.statusCode ?? 0;
4050
+ resolve(new Response(status === 204 || status === 304 ? null : Readable.toWeb(res), {
4051
+ status,
4052
+ headers: out
4053
+ }));
4054
+ });
4055
+ req.on("error", reject);
4056
+ req.end(body);
4057
+ });
4058
+ };
4059
+ }
4013
4060
  // src/runtime/holdFetch.ts
4014
4061
  /**
4015
4062
  * How the CLI reads a held item or manifest (WISP 404): a GET to the address the contact chose, only
@@ -4089,6 +4136,23 @@ function nodePublicFetch(lookup = publicOnlyLookup) {
4089
4136
  }
4090
4137
  };
4091
4138
  }
4139
+ /**
4140
+ * How the CLI asks a Lightning address or LNURL service (WISP 205 § Transport), its redirects and its callback: as an
4141
+ * identity's address, at a name whose every address is public when it connects. The engine follows each redirect
4142
+ * itself (`redirect: "manual"`) and checks names only. A service the person named on this machine itself (a test
4143
+ * server, plain HTTP allowed) is asked as named.
4144
+ */
4145
+ function nodeLnurlFetch(lookup = publicOnlyLookup, local = (...request) => globalThis.fetch(...request)) {
4146
+ const publicFetch = nodePublicFetch(lookup);
4147
+ return (input, init) => {
4148
+ const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
4149
+ return [
4150
+ "localhost",
4151
+ "127.0.0.1",
4152
+ "[::1]"
4153
+ ].includes(url.hostname) ? local(input, init) : publicFetch(input, init);
4154
+ };
4155
+ }
4092
4156
  // src/runtime/irohRelay.ts
4093
4157
  /**
4094
4158
  * Whether the CLI's Iroh may dial a contact through the relay its descriptor names (irohWeb.ts `publicRelay`): at a
@@ -4823,6 +4887,8 @@ var SEQ = "__ghostly_entry__";
4823
4887
  var CLOSE_WAIT_MS = 5e3;
4824
4888
  /** Records an export reads and serializes in one turn of the event loop, then writes: a few milliseconds' worth. */
4825
4889
  var EXPORT_PAGE = 256;
4890
+ /** How long a fold's snapshot serializes records before it writes them and lets the daemon's other work run. */
4891
+ var PAGE_MS = 5;
4826
4892
  /** How long a relaxed transaction's entry may wait for a sync when no other transaction brings one. */
4827
4893
  var RELAXED_SYNC_MS = 1e3;
4828
4894
  /**
@@ -4873,6 +4939,8 @@ async function openPersistentIndexedDb(dir, options = {}) {
4873
4939
  let unsynced = [];
4874
4940
  /** The syncs running off the thread, one after another, until no `complete` waits for one. */
4875
4941
  let syncing = null;
4942
+ /** The `complete`s of transactions whose entries wait in the queue (`append`). */
4943
+ let held = 0;
4876
4944
  /** The last journal entry whose layers wait for `applying` to take them to SQLite. */
4877
4945
  let applyUpTo = 0;
4878
4946
  let applying = null;
@@ -5027,17 +5095,17 @@ async function openPersistentIndexedDb(dir, options = {}) {
5027
5095
  const ops = pending.get(this._rollbackLog);
5028
5096
  if (!ops?.length) trees?.abort(this._rollbackLog);
5029
5097
  if (ops?.length) entry = ++seq;
5030
- const appended = ops?.length ? append(ops, this.durability === "relaxed", entry, this._rollbackLog) : null;
5031
- if (appended && appended !== "unsynced") return refuse(this, appended.error, event);
5032
- waits = appended === "unsynced";
5098
+ const appended = ops?.length ? append(ops, this.durability === "relaxed", entry, this._rollbackLog, () => dispatch.call(this, event)) : null;
5099
+ if (appended && typeof appended === "object") return refuse(this, appended.error, event);
5100
+ waits = appended !== null;
5101
+ if (appended === "unsynced") shareSync(() => {
5102
+ written(entry);
5103
+ dispatch.call(this, event);
5104
+ });
5033
5105
  }
5034
5106
  pending.delete(this._rollbackLog);
5035
5107
  if (schemaDirty) enqueue(writeSnapshot);
5036
5108
  if (waits) {
5037
- shareSync(() => {
5038
- written(entry);
5039
- dispatch.call(this, event);
5040
- });
5041
5109
  this.db._rawDatabase.processTransactions(event);
5042
5110
  return true;
5043
5111
  }
@@ -5060,9 +5128,13 @@ async function openPersistentIndexedDb(dir, options = {}) {
5060
5128
  * A committed transaction's entry, numbered `entry` (its first op says so, where there are trees), from the
5061
5129
  * transaction whose rollback log is `owner`. Written at once, it may fail (a full disk): the reason is given back,
5062
5130
  * and the transaction is to be refused, not completed. "unsynced": written, and its `complete` waits for a sync.
5131
+ * "queued": written behind what the queue holds (a fold, a Blob's entry), and `complete` called once it is: what
5132
+ * completed before was on no disk while the fold waited for the sync in flight, and a process killed then lost a
5133
+ * text the engine had told the contact it held.
5063
5134
  */
5064
- function append(ops, lazy, entry, owner) {
5065
- holdsDelete ||= ops.some(deletes);
5135
+ function append(ops, lazy, entry, owner, complete) {
5136
+ const deleting = ops.some(deletes);
5137
+ holdsDelete ||= deleting;
5066
5138
  if (trees) ops = [{
5067
5139
  db: SEQ,
5068
5140
  store: "",
@@ -5082,13 +5154,25 @@ async function openPersistentIndexedDb(dir, options = {}) {
5082
5154
  return null;
5083
5155
  }
5084
5156
  trees?.complete(owner, entry);
5157
+ held++;
5085
5158
  enqueue(async () => {
5086
- if (writeEntry(serialize(await Promise.all(ops.map(async (op) => op.kind === "put" ? {
5087
- ...op,
5088
- value: await blobsToDisk(op.value)
5089
- } : op))), lazy ? "lazy" : "now")) written(entry);
5159
+ try {
5160
+ if (writeEntry(serialize(await Promise.all(ops.map(async (op) => op.kind === "put" ? {
5161
+ ...op,
5162
+ value: await blobsToDisk(op.value)
5163
+ } : op))), lazy ? "lazy" : "now")) {
5164
+ holdsDelete ||= deleting;
5165
+ written(entry);
5166
+ }
5167
+ } catch (error) {
5168
+ failed(error);
5169
+ await writeSnapshot().catch(failed);
5170
+ }
5171
+ }).then(() => {
5172
+ held--;
5173
+ complete();
5090
5174
  });
5091
- return null;
5175
+ return "queued";
5092
5176
  }
5093
5177
  /**
5094
5178
  * A transaction whose entry the disk did not take: what it wrote is undone (as fake-indexeddb's own abort does), and
@@ -5237,7 +5321,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
5237
5321
  * (5 ms on a Mac's SSD, where it flushes the drive's cache), one per transaction: 8 sends at once went no faster than
5238
5322
  * 1, and every other call waited behind them. It runs off the thread now, and every entry written while it runs
5239
5323
  * goes with the next one. One that fails leaves what the journal has unsure: the store is folded into a whole
5240
- * snapshot before the `complete`s go (they go even if that fails, as a Blob's entry written late does).
5324
+ * snapshot before the `complete`s go (they go even if that fails, as a queued entry's does).
5241
5325
  */
5242
5326
  function shareSync(done) {
5243
5327
  unsynced.push(done);
@@ -5295,7 +5379,10 @@ async function openPersistentIndexedDb(dir, options = {}) {
5295
5379
  }))
5296
5380
  };
5297
5381
  }
5298
- /** What is held, as a snapshot of format 3: the stores kept on disk say only that they are. */
5382
+ /**
5383
+ * What is held, as a snapshot of format 3: the stores kept on disk say only that they are. `upTo`: the last entry it
5384
+ * holds, the transactions whose layers go to the trees with it.
5385
+ */
5299
5386
  async function capture(journalName) {
5300
5387
  const snapshot = {
5301
5388
  format: 1,
@@ -5320,9 +5407,8 @@ async function openPersistentIndexedDb(dir, options = {}) {
5320
5407
  }
5321
5408
  const saved = {
5322
5409
  ...storeMeta(store),
5323
- records: []
5410
+ records: treeRecords(store.records).map(({ key, value }) => [key, value])
5324
5411
  };
5325
- for (const record of store.records.values()) saved.records.push([record.key, record.value]);
5326
5412
  stores.push(saved);
5327
5413
  held.push(saved);
5328
5414
  }
@@ -5332,8 +5418,12 @@ async function openPersistentIndexedDb(dir, options = {}) {
5332
5418
  stores
5333
5419
  });
5334
5420
  }
5335
- for (const store of held) for (const record of store.records) record[1] = await blobsToDisk(record[1]);
5336
- return snapshot;
5421
+ const upTo = seq;
5422
+ for (const store of held) for (const record of store.records) if (hasBlob(record[1])) record[1] = await blobsToDisk(record[1]);
5423
+ return {
5424
+ snapshot,
5425
+ upTo
5426
+ };
5337
5427
  }
5338
5428
  /**
5339
5429
  * The whole store as a snapshot of format 1 (every value inline, `rows.db` read), written to `file` as it is read: a
@@ -5414,29 +5504,34 @@ async function openPersistentIndexedDb(dir, options = {}) {
5414
5504
  }
5415
5505
  async function snapshotToDisk(scrub = false) {
5416
5506
  await synced();
5417
- const name = randomBytes(8).toString("hex");
5418
- const snapshot = await capture(name);
5419
- if (trees) {
5420
- trees.apply(seq);
5421
- if (scrub) trees.scrub();
5422
- trees.sync();
5507
+ if (relaxed) {
5508
+ clearTimeout(relaxed);
5509
+ relaxed = null;
5423
5510
  }
5511
+ const name = randomBytes(8).toString("hex");
5512
+ const { snapshot, upTo } = await capture(name);
5513
+ const live = trees ? liveTrees() : null;
5514
+ unsaved = false;
5424
5515
  const temporary = snapshotPath + ".tmp";
5425
- const fd = openSync(temporary, "w", 384);
5516
+ const file = await open(temporary, "w", 384);
5426
5517
  try {
5427
- writeAll(fd, serialize(snapshot));
5428
- fsyncSync(fd);
5518
+ await writeSnapshotTo(file, snapshot);
5519
+ await file.sync();
5429
5520
  } finally {
5430
- closeSync(fd);
5521
+ await file.close();
5522
+ }
5523
+ if (trees) {
5524
+ trees.apply(upTo);
5525
+ if (scrub) trees.scrub();
5526
+ trees.sync();
5431
5527
  }
5432
5528
  renameSync(temporary, snapshotPath);
5433
5529
  try {
5434
- trees?.sweep(liveTrees());
5530
+ if (live) trees.sweep(/* @__PURE__ */ new Set([...live, ...liveTrees()]));
5435
5531
  } catch (error) {
5436
5532
  process.stderr.write(`ghostly: storage: old trees not removed: ${error instanceof Error ? error.message : String(error)}\n`);
5437
5533
  }
5438
5534
  snapshotName = name;
5439
- unsaved = false;
5440
5535
  if (relaxed) {
5441
5536
  clearTimeout(relaxed);
5442
5537
  relaxed = null;
@@ -5478,9 +5573,9 @@ async function openPersistentIndexedDb(dir, options = {}) {
5478
5573
  quiet = busy() ? 0 : quiet + 1;
5479
5574
  }
5480
5575
  }
5481
- /** Whether a transaction is running or waiting to, or for the sync that tells the engine it completed. */
5576
+ /** Whether a transaction is running or waiting to, or for the sync or the queued write that tells the engine it completed. */
5482
5577
  function busy() {
5483
- return syncing !== null || [...raw._databases.values()].some((db) => db.transactions.some((transaction) => transaction._state !== "finished"));
5578
+ return syncing !== null || held > 0 || [...raw._databases.values()].some((db) => db.transactions.some((transaction) => transaction._state !== "finished"));
5484
5579
  }
5485
5580
  const installed = globalThis;
5486
5581
  installed.indexedDB = factory;
@@ -5528,6 +5623,44 @@ function writeAll(fd, bytes) {
5528
5623
  for (let at = 0; at < bytes.length;) at += writeSync(fd, bytes, at);
5529
5624
  }
5530
5625
  /**
5626
+ * A snapshot to `file`, its records `EXPORT_PAGE` at a time (or fewer, large ones: `PAGE_MS` of the thread) with a write
5627
+ * between: what `serialize(snapshot)` would write.
5628
+ */
5629
+ async function writeSnapshotTo(file, snapshot) {
5630
+ const out = new SnapshotWriter(file);
5631
+ const { databases, ...head } = snapshot;
5632
+ out.begin("o");
5633
+ for (const [key, value] of Object.entries(head)) out.value(key, value);
5634
+ out.key("databases");
5635
+ out.begin("A", databases.length);
5636
+ for (const { stores, ...db } of databases) {
5637
+ out.begin("o");
5638
+ for (const [key, value] of Object.entries(db)) out.value(key, value);
5639
+ out.key("stores");
5640
+ out.begin("A", stores.length);
5641
+ for (const { records, ...meta } of stores) {
5642
+ out.begin("o");
5643
+ for (const [key, value] of Object.entries(meta)) out.value(key, value);
5644
+ out.key("records");
5645
+ out.begin("A", records.length);
5646
+ let due = performance.now() + PAGE_MS;
5647
+ for (let at = 0; at < records.length; at++) {
5648
+ out.item(records[at]);
5649
+ if ((at + 1) % EXPORT_PAGE !== 0 && performance.now() < due) continue;
5650
+ await out.flush();
5651
+ due = performance.now() + PAGE_MS;
5652
+ }
5653
+ out.end("A", records.length);
5654
+ out.end("o", Object.keys(meta).length + 1);
5655
+ }
5656
+ out.end("A", stores.length);
5657
+ out.end("o", Object.keys(db).length + 1);
5658
+ }
5659
+ out.end("A", databases.length);
5660
+ out.end("o", Object.keys(head).length + 1);
5661
+ await out.flush();
5662
+ }
5663
+ /**
5531
5664
  * A value v8 would serialize whole, written in pieces: the objects and arrays around the records begun and ended here
5532
5665
  * by hand, as v8 itself writes them, and the records serialized a page at a time, each page's bytes to `file`. A reader
5533
5666
  * gets what `deserialize` of `serialize(value)` gives (the bytes differ at most by v8's alignment padding before a
@@ -6051,6 +6184,24 @@ function absent(keyPath, value) {
6051
6184
  return false;
6052
6185
  }
6053
6186
  /**
6187
+ * A store's records in key order, read off fake-indexeddb's red-black tree node by node: its own iterator nests a
6188
+ * generator per level and checks the range at each node, 360 ms of the daemon's thread for a seen set of 300,000 notes.
6189
+ */
6190
+ function treeRecords(store) {
6191
+ const records = [], above = [];
6192
+ for (let node = store.records._root; node || above.length;) {
6193
+ if (node) {
6194
+ above.push(node);
6195
+ node = node.left;
6196
+ continue;
6197
+ }
6198
+ node = above.pop();
6199
+ if (!node.deleted) records.push(node.record);
6200
+ node = node.right;
6201
+ }
6202
+ return records;
6203
+ }
6204
+ /**
6054
6205
  * fake-indexeddb's red-black tree, built balanced from sorted records: every level full but the last, whose nodes
6055
6206
  * are red, so each path holds the same number of black nodes and later inserts rebalance as usual.
6056
6207
  */
@@ -6335,7 +6486,7 @@ function bootstrapNodes(name, env) {
6335
6486
  const port = /^[^\s:;/@[\]]+:(\d{1,5})$/.exec(node)?.[1];
6336
6487
  return !port || Number(port) < 1 || Number(port) > 65535;
6337
6488
  });
6338
- if (bad !== void 0) throw new CliError("usage", `${name} takes host:port nodes, comma-separated, not ${JSON.stringify(bad)}`);
6489
+ if (bad !== void 0) throw new CliError("usage", `${name} takes host:port nodes, comma-separated, not ${shownValue(bad)}`);
6339
6490
  return nodes;
6340
6491
  }
6341
6492
  /**
@@ -6347,7 +6498,7 @@ function pkarrRelays(env = process.env) {
6347
6498
  const relays = (env.GHOSTLY_PKARR_RELAYS ?? "").split(",").map((url) => url.trim()).filter(Boolean);
6348
6499
  if (!relays.length) return null;
6349
6500
  const bad = relays.find((url) => !/^https?:\/\/[^/\s]/i.test(url) || /[\s;]/.test(url) || !URL.canParse(url));
6350
- if (bad) throw new CliError("usage", `GHOSTLY_PKARR_RELAYS takes http:// or https:// URLs, comma-separated, not ${JSON.stringify(bad)}`);
6501
+ if (bad) throw new CliError("usage", `GHOSTLY_PKARR_RELAYS takes http:// or https:// URLs, comma-separated, not ${shownValue(bad)}`);
6351
6502
  return relays;
6352
6503
  }
6353
6504
  /**
@@ -6561,12 +6712,12 @@ async function startRuntime(paths, options = {}) {
6561
6712
  if (testMints) (await import("./mints-BcBODVVW.js")).declareTestMints(testMints.split(","));
6562
6713
  await installEventSource();
6563
6714
  await preloadWalletModules();
6564
- (await import("./ghostly_iroh_web-DIj5xGmR.js")).initSync({ module: irohWasmBytes() });
6715
+ (await import("./ghostly_iroh_web-9VOwZcJQ.js")).initSync({ module: irohWasmBytes() });
6565
6716
  const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-CCKbwqG_.js"), import("./fileBytes-tj6-VZcB.js")]);
6566
6717
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
6567
6718
  if (await (await import("./blobFiles-DDs34n0r.js")).moveBlobFiles()) await store.compact();
6568
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-D4gf-LnD.js"), import("./endpoint-Cvu-taMs.js")]);
6569
- const mainline = dht.off ? null : new (await (import("./mainline-CVrd0C1n.js"))).Mainline({
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({
6570
6721
  bootstrap: dht.bootstrap,
6571
6722
  host: dht.host
6572
6723
  });
@@ -6574,7 +6725,7 @@ async function startRuntime(paths, options = {}) {
6574
6725
  ...pinned ? { relays: pinned } : {},
6575
6726
  ...relayBudgetForTests()
6576
6727
  };
6577
- const transport = mainline || pinned ? new (await (import("./mainline-CVrd0C1n.js"))).RelaysAndDht(mainline, relayOptions, !!pinned) : null;
6728
+ const transport = mainline || pinned ? new (await (import("./mainline-DY95WbuK.js"))).RelaysAndDht(mainline, relayOptions, !!pinned) : null;
6578
6729
  const apps = servedApps(paths.dir).length > 0;
6579
6730
  const server = new EngineServer({
6580
6731
  ...transport ? { transport } : {},
@@ -6594,6 +6745,8 @@ async function startRuntime(paths, options = {}) {
6594
6745
  pushSend: (request) => nodePushSend(request),
6595
6746
  holdFetch: nodeHoldFetch(),
6596
6747
  identityFetch: nodePublicFetch(),
6748
+ groupCallFetch: nodeGroupCallFetch(),
6749
+ lnurlFetch: nodeLnurlFetch(),
6597
6750
  webrtcIgnoresRelayOnly: true,
6598
6751
  callsSupport: callsUnavailable === null,
6599
6752
  ...callsUnavailable ? { callsUnavailable } : {},
@@ -7034,4 +7187,4 @@ function connection(ctx, socket, secret, answering) {
7034
7187
  }
7035
7188
  export { BASELINE_NEWEST, MAX_UNREAD, STOP_ANSWERS_MS, keepServing, openHost, serve };
7036
7189
 
7037
- //# sourceMappingURL=host-BxM-HMr0.js.map
7190
+ //# sourceMappingURL=host-CGzVFfMz.js.map