@ghostlytools/cli 1.5.2 → 1.5.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.
Files changed (101) hide show
  1. package/README.md +16 -11
  2. package/dist/assets/{api-CHD8_kcJ.js → api-BIg0Msax.js} +2 -2
  3. package/dist/assets/{api-CMohP9Pw.js → api-d2aXkbM5.js} +341 -114
  4. package/dist/assets/api-d2aXkbM5.js.map +1 -0
  5. package/dist/assets/{apiKit-CfwVtBcw.js → apiKit-Ba_t7MZO.js} +4 -4
  6. package/dist/assets/apiKit-Ba_t7MZO.js.map +1 -0
  7. package/dist/assets/{apps-733nXRBy.js → apps-B_F3gEI4.js} +1 -1
  8. package/dist/assets/{apps-LG-QOIxs.js → apps-CJo1MmSY.js} +17 -16
  9. package/dist/assets/apps-CJo1MmSY.js.map +1 -0
  10. package/dist/assets/{arkade-C8x3Efyj.js → arkade-DTne0O3Q.js} +12 -5
  11. package/dist/assets/arkade-DTne0O3Q.js.map +1 -0
  12. package/dist/assets/{backup-CfJenOQo.js → backup-BY88aZr5.js} +11 -8
  13. package/dist/assets/backup-BY88aZr5.js.map +1 -0
  14. package/dist/assets/{backup-nCbNWJ7-.js → backup-CqpDAZZG.js} +1 -1
  15. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  16. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  17. package/dist/assets/{blobFiles-1wUBd8ZD.js → blobFiles-B1lX6iGy.js} +3 -3
  18. package/dist/assets/{blobFiles-1wUBd8ZD.js.map → blobFiles-B1lX6iGy.js.map} +1 -1
  19. package/dist/assets/{buttons-BC0stvPg.js → buttons-B5EnA2nh.js} +23 -6
  20. package/dist/assets/buttons-B5EnA2nh.js.map +1 -0
  21. package/dist/assets/buttons-azvbN6xn.js +2 -0
  22. package/dist/assets/{daemonProof-CWTVNUmr.js → daemonProof-Dx3N_DLC.js} +19 -37
  23. package/dist/assets/daemonProof-Dx3N_DLC.js.map +1 -0
  24. package/dist/assets/{endpoint-Cl3cgAYl.js → endpoint-BdaeBw2L.js} +3 -3
  25. package/dist/assets/endpoint-BdaeBw2L.js.map +1 -0
  26. package/dist/assets/{envelope-BbvUBjc5.js → envelope-BU-BB1wR.js} +2 -2
  27. package/dist/assets/{envelope-BbvUBjc5.js.map → envelope-BU-BB1wR.js.map} +1 -1
  28. package/dist/assets/{errors-BLSPp0tK.js → errors-DI6Z3jTH.js} +26 -1
  29. package/dist/assets/errors-DI6Z3jTH.js.map +1 -0
  30. package/dist/assets/{fileBytes-gTd_8l-P.js → fileBytes-BMlLVdfg.js} +1 -1
  31. package/dist/assets/{fileBytes-uRqLyxa0.js → fileBytes-D0CYuRwZ.js} +2 -2
  32. package/dist/assets/{fileBytes-uRqLyxa0.js.map → fileBytes-D0CYuRwZ.js.map} +1 -1
  33. package/dist/assets/{fileBytes-B8eTZfAT.js → fileBytes-D85lBh-Q.js} +3 -3
  34. package/dist/assets/{fileBytes-B8eTZfAT.js.map → fileBytes-D85lBh-Q.js.map} +1 -1
  35. package/dist/assets/fileBytesIdb-Dn9levD1.js +2 -0
  36. package/dist/assets/{fileBytesIdb-BIFKtgln.js → fileBytesIdb-LAhH7kY2.js} +7 -7
  37. package/dist/assets/fileBytesIdb-LAhH7kY2.js.map +1 -0
  38. package/dist/assets/{fileBytesOpfs-ChrHcCVV.js → fileBytesOpfs-DjBBghvq.js} +3 -3
  39. package/dist/assets/{fileBytesOpfs-ChrHcCVV.js.map → fileBytesOpfs-DjBBghvq.js.map} +1 -1
  40. package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js → ghostly_iroh_web-BXCsSxxo.js} +29 -29
  41. package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js.map → ghostly_iroh_web-BXCsSxxo.js.map} +1 -1
  42. package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
  43. package/dist/assets/{groupFiles-Bmo-SkVQ.js → groupFiles-D9k6fyhf.js} +61 -17
  44. package/dist/assets/groupFiles-D9k6fyhf.js.map +1 -0
  45. package/dist/assets/{host-DxDRCRKD.js → host-DrL7FPG4.js} +125 -47
  46. package/dist/assets/host-DrL7FPG4.js.map +1 -0
  47. package/dist/assets/{hyperdhtRelay-CZfsPfT9.js → hyperdhtRelay-C-BsT6_V.js} +2 -2
  48. package/dist/assets/{hyperdhtRelay-CZfsPfT9.js.map → hyperdhtRelay-C-BsT6_V.js.map} +1 -1
  49. package/dist/assets/{idb-BJARz3Qi.js → idb-CWvq4HKc.js} +25 -3
  50. package/dist/assets/{idb-BJARz3Qi.js.map → idb-CWvq4HKc.js.map} +1 -1
  51. package/dist/assets/{irohWeb-BUvaADop.js → irohWeb-DdHXEwgj.js} +3 -3
  52. package/dist/assets/{irohWeb-BUvaADop.js.map → irohWeb-DdHXEwgj.js.map} +1 -1
  53. package/dist/assets/{main-BIXIs84L.js → main-xeoX7yLM.js} +160 -50
  54. package/dist/assets/main-xeoX7yLM.js.map +1 -0
  55. package/dist/assets/{mainline-HQVJ5ukA.js → mainline-CEqGvRYJ.js} +46 -16
  56. package/dist/assets/mainline-CEqGvRYJ.js.map +1 -0
  57. package/dist/assets/{networkReason-CKBiFTwt.js → networkReason-RGRU5xoa.js} +3 -3
  58. package/dist/assets/{networkReason-CKBiFTwt.js.map → networkReason-RGRU5xoa.js.map} +1 -1
  59. package/dist/assets/{nwc-Dm4RSvvF.js → nwc-s5xHLqNf.js} +3 -3
  60. package/dist/assets/{nwc-Dm4RSvvF.js.map → nwc-s5xHLqNf.js.map} +1 -1
  61. package/dist/assets/{nwcProvider-yQdL-DfC.js → nwcProvider-CfAFO5Fr.js} +2 -2
  62. package/dist/assets/{nwcProvider-yQdL-DfC.js.map → nwcProvider-CfAFO5Fr.js.map} +1 -1
  63. package/dist/assets/{profiles-BehWURA9.js → profiles-gZdQPyaz.js} +74 -13
  64. package/dist/assets/profiles-gZdQPyaz.js.map +1 -0
  65. package/dist/assets/{registry-CHVZ0Jzl.js → registry-BUhSjM-J.js} +1 -1
  66. package/dist/assets/{registry-C9f2Ogff.js → registry-CVUdD4bJ.js} +3 -3
  67. package/dist/assets/{registry-C9f2Ogff.js.map → registry-CVUdD4bJ.js.map} +1 -1
  68. package/dist/assets/{resolve-Cqj1jjK2.js → resolve-uZECJ3f7.js} +2 -2
  69. package/dist/assets/{resolve-Cqj1jjK2.js.map → resolve-uZECJ3f7.js.map} +1 -1
  70. package/dist/assets/{restoredRows-DGuKtIBz.js → restoredRows-D6WZUA2U.js} +2 -2
  71. package/dist/assets/{restoredRows-DGuKtIBz.js.map → restoredRows-D6WZUA2U.js.map} +1 -1
  72. package/dist/assets/{server-CcAs54Yb.js → server-DOtUKoYR.js} +776 -248
  73. package/dist/assets/server-DOtUKoYR.js.map +1 -0
  74. package/dist/assets/{src-BLHey3Q1.js → src-Dd_7Ew1X.js} +459 -129
  75. package/dist/assets/src-Dd_7Ew1X.js.map +1 -0
  76. package/dist/assets/{usdt-DMKpMhdM.js → usdt-C2Anx8p7.js} +3 -3
  77. package/dist/assets/{usdt-DMKpMhdM.js.map → usdt-C2Anx8p7.js.map} +1 -1
  78. package/dist/assets/{words-DUlvkoUT.js → words-DoLU6p8H.js} +4 -4
  79. package/dist/assets/words-DoLU6p8H.js.map +1 -0
  80. package/dist/ghostly.mjs +1 -1
  81. package/package.json +1 -1
  82. package/dist/assets/api-CMohP9Pw.js.map +0 -1
  83. package/dist/assets/apiKit-CfwVtBcw.js.map +0 -1
  84. package/dist/assets/apps-LG-QOIxs.js.map +0 -1
  85. package/dist/assets/arkade-C8x3Efyj.js.map +0 -1
  86. package/dist/assets/backup-CfJenOQo.js.map +0 -1
  87. package/dist/assets/buttons-BC0stvPg.js.map +0 -1
  88. package/dist/assets/buttons-BDKeKyKw.js +0 -2
  89. package/dist/assets/daemonProof-CWTVNUmr.js.map +0 -1
  90. package/dist/assets/endpoint-Cl3cgAYl.js.map +0 -1
  91. package/dist/assets/errors-BLSPp0tK.js.map +0 -1
  92. package/dist/assets/fileBytesIdb-BIFKtgln.js.map +0 -1
  93. package/dist/assets/fileBytesIdb-BVVr_rWX.js +0 -2
  94. package/dist/assets/groupFiles-Bmo-SkVQ.js.map +0 -1
  95. package/dist/assets/host-DxDRCRKD.js.map +0 -1
  96. package/dist/assets/main-BIXIs84L.js.map +0 -1
  97. package/dist/assets/mainline-HQVJ5ukA.js.map +0 -1
  98. package/dist/assets/profiles-BehWURA9.js.map +0 -1
  99. package/dist/assets/server-CcAs54Yb.js.map +0 -1
  100. package/dist/assets/src-BLHey3Q1.js.map +0 -1
  101. package/dist/assets/words-DUlvkoUT.js.map +0 -1
@@ -1,12 +1,12 @@
1
- import { Ao as CALL_SIGNAL_MAX_AGE_MS, Fo as callSignalHeardAt, Lo as extractParamsFromSdp, Mo as answersOffer, No as buildSdpFromSignal, Po as callRtcConfig, Ro as parseCallSignal, Si as isPublicAddress, Ul as setLinkTraceSink, Xr as checkPushEndpoint, jo as RTC_CONFIG, lu as fromBase64Url, zo as signalHasVideo } from "./src-BLHey3Q1.js";
2
- import { a as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-BUvaADop.js";
3
- import { r as asCliError, t as CliError } from "./errors-BLSPp0tK.js";
4
- import { a as findChat, c as findOwnNamedChat } from "./apiKit-CfwVtBcw.js";
5
- import { _ as flushCardUpdates, c as paymentJson, d as nodeLocalFetch, f as chatJson, g as resumeHolds, h as groupMessageJson, l as reportAppFrames, m as groupJson, p as chatMessageJson, r as callApi, u as servedApps } from "./api-CMohP9Pw.js";
6
- import { n as RESTORED_MARK, r as acquireLock } from "./profiles-BehWURA9.js";
7
- import { _ as ownFolder, a as proof, d as DEFAULT_RATE, f as PlaybackQueue, g as isCallRate, h as frameSamples, l as removeDaemonSecret, m as frameBytes, n as greeting, p as bytesToMs, r as newDaemonSecret, y as privateFolder } from "./daemonProof-CWTVNUmr.js";
1
+ import { Fo as RTC_CONFIG, Ho as parseCallSignal, Io as answersOffer, Jl as setLinkTraceSink, Lo as buildSdpFromSignal, Po as CALL_SIGNAL_MAX_AGE_MS, Qr as checkPushEndpoint, Ro as callRtcConfig, Uo as signalHasVideo, Vo as extractParamsFromSdp, mu as fromBase64Url, wi as isPublicAddress, zo as callSignalHeardAt } from "./src-Dd_7Ew1X.js";
2
+ import { a as fedimintSdkOn, r as irohRelayProblem } from "./irohWeb-DdHXEwgj.js";
3
+ import { r as asCliError, t as CliError } from "./errors-DI6Z3jTH.js";
4
+ import { a as findChat, c as findOwnNamedChat } from "./apiKit-Ba_t7MZO.js";
5
+ import { _ as flushCardUpdates, c as paymentJson, d as nodeLocalFetch, f as chatJson, g as resumeHolds, h as groupMessageJson, l as reportAppFrames, m as groupJson, p as chatMessageJson, r as callApi, u as servedApps } from "./api-d2aXkbM5.js";
6
+ import { g as ownFolder, n as RESTORED_MARK, r as acquireLock, v as privateFolder, y as runtimePath } from "./profiles-gZdQPyaz.js";
7
+ import { _ as isCallRate, f as DEFAULT_RATE, g as frameSamples, h as frameBytes, i as newDaemonSecret, m as bytesToMs, o as proof, p as PlaybackQueue, r as greeting, u as removeDaemonSecret } from "./daemonProof-Dx3N_DLC.js";
8
8
  import { createRequire } from "node:module";
9
- import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
9
+ import { appendFileSync, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
10
10
  import { readFile } from "node:fs/promises";
11
11
  import { dirname, join } from "node:path";
12
12
  import { createHash, randomBytes } from "node:crypto";
@@ -49,14 +49,14 @@ function announceJoins(hub, node) {
49
49
  //#region src/calls/audioSocket.ts
50
50
  /**
51
51
  * A call's audio socket (WISP 1100 § Calls): `<profile>/calls/<call>.sock`, 0600, in a folder only the owner may
52
- * open. When that path is too long for a Unix socket: `/tmp/ghostly-calls-<hash of the profile>/<call>.sock`, in a
53
- * folder of the owner's, 0700, checked as such before use. A named pipe on Windows.
52
+ * open. When that path is too long for a Unix socket: `ghostly-calls-<hash of the profile>/<call>.sock` in the user's
53
+ * runtime folder (`runtimePath`), a folder of the owner's, 0700, checked as such before use. A named pipe on Windows.
54
54
  */
55
55
  function audioSocketPath(profileDir, callId) {
56
56
  const inside = join(profileDir, "calls", `${callId}.sock`);
57
57
  if (process.platform === "win32") return `\\\\.\\pipe\\ghostly-call-${createHash("sha256").update(inside).digest("hex").slice(0, 24)}`;
58
58
  if (Buffer.byteLength(inside) <= 100) return inside;
59
- return join("/tmp", `ghostly-calls-${createHash("sha256").update(profileDir).digest("hex").slice(0, 24)}`, `${callId}.sock`);
59
+ return runtimePath("ghostly-calls", profileDir, `${callId}.sock`);
60
60
  }
61
61
  /**
62
62
  * Removes the call sockets a daemon that died during a call left in this profile's folder (`audioSocketPath`; call
@@ -288,6 +288,8 @@ var CallAudio = class {
288
288
  lastQuiet = null;
289
289
  same = 0;
290
290
  quiet = null;
291
+ /** Whether the encoder's FEC is on (`OpusCodec.fec`); unknown until the first frame. */
292
+ fecOn;
291
293
  stopped = false;
292
294
  /** Frames sent and received, for `call list`. */
293
295
  sent = 0;
@@ -328,6 +330,12 @@ var CallAudio = class {
328
330
  let payload;
329
331
  if (still && this.quiet) payload = this.quiet;
330
332
  else {
333
+ if (this.fecOn !== !still) {
334
+ this.fecOn = !still;
335
+ try {
336
+ this.options.encoder.fec?.(!still);
337
+ } catch {}
338
+ }
331
339
  try {
332
340
  payload = this.options.encoder.encode(frame, this.samples);
333
341
  } catch {
@@ -464,10 +472,30 @@ var CallAudio = class {
464
472
  }
465
473
  };
466
474
  //#endregion
475
+ //#region src/envSwitch.ts
476
+ var OFF = /^(0|false|off|no)$/i;
477
+ var ON = /^(1|true|on|yes)$/i;
478
+ /**
479
+ * An on/off environment switch (`GHOSTLY_DHT`, `GHOSTLY_STUN`, `GHOSTLY_WEBRTC`, `GHOSTLY_HUB`): unset or empty is
480
+ * `fallback`; 0/false/off/no and 1/true/on/yes, in any case and trimmed, say it; anything else is a usage error naming
481
+ * the variable. Before, only the exact "0" turned one off: `GHOSTLY_DHT=false` kept the profile on the public Mainline
482
+ * DHT, and `GHOSTLY_STUN=off` kept asking Google's STUN servers, with no word (agents#1756). A privacy switch never
483
+ * fails open in silence.
484
+ */
485
+ function envSwitch(name, fallback, env = process.env) {
486
+ const value = env[name];
487
+ if (value === void 0 || value.trim() === "") return fallback;
488
+ if (OFF.test(value.trim())) return false;
489
+ if (ON.test(value.trim())) return true;
490
+ throw new CliError("usage", `${name} takes 0 or 1 (or false/true, off/on, no/yes), not ${JSON.stringify(value)}`);
491
+ }
492
+ //#endregion
467
493
  //#region src/calls/media.ts
468
494
  var loading = null;
469
495
  var OPUS_APPLICATION_VOIP = 2048;
470
496
  var OPUS_SET_BITRATE = 4002;
497
+ var OPUS_SET_INBAND_FEC = 4012;
498
+ var OPUS_SET_PACKET_LOSS_PERC = 4014;
471
499
  /** The largest packet a codec reads or writes (opusscript's MAX_PACKET_SIZE). */
472
500
  var MAX_PACKET_BYTES = 3828;
473
501
  /**
@@ -503,6 +531,10 @@ function opusCodec(native, rate) {
503
531
  if (samples < 0) throw new Error(`Decode error: ${samples}`);
504
532
  return Buffer.from(native.HEAPU16.subarray(pcm / 2, pcm / 2 + Math.min(samples * 2, MAX_PCM_OUT)));
505
533
  },
534
+ fec(on) {
535
+ if (deleted) return;
536
+ if (handler._encoder_ctl(OPUS_SET_INBAND_FEC, on ? 1 : 0) < 0 || handler._encoder_ctl(OPUS_SET_PACKET_LOSS_PERC, on ? 10 : 0) < 0) throw new Error("Encoder CTL error");
537
+ },
506
538
  delete() {
507
539
  if (deleted) return;
508
540
  deleted = true;
@@ -511,7 +543,7 @@ function opusCodec(native, rate) {
511
543
  native._free(packet);
512
544
  }
513
545
  };
514
- if (handler._encoder_ctl(OPUS_SET_BITRATE, 32e3) < 0) {
546
+ if (handler._encoder_ctl(OPUS_SET_BITRATE, 32e3) < 0 || handler._encoder_ctl(OPUS_SET_INBAND_FEC, 1) < 0 || handler._encoder_ctl(OPUS_SET_PACKET_LOSS_PERC, 10) < 0) {
515
547
  codec.delete?.();
516
548
  throw new Error("Encoder CTL error");
517
549
  }
@@ -520,7 +552,11 @@ function opusCodec(native, rate) {
520
552
  /** The media stack, or why calls are not available here (the reason the call buttons of the contact's app show). */
521
553
  function loadCallStack() {
522
554
  return loading ??= (async () => {
523
- if (process.env.GHOSTLY_WEBRTC === "0") return "Calls are off on this headless Ghostly (GHOSTLY_WEBRTC=0)";
555
+ try {
556
+ if (!envSwitch("GHOSTLY_WEBRTC", true)) return "Calls are off on this headless Ghostly (GHOSTLY_WEBRTC=0)";
557
+ } catch (error) {
558
+ return error.message;
559
+ }
524
560
  try {
525
561
  const ndc = await import("node-datachannel");
526
562
  const lib = ndc.PeerConnection ? ndc : ndc.default;
@@ -542,7 +578,7 @@ function loadCallStack() {
542
578
  * apps' calls use them.
543
579
  */
544
580
  function callIceServers(extra = [], env = process.env) {
545
- const out = env.GHOSTLY_STUN === "0" ? [] : (RTC_CONFIG.iceServers ?? []).flatMap((server) => [server.urls].flat()).slice(0, 2);
581
+ const out = !envSwitch("GHOSTLY_STUN", true, env) ? [] : (RTC_CONFIG.iceServers ?? []).flatMap((server) => [server.urls].flat()).slice(0, 2);
546
582
  for (const server of callRtcConfig(extra).iceServers?.slice(RTC_CONFIG.iceServers?.length ?? 0) ?? []) for (const url of [server.urls].flat()) {
547
583
  const m = /^(stun|turns?):([^:?\s]+)(?::(\d+))?(?:\?transport=(udp|tcp))?$/i.exec(url);
548
584
  if (!m) continue;
@@ -2946,6 +2982,15 @@ function thaw(bytes) {
2946
2982
  function handOut(value) {
2947
2983
  return value && typeof value === "object" && fresh.delete(value) ? value : structuredClone(value);
2948
2984
  }
2985
+ /**
2986
+ * Ends a SQLite transaction that failed. SQLite rolls one back itself on some errors (a full disk): the ROLLBACK then
2987
+ * throws "cannot rollback - no transaction is active", which hid the error that mattered (ENOSPC) from the log.
2988
+ */
2989
+ function rollback(db) {
2990
+ try {
2991
+ db.exec("ROLLBACK");
2992
+ } catch {}
2993
+ }
2949
2994
  /** rows.db's trees: the stores kept on disk and their indexes, each a tree id in `entries`. */
2950
2995
  var TreeFile = class {
2951
2996
  db;
@@ -3010,7 +3055,7 @@ var TreeFile = class {
3010
3055
  this.db.prepare("INSERT OR REPLACE INTO meta (name, value) VALUES ('applied', max(?, coalesce((SELECT value FROM meta WHERE name = 'applied'), 0)))").run(top);
3011
3056
  this.db.exec("COMMIT");
3012
3057
  } catch (error) {
3013
- this.db.exec("ROLLBACK");
3058
+ rollback(this.db);
3014
3059
  throw error;
3015
3060
  }
3016
3061
  for (const tree of due) tree.settle(upTo);
@@ -3035,7 +3080,7 @@ var TreeFile = class {
3035
3080
  }
3036
3081
  this.db.exec("COMMIT");
3037
3082
  } catch (error) {
3038
- this.db.exec("ROLLBACK");
3083
+ rollback(this.db);
3039
3084
  throw error;
3040
3085
  }
3041
3086
  for (const tree of this.live) if (!keep.has(tree.id)) this.live.delete(tree);
@@ -3578,9 +3623,8 @@ async function openPersistentIndexedDb(dir, options = {}) {
3578
3623
  } else {
3579
3624
  const ops = pending.get(this._rollbackLog);
3580
3625
  if (ops?.length) {
3581
- const entry = ++seq;
3582
- trees?.complete(this._rollbackLog, entry);
3583
- append(ops, this.durability === "relaxed", entry);
3626
+ const refused = append(ops, this.durability === "relaxed", ++seq, this._rollbackLog);
3627
+ if (refused) return refuse(this, refused.error, event);
3584
3628
  }
3585
3629
  }
3586
3630
  pending.delete(this._rollbackLog);
@@ -3602,8 +3646,12 @@ async function openPersistentIndexedDb(dir, options = {}) {
3602
3646
  });
3603
3647
  return request;
3604
3648
  };
3605
- /** A committed transaction's entry, numbered `entry` (its first op says so, where there are trees). */
3606
- function append(ops, lazy, entry) {
3649
+ /**
3650
+ * A committed transaction's entry, numbered `entry` (its first op says so, where there are trees), from the
3651
+ * transaction whose rollback log is `owner`. Written at once, it may fail (a full disk): the reason is given back,
3652
+ * and the transaction is to be refused, not completed.
3653
+ */
3654
+ function append(ops, lazy, entry, owner) {
3607
3655
  if (trees) ops = [{
3608
3656
  db: SEQ,
3609
3657
  store: "",
@@ -3611,15 +3659,42 @@ async function openPersistentIndexedDb(dir, options = {}) {
3611
3659
  seq: entry
3612
3660
  }, ...ops];
3613
3661
  if (queued === 0 && !ops.some((op) => op.kind === "put" && hasBlob(op.value))) {
3614
- if (writeEntry(serialize(ops), lazy)) written(entry);
3615
- return;
3662
+ let done;
3663
+ try {
3664
+ done = writeEntry(serialize(ops), lazy);
3665
+ } catch (error) {
3666
+ return { error };
3667
+ }
3668
+ trees?.complete(owner, entry);
3669
+ if (done) written(entry);
3670
+ return null;
3616
3671
  }
3672
+ trees?.complete(owner, entry);
3617
3673
  enqueue(async () => {
3618
3674
  if (writeEntry(serialize(await Promise.all(ops.map(async (op) => op.kind === "put" ? {
3619
3675
  ...op,
3620
3676
  value: await blobsToDisk(op.value)
3621
3677
  } : op))), lazy)) written(entry);
3622
3678
  });
3679
+ return null;
3680
+ }
3681
+ /**
3682
+ * A transaction whose entry the disk did not take: what it wrote is undone (as fake-indexeddb's own abort does), and
3683
+ * it ends with an `abort` in place of its `complete`, with a QuotaExceededError, as a browser's out of room does. It
3684
+ * completed, before: the engine answered done for a change that was held but not on disk (a full disk under a
3685
+ * daemon), and a restart lost it.
3686
+ */
3687
+ function refuse(transaction, error, complete) {
3688
+ failed(error);
3689
+ for (const undo of transaction._rollbackLog.reverse()) undo();
3690
+ const reason = error?.code === "ENOSPC" ? `No room left on the disk of ${dir}: free some space, then try again` : `This change could not be saved in ${dir}`;
3691
+ transaction.error = Object.assign(new DOMException(reason, "QuotaExceededError"), { cause: error });
3692
+ const abort = new complete.constructor("abort", {
3693
+ bubbles: true,
3694
+ cancelable: false
3695
+ });
3696
+ abort.eventPath = [transaction.db];
3697
+ return transaction.dispatchEvent(abort);
3623
3698
  }
3624
3699
  /**
3625
3700
  * The journal has entry `entry`: the trees' layers up to it go to SQLite. One that fails stays in memory, where reads
@@ -3664,7 +3739,7 @@ async function openPersistentIndexedDb(dir, options = {}) {
3664
3739
  indexes.forEach((index, at) => trees.load(ids[at], index.records.values(), true, index.records.keysAreUnique));
3665
3740
  trees.db.exec("COMMIT");
3666
3741
  } catch (error) {
3667
- trees.db.exec("ROLLBACK");
3742
+ rollback(trees.db);
3668
3743
  throw error;
3669
3744
  }
3670
3745
  attachTree(store.records, trees.tree(id, true, false), false);
@@ -3698,20 +3773,24 @@ async function openPersistentIndexedDb(dir, options = {}) {
3698
3773
  */
3699
3774
  function writeEntry(entry, lazy = false) {
3700
3775
  if (!writing) return false;
3776
+ let whole = -1;
3701
3777
  try {
3702
- if (journalFd === null) {
3703
- journalFd = openSync(journalPath, "a", 384);
3704
- if (snapshotName !== void 0 && fstatSync(journalFd).size === 0) writeAll(journalFd, framed(serialize([{
3705
- db: FOLLOWS,
3706
- store: "",
3707
- kind: "clear",
3708
- snapshot: snapshotName
3709
- }])));
3710
- }
3778
+ if (journalFd === null) journalFd = openSync(journalPath, "a", 384);
3779
+ whole = fstatSync(journalFd).size;
3780
+ if (snapshotName !== void 0 && whole === 0) writeAll(journalFd, framed(serialize([{
3781
+ db: FOLLOWS,
3782
+ store: "",
3783
+ kind: "clear",
3784
+ snapshot: snapshotName
3785
+ }])));
3711
3786
  marked = false;
3712
3787
  writeAll(journalFd, framed(entry));
3788
+ if (!lazy) sync();
3713
3789
  } catch (error) {
3714
3790
  unsaved = true;
3791
+ if (journalFd !== null && whole >= 0) try {
3792
+ ftruncateSync(journalFd, whole);
3793
+ } catch {}
3715
3794
  throw error;
3716
3795
  }
3717
3796
  if (lazy) relaxed ??= setTimeout(() => {
@@ -3721,7 +3800,6 @@ async function openPersistentIndexedDb(dir, options = {}) {
3721
3800
  failed(error);
3722
3801
  }
3723
3802
  }, RELAXED_SYNC_MS).unref();
3724
- else sync();
3725
3803
  if (statSync(journalPath).size > COMPACT_BYTES) enqueue(writeSnapshot);
3726
3804
  return true;
3727
3805
  }
@@ -4286,7 +4364,7 @@ function recordsToDisk(trees, db, store, saved, cmp) {
4286
4364
  }
4287
4365
  trees.db.exec("COMMIT");
4288
4366
  } catch (error) {
4289
- trees.db.exec("ROLLBACK");
4367
+ rollback(trees.db);
4290
4368
  throw error;
4291
4369
  }
4292
4370
  }
@@ -4560,7 +4638,7 @@ function irohRelays(env = process.env) {
4560
4638
  * profile's own `iceServers` stay.
4561
4639
  */
4562
4640
  function publicStun(env = process.env) {
4563
- return env.GHOSTLY_STUN !== "0";
4641
+ return envSwitch("GHOSTLY_STUN", true, env);
4564
4642
  }
4565
4643
  /** An RTC configuration without the apps' public STUN servers. */
4566
4644
  function withoutPublicStun(config) {
@@ -4582,7 +4660,7 @@ function withoutPublicStun(config) {
4582
4660
  * public DHT.
4583
4661
  */
4584
4662
  function mainlineNetwork(env = process.env) {
4585
- if (env.GHOSTLY_DHT === "0") return { off: true };
4663
+ if (!envSwitch("GHOSTLY_DHT", true, env)) return { off: true };
4586
4664
  const bootstrap = (env.GHOSTLY_DHT_BOOTSTRAP ?? "").split(",").map((node) => node.trim()).filter(Boolean);
4587
4665
  if (!bootstrap.length && pkarrRelays(env)) return { off: true };
4588
4666
  if (!bootstrap.length) return { off: false };
@@ -4598,7 +4676,7 @@ function mainlineNetwork(env = process.env) {
4598
4676
  * `GHOSTLY_WEBRTC=0`, the CLI runs without WebRTC and says so.
4599
4677
  */
4600
4678
  async function installWebRtc() {
4601
- if (process.env.GHOSTLY_WEBRTC === "0") return false;
4679
+ if (!envSwitch("GHOSTLY_WEBRTC", true)) return false;
4602
4680
  try {
4603
4681
  const polyfill = await import("node-datachannel/polyfill");
4604
4682
  const scope = globalThis;
@@ -4700,7 +4778,7 @@ async function startRuntime(paths, options = {}) {
4700
4778
  const restored = join(paths.dir, RESTORED_MARK);
4701
4779
  if (existsSync(restored)) {
4702
4780
  try {
4703
- const rows = await import("./restoredRows-DGuKtIBz.js");
4781
+ const rows = await import("./restoredRows-D6WZUA2U.js");
4704
4782
  await rows.markRestoredWallet();
4705
4783
  await rows.markLeftOutFiles(leftOutIn(restored));
4706
4784
  await store.compact();
@@ -4718,18 +4796,18 @@ async function startRuntime(paths, options = {}) {
4718
4796
  if (testMints) (await import("./mints-CqTdA4Gk.js")).declareTestMints(testMints.split(","));
4719
4797
  await installEventSource();
4720
4798
  await preloadWalletModules();
4721
- (await import("./ghostly_iroh_web-BsAEFIjl.js")).initSync({ module: irohWasmBytes() });
4722
- const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-gTd_8l-P.js"), import("./fileBytes-uRqLyxa0.js")]);
4799
+ (await import("./ghostly_iroh_web-BXCsSxxo.js")).initSync({ module: irohWasmBytes() });
4800
+ const [{ registerFileBytes }, { NodeFileBytes }] = await Promise.all([import("./fileBytes-BMlLVdfg.js"), import("./fileBytes-D0CYuRwZ.js")]);
4723
4801
  registerFileBytes("native", async () => new NodeFileBytes(paths.files), true);
4724
- if (await (await import("./blobFiles-1wUBd8ZD.js")).moveBlobFiles()) await store.compact();
4725
- const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-CcAs54Yb.js"), import("./endpoint-Cl3cgAYl.js")]);
4802
+ if (await (await import("./blobFiles-B1lX6iGy.js")).moveBlobFiles()) await store.compact();
4803
+ const [{ EngineServer }, { createHyperEndpoint }] = await Promise.all([import("./server-DOtUKoYR.js"), import("./endpoint-BdaeBw2L.js")]);
4726
4804
  const network = hyperdhtNetwork();
4727
4805
  const dht = mainlineNetwork();
4728
- const mainline = dht.off ? null : new (await (import("./mainline-HQVJ5ukA.js"))).Mainline({
4806
+ const mainline = dht.off ? null : new (await (import("./mainline-CEqGvRYJ.js"))).Mainline({
4729
4807
  bootstrap: dht.bootstrap,
4730
4808
  host: dht.host
4731
4809
  });
4732
- const transport = mainline || pinned ? new (await (import("./mainline-HQVJ5ukA.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
4810
+ const transport = mainline || pinned ? new (await (import("./mainline-CEqGvRYJ.js"))).RelaysAndDht(mainline, pinned ? { relays: pinned } : {}, !!pinned) : null;
4733
4811
  const apps = servedApps(paths.dir).length > 0;
4734
4812
  const server = new EngineServer({
4735
4813
  ...transport ? { transport } : {},
@@ -4741,7 +4819,7 @@ async function startRuntime(paths, options = {}) {
4741
4819
  fedimintSdk: nodeFedimintSdk(join(paths.dir, "fedimint")),
4742
4820
  servicesSupport: true,
4743
4821
  apps: apps ? "wire" : false,
4744
- staysOnline: process.env.GHOSTLY_HUB !== "0",
4822
+ staysOnline: envSwitch("GHOSTLY_HUB", true),
4745
4823
  localFetch: nodeLocalFetch,
4746
4824
  pushSend: (request) => nodePushSend(request),
4747
4825
  holdFetch: nodeHoldFetch(),
@@ -5070,4 +5148,4 @@ function connection(ctx, socket, secret) {
5070
5148
  //#endregion
5071
5149
  export { BASELINE_NEWEST, MAX_LINE, MAX_UNREAD, keepServing, openHost, serve };
5072
5150
 
5073
- //# sourceMappingURL=host-DxDRCRKD.js.map
5151
+ //# sourceMappingURL=host-DrL7FPG4.js.map