home-hosted 0.10.3 → 0.12.0

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 (317) hide show
  1. package/README.md +273 -628
  2. package/dist/chunks/archive-DpCwA8Nf.js +339 -0
  3. package/dist/chunks/archive-DpCwA8Nf.js.map +1 -0
  4. package/dist/chunks/atomic-CEfCUfkQ.js +25 -0
  5. package/dist/chunks/atomic-CEfCUfkQ.js.map +1 -0
  6. package/dist/chunks/backup-CPrJVPJI.js +797 -0
  7. package/dist/chunks/backup-CPrJVPJI.js.map +1 -0
  8. package/dist/chunks/backups-Bd2SF2qd.js +4346 -0
  9. package/dist/chunks/backups-Bd2SF2qd.js.map +1 -0
  10. package/dist/chunks/config-text-DifCHhnz.js +50 -0
  11. package/dist/chunks/config-text-DifCHhnz.js.map +1 -0
  12. package/dist/chunks/contracts-ku5ypHXJ.js +2256 -0
  13. package/dist/chunks/contracts-ku5ypHXJ.js.map +1 -0
  14. package/dist/chunks/daemon-TwXk5vb8.js +215 -0
  15. package/dist/chunks/daemon-TwXk5vb8.js.map +1 -0
  16. package/dist/chunks/daemon-log-BVj8cDEo.js +241 -0
  17. package/dist/chunks/daemon-log-BVj8cDEo.js.map +1 -0
  18. package/dist/chunks/docker-CGv4Uv7w.js +436 -0
  19. package/dist/chunks/docker-CGv4Uv7w.js.map +1 -0
  20. package/dist/chunks/down-BlX5X3bm.js +378 -0
  21. package/dist/chunks/down-BlX5X3bm.js.map +1 -0
  22. package/dist/chunks/init-DdmqHVra.js +263 -0
  23. package/dist/chunks/init-DdmqHVra.js.map +1 -0
  24. package/dist/chunks/last-stop-BZ08Z89-.js +52 -0
  25. package/dist/chunks/last-stop-BZ08Z89-.js.map +1 -0
  26. package/dist/chunks/layout-D74TGUnr.js +24 -0
  27. package/dist/chunks/layout-D74TGUnr.js.map +1 -0
  28. package/dist/chunks/log-buffer-HnP0jKhZ.js +350 -0
  29. package/dist/chunks/log-buffer-HnP0jKhZ.js.map +1 -0
  30. package/dist/chunks/logger-B5U4GD3j.js +13 -0
  31. package/dist/chunks/logger-B5U4GD3j.js.map +1 -0
  32. package/dist/chunks/logs-gI_69Q1P.js +265 -0
  33. package/dist/chunks/logs-gI_69Q1P.js.map +1 -0
  34. package/dist/chunks/migrate-BTlsibvF.js +155 -0
  35. package/dist/chunks/migrate-BTlsibvF.js.map +1 -0
  36. package/dist/chunks/nanny-20aBXL1o.js +1069 -0
  37. package/dist/chunks/nanny-20aBXL1o.js.map +1 -0
  38. package/dist/chunks/nanny-CjnnrIpm.js +132 -0
  39. package/dist/chunks/nanny-CjnnrIpm.js.map +1 -0
  40. package/dist/chunks/nanny-DUaAfCV-.js +39 -0
  41. package/dist/chunks/nanny-DUaAfCV-.js.map +1 -0
  42. package/dist/chunks/nanny-sweep-Ca9kPAVi.js +104 -0
  43. package/dist/chunks/nanny-sweep-Ca9kPAVi.js.map +1 -0
  44. package/dist/chunks/nearest-6KgQEDUe.js +41 -0
  45. package/dist/chunks/nearest-6KgQEDUe.js.map +1 -0
  46. package/dist/chunks/parse-B9owE47G.js +383 -0
  47. package/dist/chunks/parse-B9owE47G.js.map +1 -0
  48. package/dist/chunks/paths-BT94q6-w.js +172 -0
  49. package/dist/chunks/paths-BT94q6-w.js.map +1 -0
  50. package/dist/chunks/port-B8WBTRMk.js +333 -0
  51. package/dist/chunks/port-B8WBTRMk.js.map +1 -0
  52. package/dist/chunks/restart-UZgeDukG.js +126 -0
  53. package/dist/chunks/restart-UZgeDukG.js.map +1 -0
  54. package/dist/chunks/rolldown-runtime-D7D4PA-g.js +13 -0
  55. package/dist/chunks/schema-o7Lgk0V1.js +102 -0
  56. package/dist/chunks/schema-o7Lgk0V1.js.map +1 -0
  57. package/dist/chunks/secrets-D7PdYh71.js +544 -0
  58. package/dist/chunks/secrets-D7PdYh71.js.map +1 -0
  59. package/dist/chunks/server-BuIeSsRu.js +169 -0
  60. package/dist/chunks/server-BuIeSsRu.js.map +1 -0
  61. package/dist/chunks/server-ids-DRuNLVCV.js +32 -0
  62. package/dist/chunks/server-ids-DRuNLVCV.js.map +1 -0
  63. package/dist/chunks/set-password-DegMumPh.js +43 -0
  64. package/dist/chunks/set-password-DegMumPh.js.map +1 -0
  65. package/dist/chunks/set-token-21d1FTDC.js +78 -0
  66. package/dist/chunks/set-token-21d1FTDC.js.map +1 -0
  67. package/dist/chunks/settings-BVSBnIwJ.js +332 -0
  68. package/dist/chunks/settings-BVSBnIwJ.js.map +1 -0
  69. package/dist/chunks/setup-temp-XiuAtiW2.js +150 -0
  70. package/dist/chunks/setup-temp-XiuAtiW2.js.map +1 -0
  71. package/dist/chunks/shape-DnTKzjQ2.js +24 -0
  72. package/dist/chunks/shape-DnTKzjQ2.js.map +1 -0
  73. package/dist/chunks/src-BL97vLVb.js +11153 -0
  74. package/dist/chunks/src-BL97vLVb.js.map +1 -0
  75. package/dist/chunks/status-EuWdRq8Q.js +119 -0
  76. package/dist/chunks/status-EuWdRq8Q.js.map +1 -0
  77. package/dist/chunks/ui-DbPuwddJ.js +323 -0
  78. package/dist/chunks/ui-DbPuwddJ.js.map +1 -0
  79. package/dist/chunks/ui-dir-CsU3uLNV.js +39 -0
  80. package/dist/chunks/ui-dir-CsU3uLNV.js.map +1 -0
  81. package/dist/chunks/ui-release-DKzVvlLd.js +312 -0
  82. package/dist/chunks/ui-release-DKzVvlLd.js.map +1 -0
  83. package/dist/chunks/ui-revert-BhqOAhmM.js +27 -0
  84. package/dist/chunks/ui-revert-BhqOAhmM.js.map +1 -0
  85. package/dist/chunks/ui-switch-CMoslPO2.js +150 -0
  86. package/dist/chunks/ui-switch-CMoslPO2.js.map +1 -0
  87. package/dist/chunks/ui-update-TTBBoDik.js +272 -0
  88. package/dist/chunks/ui-update-TTBBoDik.js.map +1 -0
  89. package/dist/chunks/up-C4H13hBw.js +196 -0
  90. package/dist/chunks/up-C4H13hBw.js.map +1 -0
  91. package/dist/chunks/usage-CSBgLRN5.js +85 -0
  92. package/dist/chunks/usage-CSBgLRN5.js.map +1 -0
  93. package/dist/chunks/workspaces-CAln2sQ7.js +221 -0
  94. package/dist/chunks/workspaces-CAln2sQ7.js.map +1 -0
  95. package/dist/chunks/wsl-temperature-BiCI4iK6.js +322 -0
  96. package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +1 -0
  97. package/dist/cli.js +229 -24861
  98. package/dist/cli.js.map +1 -1
  99. package/dist/client.js +120 -0
  100. package/dist/client.js.map +1 -0
  101. package/dist/types/api/acme.d.ts +24 -0
  102. package/dist/types/api/auth/$.routes.d.ts +103 -0
  103. package/dist/types/api/backups.d.ts +179 -0
  104. package/dist/types/api/control.d.ts +469 -0
  105. package/dist/types/api/ddns.d.ts +432 -0
  106. package/dist/types/api/events.d.ts +21 -0
  107. package/dist/types/api/health.d.ts +27 -0
  108. package/dist/types/api/logs.d.ts +95 -0
  109. package/dist/types/api/metrics.d.ts +19 -0
  110. package/dist/types/api/notifications.d.ts +141 -0
  111. package/dist/types/api/proxy.d.ts +1128 -0
  112. package/dist/types/api/servers/$.routes.d.ts +1318 -0
  113. package/dist/types/api/settings.d.ts +642 -0
  114. package/dist/types/api/state.d.ts +492 -0
  115. package/dist/types/api/static.d.ts +11 -0
  116. package/dist/types/api/tls.d.ts +112 -0
  117. package/dist/types/api/workspaces/$.routes.d.ts +797 -0
  118. package/dist/types/api/wsl-temperature.d.ts +113 -0
  119. package/dist/types/app.d.ts +6080 -0
  120. package/dist/types/cli/args.d.ts +75 -0
  121. package/dist/types/cli/backup-offline.d.ts +23 -0
  122. package/dist/types/cli/backup.d.ts +79 -0
  123. package/dist/types/cli/down.d.ts +75 -0
  124. package/dist/types/cli/init.d.ts +60 -0
  125. package/dist/types/cli/io.d.ts +65 -0
  126. package/dist/types/cli/logs.d.ts +64 -0
  127. package/dist/types/cli/migrate.d.ts +33 -0
  128. package/dist/types/cli/nanny.d.ts +19 -0
  129. package/dist/types/cli/nearest.d.ts +10 -0
  130. package/dist/types/cli/restart.d.ts +42 -0
  131. package/dist/types/cli/server.d.ts +68 -0
  132. package/dist/types/cli/set-password.d.ts +14 -0
  133. package/dist/types/cli/set-token.d.ts +21 -0
  134. package/dist/types/cli/setup-temp.d.ts +65 -0
  135. package/dist/types/cli/status.d.ts +14 -0
  136. package/dist/types/cli/ui-revert.d.ts +3 -0
  137. package/dist/types/cli/ui-switch.d.ts +27 -0
  138. package/dist/types/cli/ui-update.d.ts +72 -0
  139. package/dist/types/cli/up.d.ts +90 -0
  140. package/dist/types/cli/usage.d.ts +23 -0
  141. package/dist/types/cli.d.ts +12 -0
  142. package/dist/types/client.d.ts +6284 -0
  143. package/dist/types/config/layout.d.ts +11 -0
  144. package/dist/types/config/migrations.d.ts +69 -0
  145. package/dist/types/config/parse.d.ts +54 -0
  146. package/dist/types/config/patch.d.ts +20 -0
  147. package/dist/types/config/schema.d.ts +318 -0
  148. package/dist/types/config/secret-parts.d.ts +48 -0
  149. package/dist/types/config/secrets.d.ts +206 -0
  150. package/dist/types/config/seed.d.ts +30 -0
  151. package/dist/types/config/server-ids.d.ts +14 -0
  152. package/dist/types/config/settings.d.ts +74 -0
  153. package/dist/types/config/store.d.ts +132 -0
  154. package/dist/types/config/workspaces.d.ts +96 -0
  155. package/dist/types/helpers/action-result.d.ts +46 -0
  156. package/dist/types/helpers/atomic.d.ts +9 -0
  157. package/dist/types/helpers/backoff.d.ts +7 -0
  158. package/dist/types/helpers/bind.d.ts +16 -0
  159. package/dist/types/helpers/config-text.d.ts +23 -0
  160. package/dist/types/helpers/cookies.d.ts +19 -0
  161. package/dist/types/helpers/copy-tree.d.ts +15 -0
  162. package/dist/types/helpers/daemon-log.d.ts +45 -0
  163. package/dist/types/helpers/daemon.d.ts +122 -0
  164. package/dist/types/helpers/deferred.d.ts +7 -0
  165. package/dist/types/helpers/env-file.d.ts +20 -0
  166. package/dist/types/helpers/error.d.ts +18 -0
  167. package/dist/types/helpers/factory.d.ts +6 -0
  168. package/dist/types/helpers/last-stop.d.ts +20 -0
  169. package/dist/types/helpers/logger.d.ts +7 -0
  170. package/dist/types/helpers/open.d.ts +2 -0
  171. package/dist/types/helpers/openapi.d.ts +46 -0
  172. package/dist/types/helpers/paths.d.ts +94 -0
  173. package/dist/types/helpers/restore-lock.d.ts +32 -0
  174. package/dist/types/helpers/runtime.d.ts +18 -0
  175. package/dist/types/helpers/secret-compare.d.ts +13 -0
  176. package/dist/types/helpers/shell.d.ts +19 -0
  177. package/dist/types/helpers/sse.d.ts +23 -0
  178. package/dist/types/helpers/template.d.ts +8 -0
  179. package/dist/types/helpers/ui-dir.d.ts +11 -0
  180. package/dist/types/helpers/validate.d.ts +7 -0
  181. package/dist/types/helpers/validator.d.ts +12 -0
  182. package/dist/types/helpers/version.d.ts +10 -0
  183. package/dist/types/helpers/workspace.d.ts +25 -0
  184. package/dist/types/index.d.ts +17 -0
  185. package/dist/types/middleware/auth.d.ts +37 -0
  186. package/dist/types/middleware/host.d.ts +29 -0
  187. package/dist/types/middleware/loopback.d.ts +18 -0
  188. package/dist/types/openapi-reference.d.ts +22 -0
  189. package/dist/types/openapi.d.ts +34 -0
  190. package/dist/types/providers/archive.d.ts +54 -0
  191. package/dist/types/providers/backup-hook.d.ts +34 -0
  192. package/dist/types/providers/ddns/cloudflare.d.ts +2 -0
  193. package/dist/types/providers/ddns/desec.d.ts +2 -0
  194. package/dist/types/providers/ddns/digitalocean.d.ts +2 -0
  195. package/dist/types/providers/ddns/duckdns.d.ts +2 -0
  196. package/dist/types/providers/ddns/dyndns2.d.ts +15 -0
  197. package/dist/types/providers/ddns/dynu.d.ts +2 -0
  198. package/dist/types/providers/ddns/freedns.d.ts +2 -0
  199. package/dist/types/providers/ddns/gandi.d.ts +2 -0
  200. package/dist/types/providers/ddns/godaddy.d.ts +2 -0
  201. package/dist/types/providers/ddns/henet.d.ts +3 -0
  202. package/dist/types/providers/ddns/index.d.ts +12 -0
  203. package/dist/types/providers/ddns/ip.d.ts +27 -0
  204. package/dist/types/providers/ddns/namecheap-api.d.ts +13 -0
  205. package/dist/types/providers/ddns/namecheap.d.ts +6 -0
  206. package/dist/types/providers/ddns/noip.d.ts +2 -0
  207. package/dist/types/providers/ddns/porkbun.d.ts +2 -0
  208. package/dist/types/providers/ddns/spaceship.d.ts +7 -0
  209. package/dist/types/providers/ddns/types.d.ts +98 -0
  210. package/dist/types/providers/ddns/zone.d.ts +11 -0
  211. package/dist/types/providers/docker.d.ts +117 -0
  212. package/dist/types/providers/entry-state.d.ts +15 -0
  213. package/dist/types/providers/health-check.d.ts +27 -0
  214. package/dist/types/providers/host.d.ts +147 -0
  215. package/dist/types/providers/identity.d.ts +54 -0
  216. package/dist/types/providers/log-tail.d.ts +29 -0
  217. package/dist/types/providers/nanny-sweep.d.ts +51 -0
  218. package/dist/types/providers/nanny.d.ts +94 -0
  219. package/dist/types/providers/port.d.ts +142 -0
  220. package/dist/types/providers/proc.d.ts +116 -0
  221. package/dist/types/providers/process.d.ts +61 -0
  222. package/dist/types/providers/proxy/caddy.d.ts +2 -0
  223. package/dist/types/providers/proxy/index.d.ts +7 -0
  224. package/dist/types/providers/proxy/types.d.ts +54 -0
  225. package/dist/types/providers/server-vars.d.ts +4 -0
  226. package/dist/types/providers/telegram.d.ts +32 -0
  227. package/dist/types/providers/ui-release.d.ts +113 -0
  228. package/dist/types/providers/webhook.d.ts +64 -0
  229. package/dist/types/providers/wsl-temperature.d.ts +69 -0
  230. package/dist/types/services/acme-challenge.d.ts +44 -0
  231. package/dist/types/services/auth.d.ts +145 -0
  232. package/dist/types/services/backups.d.ts +352 -0
  233. package/dist/types/services/config-watch.d.ts +40 -0
  234. package/dist/types/services/control-server.d.ts +58 -0
  235. package/dist/types/services/ddns.d.ts +67 -0
  236. package/dist/types/services/dependencies.d.ts +21 -0
  237. package/dist/types/services/events.d.ts +17 -0
  238. package/dist/types/services/exposure.d.ts +33 -0
  239. package/dist/types/services/history.d.ts +36 -0
  240. package/dist/types/services/host-monitor.d.ts +32 -0
  241. package/dist/types/services/init.d.ts +71 -0
  242. package/dist/types/services/log-buffer.d.ts +28 -0
  243. package/dist/types/services/log-files.d.ts +87 -0
  244. package/dist/types/services/log-relay.d.ts +36 -0
  245. package/dist/types/services/nanny.d.ts +14 -0
  246. package/dist/types/services/notifications.d.ts +124 -0
  247. package/dist/types/services/panel.d.ts +194 -0
  248. package/dist/types/services/proxy-config.d.ts +83 -0
  249. package/dist/types/services/proxy.d.ts +454 -0
  250. package/dist/types/services/state.d.ts +41 -0
  251. package/dist/types/services/supervisor/compose.d.ts +17 -0
  252. package/dist/types/services/supervisor/entry.d.ts +139 -0
  253. package/dist/types/services/supervisor/health.d.ts +55 -0
  254. package/dist/types/services/supervisor/pending-load.d.ts +6 -0
  255. package/dist/types/services/supervisor/persistent.d.ts +55 -0
  256. package/dist/types/services/supervisor/port-preflight.d.ts +45 -0
  257. package/dist/types/services/supervisor/records.d.ts +38 -0
  258. package/dist/types/services/supervisor/spawn.d.ts +15 -0
  259. package/dist/types/services/supervisor/view.d.ts +4 -0
  260. package/dist/types/services/supervisor.d.ts +113 -0
  261. package/dist/types/services/tls.d.ts +48 -0
  262. package/dist/types/services/ui-update.d.ts +44 -0
  263. package/dist/types/services/ui.d.ts +50 -0
  264. package/dist/types/shared/api-client.d.ts +137 -0
  265. package/dist/types/shared/backup-scope.d.ts +109 -0
  266. package/dist/types/shared/clone.d.ts +14 -0
  267. package/dist/types/shared/contracts.d.ts +4233 -0
  268. package/dist/types/shared/cpu-scale.d.ts +25 -0
  269. package/dist/types/shared/ddns-form.d.ts +62 -0
  270. package/dist/types/shared/endpoint.d.ts +8 -0
  271. package/dist/types/shared/error-message.d.ts +8 -0
  272. package/dist/types/shared/fields.d.ts +21 -0
  273. package/dist/types/shared/generated.d.ts +26 -0
  274. package/dist/types/shared/host-readings.d.ts +185 -0
  275. package/dist/types/shared/patch-diff.d.ts +94 -0
  276. package/dist/types/shared/probe-latency.d.ts +25 -0
  277. package/dist/types/shared/proxy-form.d.ts +182 -0
  278. package/dist/types/shared/server-attention.d.ts +37 -0
  279. package/dist/types/shared/server-key.d.ts +13 -0
  280. package/dist/types/shared/server-readings.d.ts +55 -0
  281. package/dist/types/shared/server-url.d.ts +43 -0
  282. package/dist/types/shared/shape.d.ts +17 -0
  283. package/dist/types/shared/ui-format.d.ts +89 -0
  284. package/docs/API.md +180 -0
  285. package/docs/BACKUPS.md +97 -0
  286. package/docs/CLI.md +122 -0
  287. package/docs/DDNS.md +12 -3
  288. package/docs/NOTIFICATIONS.md +3 -1
  289. package/docs/RESTORE_DEMO.md +6 -4
  290. package/docs/REVERSE_PROXY.md +2 -2
  291. package/docs/SECURITY.md +82 -0
  292. package/docs/SERVERS.md +47 -15
  293. package/docs/UI_CREATION.md +82 -286
  294. package/package.json +18 -9
  295. package/uis/stock/dist/assets/de-DyGrM1KK.js +1 -0
  296. package/uis/stock/dist/assets/es-BebHdc0E.js +1 -0
  297. package/uis/stock/dist/assets/fr-DsDTrxhI.js +1 -0
  298. package/uis/stock/dist/assets/index-6LANO2Ua.css +2 -0
  299. package/uis/stock/dist/assets/index-D06cUZbM.js +56 -0
  300. package/uis/stock/dist/assets/ja-D3RARJjW.js +1 -0
  301. package/uis/stock/dist/assets/ko-CKI3dFoD.js +1 -0
  302. package/uis/stock/dist/assets/ru-DEU5ujXt.js +1 -0
  303. package/uis/stock/dist/assets/vi-ULKPnasj.js +1 -0
  304. package/uis/stock/dist/assets/zh-CN-tCvnOxWy.js +1 -0
  305. package/uis/stock/dist/index.html +2 -2
  306. package/uis/stock/dist/ui.json +3 -3
  307. package/AGENTS.md +0 -403
  308. package/uis/stock/dist/assets/de-CiSKBON6.js +0 -1
  309. package/uis/stock/dist/assets/es-BgNQbboq.js +0 -1
  310. package/uis/stock/dist/assets/fr-WzBF8AXI.js +0 -1
  311. package/uis/stock/dist/assets/index-CXDl25BP.js +0 -53
  312. package/uis/stock/dist/assets/index-Cok5msAO.css +0 -2
  313. package/uis/stock/dist/assets/ja-DMQqF4ip.js +0 -1
  314. package/uis/stock/dist/assets/ko-DgfSg9v_.js +0 -1
  315. package/uis/stock/dist/assets/ru-DjIByX61.js +0 -1
  316. package/uis/stock/dist/assets/vi-DOB8nYFC.js +0 -1
  317. package/uis/stock/dist/assets/zh-CN-DZ3WlUgy.js +0 -1
@@ -0,0 +1,332 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
+ import { t as writeFileAtomic } from "./atomic-CEfCUfkQ.js";
3
+ import { n as readStateFile } from "./config-text-DifCHhnz.js";
4
+ import { t as isRecord } from "./shape-DnTKzjQ2.js";
5
+ import { c as planConfigMigrations, o as stampConfig, r as parseTolerant, t as parseGlobalSettings } from "./parse-B9owE47G.js";
6
+ import { B as proxyConfigSchema, f as controlSchema, l as backupsSchema, w as hostSchema } from "./contracts-ku5ypHXJ.js";
7
+ import { i as globalSettingsSchema } from "./schema-o7Lgk0V1.js";
8
+ import { a as globalSettingsPath } from "./paths-BT94q6-w.js";
9
+ import path from "node:path";
10
+ import fs from "node:fs";
11
+ import { type } from "arktype";
12
+ //#region src/config/patch.ts
13
+ /** Nested groups a patch merges into instead of replacing. */
14
+ var SERVER_MERGE_KEYS = /* @__PURE__ */ new Set([
15
+ "restart",
16
+ "health",
17
+ "stop"
18
+ ]);
19
+ var CONTROL_MERGE_KEYS = /* @__PURE__ */ new Set(["auth", "tls"]);
20
+ /** The general block merges key by key; `destinations` is a list a patch replaces. */
21
+ var NOTIFICATION_MERGE_KEYS = /* @__PURE__ */ new Set(["defaults"]);
22
+ /** The DDNS lists are replaced; only its two IP-family groups merge. */
23
+ var DDNS_MERGE_KEYS = /* @__PURE__ */ new Set(["ipv4", "ipv6"]);
24
+ /** The proxy's one nested group; `routes` and `certificates` are lists a patch replaces. */
25
+ var PROXY_MERGE_KEYS = /* @__PURE__ */ new Set(["dns01"]);
26
+ /** Backups' scheduled half merges, so a patch sending only `intervalMs` keeps the retention. */
27
+ var BACKUP_MERGE_KEYS = /* @__PURE__ */ new Set(["schedule"]);
28
+ var EMPTY_MERGE_KEYS = /* @__PURE__ */ new Set();
29
+ function applyPatch(target, patch, mergeKeys) {
30
+ for (const [key, value] of Object.entries(patch)) {
31
+ if (value === void 0) continue;
32
+ if (mergeKeys.has(key) && isRecord(value) && isRecord(target[key])) {
33
+ target[key] = mergeGroup(target[key], value);
34
+ continue;
35
+ }
36
+ if (value === null) {
37
+ delete target[key];
38
+ continue;
39
+ }
40
+ target[key] = value;
41
+ }
42
+ }
43
+ /**
44
+ * Merges one nested group recursively — `health.http` is a group of its own, and
45
+ * replacing it wholesale would silently reset the siblings a partial patch never
46
+ * mentioned. An explicit `null` removes a key, which is how a schema-optional
47
+ * field is cleared.
48
+ */
49
+ function mergeGroup(target, patch) {
50
+ const merged = { ...target };
51
+ for (const [key, value] of Object.entries(patch)) {
52
+ if (value === void 0) continue;
53
+ if (value === null) {
54
+ delete merged[key];
55
+ continue;
56
+ }
57
+ if (isRecord(value) && isRecord(merged[key])) {
58
+ merged[key] = mergeGroup(merged[key], value);
59
+ continue;
60
+ }
61
+ merged[key] = value;
62
+ }
63
+ return merged;
64
+ }
65
+ //#endregion
66
+ //#region src/config/seed.ts
67
+ /**
68
+ * Written when `$HHOSTED_HOME` has no state yet. Every seed stays empty of
69
+ * servers on purpose: home-hosted ships none, so what a user supervises is
70
+ * theirs to declare. The rest is default policy, which the settings pages can
71
+ * change.
72
+ */
73
+ /** `$HHOSTED_HOME/.hh/settings.json`. */
74
+ var SEED_GLOBAL_SETTINGS = {
75
+ $schema: "./settings.schema.json",
76
+ control: {
77
+ port: 3999,
78
+ host: "local",
79
+ openBrowser: false
80
+ }
81
+ };
82
+ /** `$HHOSTED_HOME/.hh/<id>/settings.json`. */
83
+ var SEED_WORKSPACE_SETTINGS = {
84
+ $schema: "./settings.schema.json",
85
+ defaults: {
86
+ enabled: true,
87
+ autostart: false,
88
+ bind: "local",
89
+ onPortConflict: "block"
90
+ }
91
+ };
92
+ /** `$HHOSTED_HOME/.hh/<id>/servers.config.json`. */
93
+ var SEED_SERVERS_FILE = {
94
+ $schema: "./servers.config.schema.json",
95
+ servers: []
96
+ };
97
+ //#endregion
98
+ //#region src/config/settings.ts
99
+ var settings_exports = /* @__PURE__ */ __exportAll({
100
+ ConfigError: () => ConfigError,
101
+ GlobalSettingsStore: () => GlobalSettingsStore
102
+ });
103
+ var ConfigError = class extends Error {
104
+ name = "ConfigError";
105
+ /**
106
+ * The *kind* of config problem, when a caller has to branch on it rather than just report it.
107
+ * `UNKNOWN_SERVER` is the one case today: the servers route answers 404 for a missing id and 400
108
+ * for an invalid patch, and it decided that by matching the message text.
109
+ */
110
+ code;
111
+ constructor(message, code) {
112
+ super(message);
113
+ this.code = code;
114
+ }
115
+ };
116
+ /**
117
+ * The panel-wide settings file (`$HHOSTED_HOME/.hh/settings.json`): the listener,
118
+ * authentication, TLS policy, host vitals and backups. Nothing here belongs to a
119
+ * workspace, which is why it sits above them.
120
+ */
121
+ var GlobalSettingsStore = class {
122
+ file;
123
+ seed;
124
+ raw = {};
125
+ /** The bytes behind the live settings, so a watcher can tell a real edit from our own write. */
126
+ lastText = null;
127
+ resolvedConfig;
128
+ error = null;
129
+ /** A JSON parse failure, kept apart from a schema problem so `apply()` cannot clear it. */
130
+ parseError = null;
131
+ warnings = [];
132
+ schemaVersion = 1;
133
+ listeners = /* @__PURE__ */ new Set();
134
+ constructor(file = globalSettingsPath, seed = SEED_GLOBAL_SETTINGS) {
135
+ this.file = file;
136
+ this.seed = seed;
137
+ }
138
+ get path() {
139
+ return this.file;
140
+ }
141
+ get config() {
142
+ return this.resolvedConfig;
143
+ }
144
+ get control() {
145
+ return this.resolvedConfig.control;
146
+ }
147
+ get host() {
148
+ return this.resolvedConfig.host;
149
+ }
150
+ get backups() {
151
+ return this.resolvedConfig.backups;
152
+ }
153
+ get proxy() {
154
+ return this.resolvedConfig.proxy;
155
+ }
156
+ get configError() {
157
+ return this.error;
158
+ }
159
+ /** Keys a newer release wrote that this one ignores; nothing to refuse over. */
160
+ get configWarnings() {
161
+ return [...this.warnings];
162
+ }
163
+ get configSchemaVersion() {
164
+ return this.schemaVersion;
165
+ }
166
+ /**
167
+ * Steps that would have to run before this release could use the file.
168
+ *
169
+ * A file that cannot be **parsed** has no schema to plan from, and `migrate` refuses one it
170
+ * cannot read rather than lifting it — so claiming a migration here sends the person to the one
171
+ * command guaranteed not to help. Measured: a truncated `.hh/settings.json` made `up` say
172
+ * "needs 1 migration(s)" and `migrate` answer "cannot read … Unexpected end of JSON input". The
173
+ * workspace pair already excluded the parse failure (`WorkspaceStore.pendingMigrations`); this is
174
+ * the same rule on the global file, which is the one the startup guard reads first.
175
+ */
176
+ get pendingMigrations() {
177
+ if (this.parseError !== null) return [];
178
+ return planConfigMigrations(this.schemaVersion).steps;
179
+ }
180
+ get rawConfig() {
181
+ return structuredClone(this.raw);
182
+ }
183
+ onChange(listener) {
184
+ this.listeners.add(listener);
185
+ return () => this.listeners.delete(listener);
186
+ }
187
+ load() {
188
+ this.read();
189
+ this.notify();
190
+ }
191
+ reloadFromDisk() {
192
+ let text;
193
+ try {
194
+ text = readStateFile(this.file);
195
+ } catch {
196
+ this.error = `${path.basename(this.file)} is gone`;
197
+ return {
198
+ changed: false,
199
+ applied: false,
200
+ error: this.error
201
+ };
202
+ }
203
+ if (text === this.lastText) {
204
+ if (this.error !== null) {
205
+ this.error = null;
206
+ this.load();
207
+ }
208
+ return {
209
+ changed: false,
210
+ applied: false,
211
+ error: null
212
+ };
213
+ }
214
+ const before = this.resolvedConfig;
215
+ this.load();
216
+ return {
217
+ changed: true,
218
+ applied: this.resolvedConfig !== before,
219
+ error: this.error
220
+ };
221
+ }
222
+ read() {
223
+ this.parseError = null;
224
+ if (!fs.existsSync(this.file)) {
225
+ const seed = stampConfig(structuredClone(this.seed));
226
+ const text = `${JSON.stringify(seed, null, 2)}\n`;
227
+ writeFileAtomic(this.file, text);
228
+ this.lastText = text;
229
+ this.raw = seed;
230
+ this.apply(seed);
231
+ return;
232
+ }
233
+ let text;
234
+ let parsed;
235
+ try {
236
+ text = readStateFile(this.file);
237
+ parsed = JSON.parse(text);
238
+ } catch (error) {
239
+ this.error = `cannot parse ${path.basename(this.file)}: ${error.message}`;
240
+ this.parseError = this.error;
241
+ if (this.resolvedConfig === void 0) {
242
+ this.raw = {};
243
+ this.resolvedConfig = this.resolveFallback();
244
+ }
245
+ return;
246
+ }
247
+ this.lastText = text;
248
+ this.apply(parsed);
249
+ }
250
+ notify() {
251
+ for (const listener of this.listeners) listener();
252
+ }
253
+ updateControl(patch) {
254
+ const draft = structuredClone(this.raw);
255
+ draft.control = { ...draft.control ?? {} };
256
+ applyPatch(draft.control, patch, CONTROL_MERGE_KEYS);
257
+ const control = this.parseGroup(controlSchema, draft.control, "control");
258
+ this.commit(draft);
259
+ return control;
260
+ }
261
+ updateHost(patch) {
262
+ const draft = structuredClone(this.raw);
263
+ draft.host = { ...draft.host ?? {} };
264
+ applyPatch(draft.host, patch, EMPTY_MERGE_KEYS);
265
+ const host = this.parseGroup(hostSchema, draft.host, "host");
266
+ this.commit(draft);
267
+ return host;
268
+ }
269
+ updateBackups(patch) {
270
+ const draft = structuredClone(this.raw);
271
+ draft.backups = { ...draft.backups ?? {} };
272
+ applyPatch(draft.backups, patch, BACKUP_MERGE_KEYS);
273
+ const backups = this.parseGroup(backupsSchema, draft.backups, "backups");
274
+ this.commit(draft);
275
+ return backups;
276
+ }
277
+ /** The reverse proxy. `routes` is a list a patch replaces; `dns01` merges key by key. */
278
+ updateProxy(patch) {
279
+ const draft = structuredClone(this.raw);
280
+ draft.proxy = { ...draft.proxy ?? {} };
281
+ applyPatch(draft.proxy, patch, PROXY_MERGE_KEYS);
282
+ const proxy = this.parseGroup(proxyConfigSchema, draft.proxy, "proxy");
283
+ this.commit(draft);
284
+ return proxy;
285
+ }
286
+ /** Regenerates `settings.schema.json` for editor autocomplete, beside the file it describes. */
287
+ writeJsonSchema() {
288
+ const target = path.join(path.dirname(this.file), "settings.schema.json");
289
+ const schema = JSON.stringify(globalSettingsSchema.toJsonSchema(), null, 2);
290
+ if ((fs.existsSync(target) ? fs.readFileSync(target, "utf8") : null) !== schema) writeFileAtomic(target, schema);
291
+ }
292
+ parseGroup(schema, value, label) {
293
+ const parsed = parseTolerant(value, schema, label, []);
294
+ if (parsed.error !== null) throw new ConfigError(`${label}: ${parsed.error}`);
295
+ return parsed.value;
296
+ }
297
+ commit(draft) {
298
+ const stamped = stampConfig(draft);
299
+ const text = `${JSON.stringify(stamped, null, 2)}\n`;
300
+ writeFileAtomic(this.file, text);
301
+ this.lastText = text;
302
+ this.raw = stamped;
303
+ this.apply(stamped);
304
+ this.notify();
305
+ }
306
+ resolveFallback() {
307
+ const control = controlSchema({});
308
+ const host = hostSchema({});
309
+ const backups = backupsSchema({});
310
+ const proxy = proxyConfigSchema({});
311
+ if (control instanceof type.errors || host instanceof type.errors || backups instanceof type.errors || proxy instanceof type.errors) throw new ConfigError("internal: default settings failed validation");
312
+ return {
313
+ control,
314
+ host,
315
+ backups,
316
+ proxy
317
+ };
318
+ }
319
+ apply(raw) {
320
+ const parsed = parseGlobalSettings(raw);
321
+ this.raw = structuredClone(raw);
322
+ this.error = parsed.errors.length > 0 ? parsed.errors.join("; ") : null;
323
+ this.schemaVersion = parsed.schemaVersion;
324
+ this.warnings = [...parsed.warnings, ...parsed.unknownKeys.length === 0 ? [] : [`${path.basename(this.file)} carries ${parsed.unknownKeys.length} unrecognized key(s) this release ignores: ${parsed.unknownKeys.join(", ")}`]];
325
+ if (parsed.config !== null) this.resolvedConfig = parsed.config;
326
+ else if (this.resolvedConfig === void 0) this.resolvedConfig = this.resolveFallback();
327
+ }
328
+ };
329
+ //#endregion
330
+ export { SEED_WORKSPACE_SETTINGS as a, NOTIFICATION_MERGE_KEYS as c, applyPatch as d, SEED_SERVERS_FILE as i, PROXY_MERGE_KEYS as l, GlobalSettingsStore as n, DDNS_MERGE_KEYS as o, settings_exports as r, EMPTY_MERGE_KEYS as s, ConfigError as t, SERVER_MERGE_KEYS as u };
331
+
332
+ //# sourceMappingURL=settings-BVSBnIwJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-BVSBnIwJ.js","names":[],"sources":["../../src/config/patch.ts","../../src/config/seed.ts","../../src/config/settings.ts"],"sourcesContent":["import { isRecord } from '#src/shared/shape'\n/** Nested groups a patch merges into instead of replacing. */\nexport const SERVER_MERGE_KEYS = new Set(['restart', 'health', 'stop'])\nexport const CONTROL_MERGE_KEYS = new Set(['auth', 'tls'])\n/** The general block merges key by key; `destinations` is a list a patch replaces. */\nexport const NOTIFICATION_MERGE_KEYS = new Set(['defaults'])\n/** The DDNS lists are replaced; only its two IP-family groups merge. */\nexport const DDNS_MERGE_KEYS = new Set(['ipv4', 'ipv6'])\n/** The proxy's one nested group; `routes` and `certificates` are lists a patch replaces. */\nexport const PROXY_MERGE_KEYS = new Set(['dns01'])\n/** Backups' scheduled half merges, so a patch sending only `intervalMs` keeps the retention. */\nexport const BACKUP_MERGE_KEYS = new Set(['schedule'])\nexport const EMPTY_MERGE_KEYS = new Set<string>()\n\nexport function applyPatch(target: Record<string, unknown>, patch: Record<string, unknown>, mergeKeys: Set<string>): void {\n for (const [key, value] of Object.entries(patch)) {\n if (value === undefined)\n continue\n if (mergeKeys.has(key) && isRecord(value) && isRecord(target[key])) {\n target[key] = mergeGroup(target[key], value)\n continue\n }\n // An explicit `null` **removes** the key, exactly as it does inside a group. Setting it instead made the\n // two paths disagree, and the stored `null` then failed the schema that reads the file:\n // `servers[0]: label must be a string (was null)`. This was reachable all along — `label` is not in\n // `SERVER_MERGE_KEYS`, so it took this branch.\n if (value === null) {\n delete target[key]\n continue\n }\n target[key] = value\n }\n}\n\n/**\n * Merges one nested group recursively — `health.http` is a group of its own, and\n * replacing it wholesale would silently reset the siblings a partial patch never\n * mentioned. An explicit `null` removes a key, which is how a schema-optional\n * field is cleared.\n */\nexport function mergeGroup(target: Record<string, unknown>, patch: Record<string, unknown>): Record<string, unknown> {\n const merged = { ...target }\n for (const [key, value] of Object.entries(patch)) {\n if (value === undefined)\n continue\n if (value === null) {\n delete merged[key]\n continue\n }\n if (isRecord(value) && isRecord(merged[key])) {\n merged[key] = mergeGroup(merged[key] as Record<string, unknown>, value)\n continue\n }\n merged[key] = value\n }\n return merged\n}\n","/**\n * Written when `$HHOSTED_HOME` has no state yet. Every seed stays empty of\n * servers on purpose: home-hosted ships none, so what a user supervises is\n * theirs to declare. The rest is default policy, which the settings pages can\n * change.\n */\n\n/** `$HHOSTED_HOME/.hh/settings.json`. */\nexport const SEED_GLOBAL_SETTINGS = {\n $schema: './settings.schema.json',\n control: {\n port: 3999,\n host: 'local',\n openBrowser: false,\n },\n} as const\n\n/** `$HHOSTED_HOME/.hh/<id>/settings.json`. */\nexport const SEED_WORKSPACE_SETTINGS = {\n $schema: './settings.schema.json',\n defaults: {\n enabled: true,\n autostart: false,\n bind: 'local',\n onPortConflict: 'block',\n },\n} as const\n\n/** `$HHOSTED_HOME/.hh/<id>/servers.config.json`. */\nexport const SEED_SERVERS_FILE = {\n $schema: './servers.config.schema.json',\n servers: [],\n} as const\n","import type { ResolvedGlobalConfig } from '#src/config/schema'\nimport type { BackupsConfig, ControlConfig, HostConfig, ProxyConfig, ProxyPatch, SettingsPatch } from '#src/shared/contracts'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { type } from 'arktype'\nimport { planConfigMigrations, UNSTAMPED_SCHEMA } from '#src/config/migrations'\nimport { parseGlobalSettings, parseTolerant, stampConfig } from '#src/config/parse'\nimport { applyPatch, BACKUP_MERGE_KEYS, CONTROL_MERGE_KEYS, EMPTY_MERGE_KEYS, PROXY_MERGE_KEYS } from '#src/config/patch'\nimport { backupsSchema, controlSchema, globalSettingsSchema, hostSchema, proxyConfigSchema } from '#src/config/schema'\nimport { SEED_GLOBAL_SETTINGS } from '#src/config/seed'\nimport { writeFileAtomic } from '#src/helpers/atomic'\nimport { readStateFile } from '#src/helpers/config-text'\nimport { globalSettingsPath } from '#src/helpers/paths'\n\nexport class ConfigError extends Error {\n override name = 'ConfigError'\n /**\n * The *kind* of config problem, when a caller has to branch on it rather than just report it.\n * `UNKNOWN_SERVER` is the one case today: the servers route answers 404 for a missing id and 400\n * for an invalid patch, and it decided that by matching the message text.\n */\n readonly code: 'UNKNOWN_SERVER' | undefined\n\n constructor(message: string, code?: 'UNKNOWN_SERVER') {\n super(message)\n this.code = code\n }\n}\n\n/**\n * The panel-wide settings file (`$HHOSTED_HOME/.hh/settings.json`): the listener,\n * authentication, TLS policy, host vitals and backups. Nothing here belongs to a\n * workspace, which is why it sits above them.\n */\nexport class GlobalSettingsStore {\n private raw: Record<string, unknown> = {}\n /** The bytes behind the live settings, so a watcher can tell a real edit from our own write. */\n private lastText: string | null = null\n private resolvedConfig!: ResolvedGlobalConfig\n private error: string | null = null\n /** A JSON parse failure, kept apart from a schema problem so `apply()` cannot clear it. */\n private parseError: string | null = null\n private warnings: string[] = []\n private schemaVersion = UNSTAMPED_SCHEMA\n private readonly listeners = new Set<() => void>()\n\n constructor(private readonly file: string = globalSettingsPath, private readonly seed: Record<string, unknown> = SEED_GLOBAL_SETTINGS) {}\n\n get path(): string {\n return this.file\n }\n\n get config(): ResolvedGlobalConfig {\n return this.resolvedConfig\n }\n\n get control(): ControlConfig {\n return this.resolvedConfig.control\n }\n\n get host(): HostConfig {\n return this.resolvedConfig.host\n }\n\n get backups(): BackupsConfig {\n return this.resolvedConfig.backups\n }\n\n get proxy(): ProxyConfig {\n return this.resolvedConfig.proxy\n }\n\n get configError(): string | null {\n return this.error\n }\n\n /** Keys a newer release wrote that this one ignores; nothing to refuse over. */\n get configWarnings(): string[] {\n return [...this.warnings]\n }\n\n get configSchemaVersion(): number {\n return this.schemaVersion\n }\n\n /**\n * Steps that would have to run before this release could use the file.\n *\n * A file that cannot be **parsed** has no schema to plan from, and `migrate` refuses one it\n * cannot read rather than lifting it — so claiming a migration here sends the person to the one\n * command guaranteed not to help. Measured: a truncated `.hh/settings.json` made `up` say\n * \"needs 1 migration(s)\" and `migrate` answer \"cannot read … Unexpected end of JSON input\". The\n * workspace pair already excluded the parse failure (`WorkspaceStore.pendingMigrations`); this is\n * the same rule on the global file, which is the one the startup guard reads first.\n */\n get pendingMigrations() {\n if (this.parseError !== null)\n return []\n return planConfigMigrations(this.schemaVersion).steps\n }\n\n get rawConfig(): Record<string, unknown> {\n return structuredClone(this.raw)\n }\n\n onChange(listener: () => void): () => void {\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n load(): void {\n this.read()\n this.notify()\n }\n\n reloadFromDisk(): { changed: boolean, applied: boolean, error: string | null } {\n let text: string\n try {\n text = readStateFile(this.file)\n }\n catch {\n this.error = `${path.basename(this.file)} is gone`\n return { changed: false, applied: false, error: this.error }\n }\n\n if (text === this.lastText) {\n if (this.error !== null) {\n this.error = null\n this.load()\n }\n return { changed: false, applied: false, error: null }\n }\n\n const before = this.resolvedConfig\n this.load()\n return { changed: true, applied: this.resolvedConfig !== before, error: this.error }\n }\n\n private read(): void {\n // Cleared up front so both branches answer the same question: a file that reads cleanly now is\n // not still \"unparseable\" from the read before it.\n this.parseError = null\n if (!fs.existsSync(this.file)) {\n const seed = stampConfig(structuredClone(this.seed))\n const text = `${JSON.stringify(seed, null, 2)}\\n`\n writeFileAtomic(this.file, text)\n this.lastText = text\n this.raw = seed\n this.apply(seed)\n return\n }\n\n let text: string\n let parsed: unknown\n try {\n text = readStateFile(this.file)\n parsed = JSON.parse(text)\n }\n catch (error) {\n this.error = `cannot parse ${path.basename(this.file)}: ${(error as Error).message}`\n this.parseError = this.error\n if (this.resolvedConfig === undefined) {\n this.raw = {}\n this.resolvedConfig = this.resolveFallback()\n }\n return\n }\n\n this.lastText = text\n this.apply(parsed)\n }\n\n private notify(): void {\n for (const listener of this.listeners) listener()\n }\n\n updateControl(patch: NonNullable<SettingsPatch['control']>): ControlConfig {\n const draft = structuredClone(this.raw)\n draft.control = { ...(draft.control as Record<string, unknown> ?? {}) }\n applyPatch(draft.control as Record<string, unknown>, patch as Record<string, unknown>, CONTROL_MERGE_KEYS)\n\n const control = this.parseGroup<ControlConfig>(controlSchema as unknown as (input: unknown) => unknown, draft.control as Record<string, unknown>, 'control')\n\n this.commit(draft)\n return control\n }\n\n updateHost(patch: NonNullable<SettingsPatch['host']>): HostConfig {\n const draft = structuredClone(this.raw)\n draft.host = { ...(draft.host as Record<string, unknown> ?? {}) }\n applyPatch(draft.host as Record<string, unknown>, patch as Record<string, unknown>, EMPTY_MERGE_KEYS)\n\n const host = this.parseGroup<HostConfig>(hostSchema as unknown as (input: unknown) => unknown, draft.host as Record<string, unknown>, 'host')\n\n this.commit(draft)\n return host\n }\n\n updateBackups(patch: NonNullable<SettingsPatch['backups']>): BackupsConfig {\n const draft = structuredClone(this.raw)\n draft.backups = { ...(draft.backups as Record<string, unknown> ?? {}) }\n applyPatch(draft.backups as Record<string, unknown>, patch as Record<string, unknown>, BACKUP_MERGE_KEYS)\n\n const backups = this.parseGroup<BackupsConfig>(backupsSchema as unknown as (input: unknown) => unknown, draft.backups as Record<string, unknown>, 'backups')\n\n this.commit(draft)\n return backups\n }\n\n /** The reverse proxy. `routes` is a list a patch replaces; `dns01` merges key by key. */\n updateProxy(patch: ProxyPatch): ProxyConfig {\n const draft = structuredClone(this.raw)\n draft.proxy = { ...(draft.proxy as Record<string, unknown> ?? {}) }\n applyPatch(draft.proxy as Record<string, unknown>, patch as Record<string, unknown>, PROXY_MERGE_KEYS)\n\n const proxy = this.parseGroup<ProxyConfig>(proxyConfigSchema as unknown as (input: unknown) => unknown, draft.proxy as Record<string, unknown>, 'proxy')\n\n this.commit(draft)\n return proxy\n }\n\n /** Regenerates `settings.schema.json` for editor autocomplete, beside the file it describes. */\n writeJsonSchema(): void {\n const target = path.join(path.dirname(this.file), 'settings.schema.json')\n const schema = JSON.stringify(globalSettingsSchema.toJsonSchema(), null, 2)\n const current = fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : null\n if (current !== schema)\n writeFileAtomic(target, schema)\n }\n\n private parseGroup<T>(schema: (input: unknown) => unknown, value: Record<string, unknown>, label: string): T {\n const parsed = parseTolerant(value, schema, label, [])\n if (parsed.error !== null)\n throw new ConfigError(`${label}: ${parsed.error}`)\n return parsed.value as T\n }\n\n private commit(draft: Record<string, unknown>): void {\n const stamped = stampConfig(draft)\n const text = `${JSON.stringify(stamped, null, 2)}\\n`\n writeFileAtomic(this.file, text)\n this.lastText = text\n this.raw = stamped\n this.apply(stamped)\n this.notify()\n }\n\n private resolveFallback(): ResolvedGlobalConfig {\n const control = controlSchema({})\n const host = hostSchema({})\n const backups = backupsSchema({})\n const proxy = proxyConfigSchema({})\n if (control instanceof type.errors || host instanceof type.errors || backups instanceof type.errors || proxy instanceof type.errors)\n throw new ConfigError('internal: default settings failed validation')\n return { control, host, backups, proxy }\n }\n\n private apply(raw: unknown): void {\n const parsed = parseGlobalSettings(raw)\n this.raw = structuredClone(raw as Record<string, unknown>)\n this.error = parsed.errors.length > 0 ? parsed.errors.join('; ') : null\n this.schemaVersion = parsed.schemaVersion\n this.warnings = [\n ...parsed.warnings,\n ...(parsed.unknownKeys.length === 0\n ? []\n : [`${path.basename(this.file)} carries ${parsed.unknownKeys.length} unrecognized key(s) this release ignores: ${parsed.unknownKeys.join(', ')}`]),\n ]\n if (parsed.config !== null)\n this.resolvedConfig = parsed.config\n else if (this.resolvedConfig === undefined)\n this.resolvedConfig = this.resolveFallback()\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAEA,IAAa,oCAAoB,IAAI,IAAI;CAAC;CAAW;CAAU;AAAM,CAAC;AACtE,IAAa,qCAAqB,IAAI,IAAI,CAAC,QAAQ,KAAK,CAAC;;AAEzD,IAAa,0CAA0B,IAAI,IAAI,CAAC,UAAU,CAAC;;AAE3D,IAAa,kCAAkB,IAAI,IAAI,CAAC,QAAQ,MAAM,CAAC;;AAEvD,IAAa,mCAAmB,IAAI,IAAI,CAAC,OAAO,CAAC;;AAEjD,IAAa,oCAAoB,IAAI,IAAI,CAAC,UAAU,CAAC;AACrD,IAAa,mCAAmB,IA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,SAAS,MAAM,CAAC,EAAE;EACjD,gBAAgB,KAAK,MAAM,IAAI;EAC/B,KAAK,WAAW;EAChB,KAAK,MAAM;EACX,KAAK,MAAM,OAAO;EAClB,KAAK,OAAO;CACd;CAEA,kBAAgD;EAC9C,MAAM,UAAU,cAAc,CAAC,CAAC;EAChC,MAAM,OAAO,WAAW,CAAC,CAAC;EAC1B,MAAM,UAAU,cAAc,CAAC,CAAC;EAChC,MAAM,QAAQ,kBAAkB,CAAC,CAAC;EAClC,IAAI,mBAAmB,KAAK,UAAU,gBAAgB,KAAK,UAAU,mBAAmB,KAAK,UAAU,iBAAiB,KAAK,QAC3H,MAAM,IAAI,YAAY,8CAA8C;EACtE,OAAO;GAAE;GAAS;GAAM;GAAS;EAAM;CACzC;CAEA,MAAc,KAAoB;EAChC,MAAM,SAAS,oBAAoB,GAAG;EACtC,KAAK,MAAM,gBAAgB,GAA8B;EACzD,KAAK,QAAQ,OAAO,OAAO,SAAS,IAAI,OAAO,OAAO,KAAK,IAAI,IAAI;EACnE,KAAK,gBAAgB,OAAO;EAC5B,KAAK,WAAW,CACd,GAAG,OAAO,UACV,GAAI,OAAO,YAAY,WAAW,IAC9B,CAAC,IACD,CAAC,GAAG,KAAK,SAAS,KAAK,IAAI,EAAE,WAAW,OAAO,YAAY,OAAO,6CAA6C,OAAO,YAAY,KAAK,IAAI,GAAG,CACpJ;EACA,IAAI,OAAO,WAAW,MACpB,KAAK,iBAAiB,OAAO;OAC1B,IAAI,KAAK,mBAAmB,KAAA,GAC/B,KAAK,iBAAiB,KAAK,gBAAgB;CAC/C;AACF"}
@@ -0,0 +1,150 @@
1
+ import { _ as prompt, c as bold, d as dim, f as fail, m as green } from "../cli.js";
2
+ import { n as GlobalSettingsStore } from "./settings-BVSBnIwJ.js";
3
+ import { a as globalSettingsPath } from "./paths-BT94q6-w.js";
4
+ import { a as removeWslTemperatureScript, c as writeWslTemperatureScript, i as probeWslTemperature, l as wslScriptPath, n as lhmDirectoryWindows, o as tempCommandFor, r as lhmInstalled, s as windowsScriptPath, t as installLibreHardwareMonitor } from "./wsl-temperature-BiCI4iK6.js";
5
+ import process from "node:process";
6
+ import { defineCommand } from "citty";
7
+ import fs from "node:fs";
8
+ //#region src/cli/setup-temp.ts
9
+ /**
10
+ * `setup-temp` — teach the panel how to read this machine's CPU temperature.
11
+ *
12
+ * `--wsl` is one *source*; the next bridge is another flag beside it, not a second command.
13
+ */
14
+ var setupTempArgs = {
15
+ wsl: {
16
+ type: "boolean",
17
+ description: "read the temperature through the Windows host (WSL2)",
18
+ default: false
19
+ },
20
+ clear: {
21
+ type: "boolean",
22
+ description: "stop using a configured command and delete its helper",
23
+ default: false
24
+ },
25
+ download: {
26
+ type: "boolean",
27
+ description: "download LibreHardwareMonitor without asking; --no-download never does (for a script)"
28
+ }
29
+ };
30
+ /** Which source a flag names, or null when the invocation asks for no change. */
31
+ function sourceFromFlags(flags) {
32
+ if (flags.clear === true) return null;
33
+ if (flags.wsl === true) return "wsl";
34
+ return null;
35
+ }
36
+ /**
37
+ * The refusal for a flag set that cannot mean what it says, or `null`.
38
+ *
39
+ * `download` is a **modifier of `--wsl`**, not a command of its own: only the WSL2 branch fetches
40
+ * anything, and the no-flag branch ends before a source is chosen. Left unreachable it was silently
41
+ * dropped — `setup-temp --download` exited 0 having done nothing, which a script reads as
42
+ * "installed" — so the flag is refused instead, naming the one it belongs to.
43
+ *
44
+ * `--clear` is the opposite request, so pairing it with either is refused rather than letting one
45
+ * quietly win.
46
+ */
47
+ function flagProblem(flags) {
48
+ const download = flags.download === void 0 ? null : flags.download === true ? "--download" : "--no-download";
49
+ if (flags.clear === true) {
50
+ if (download !== null) return `\`--clear\` and \`${download}\` ask for opposite things — clear the source, or set one up, not both`;
51
+ if (flags.wsl === true) return "`--clear` and `--wsl` ask for opposite things — clear the source, or set one up, not both";
52
+ return null;
53
+ }
54
+ if (download !== null && flags.wsl !== true) return `\`${download}\` only means something with \`--wsl\` — pass \`setup-temp --wsl ${download}\`, or drop it to read the state`;
55
+ return null;
56
+ }
57
+ async function runSetupTemp(flags) {
58
+ const problem = flagProblem(flags);
59
+ if (problem !== null) fail(problem);
60
+ const store = new GlobalSettingsStore(globalSettingsPath);
61
+ store.load();
62
+ const host = store.host;
63
+ const configured = host.tempCommand.trim().length > 0;
64
+ if (flags.clear === true) {
65
+ const helper = wslScriptPath();
66
+ const hadHelper = helper !== null && fs.existsSync(helper);
67
+ if (configured) store.updateHost({ tempCommand: "" });
68
+ removeWslTemperatureScript(helper);
69
+ if (!configured && !hadHelper) {
70
+ process.stdout.write("no temperature command is set — nothing to clear\n");
71
+ return;
72
+ }
73
+ if (!configured) {
74
+ process.stdout.write(`no temperature command is set — removed the leftover helper at ${dim(helper)}\n`);
75
+ return;
76
+ }
77
+ process.stdout.write(`${green("temperature command cleared")} — the tile uses the built-in probe again\n`);
78
+ if (hadHelper) process.stdout.write(` ${dim(`helper ${helper} deleted`)}\n`);
79
+ return;
80
+ }
81
+ const source = sourceFromFlags(flags);
82
+ if (source === null) {
83
+ if (configured) {
84
+ process.stdout.write(`${green("a temperature command is set")}: ${bold(host.tempCommand)}\n`);
85
+ const probe = await probeWslTemperature(host.tempCommand, host.tempCommandTimeoutMs);
86
+ process.stdout.write(probe.celsius === null ? ` ${dim(`it did not answer: ${probe.error ?? "unknown reason"}`)}\n` : ` last reading: ${green(`${probe.celsius}°C`)}\n`);
87
+ return;
88
+ }
89
+ process.stdout.write("the panel reads the temperature from the kernel when the machine exposes a sensor.\n");
90
+ process.stdout.write(`this machine: ${host.tempCelsius > 0 ? `threshold ${host.tempCelsius}°C` : "no temperature alert"}\n`);
91
+ process.stdout.write(`\n${dim("if the Host vitals tile says n/a, set a source up:")}\n`);
92
+ process.stdout.write(` ${bold("setup-temp --wsl")} read it through the Windows host (WSL2)\n`);
93
+ return;
94
+ }
95
+ if (source === "wsl") {
96
+ const { isWsl } = await import("./wsl-temperature-BiCI4iK6.js").then((n) => n.d);
97
+ if (!isWsl()) fail("--wsl is for a WSL2 guest, and this is not one. Run `setup-temp` with no flag to see the options");
98
+ const scriptPath = wslScriptPath();
99
+ if (scriptPath === null) fail("the Windows drive is not mounted, so the helper cannot be written where powershell.exe can read it");
100
+ if (!lhmInstalled()) await offerLibreHardwareMonitor(flags);
101
+ writeWslTemperatureScript(scriptPath);
102
+ const command = tempCommandFor(scriptPath);
103
+ process.stdout.write(` helper ${dim(`${scriptPath} (${windowsScriptPath(scriptPath)} on Windows)`)}\n`);
104
+ const probe = await probeWslTemperature(command, 5e3);
105
+ if (probe.celsius === null) fail(`not set up — the helper did not answer: ${probe.error ?? "unknown reason"}\n the script is at ${scriptPath}; the config was left unchanged`);
106
+ store.updateHost({
107
+ tempCommand: command,
108
+ tempCommandTimeoutMs: 5e3
109
+ });
110
+ process.stdout.write(`${green("WSL temperature bridge set up")}\n`);
111
+ process.stdout.write(` command ${bold(command)}\n`);
112
+ process.stdout.write(` reading ${green(`${probe.celsius}°C`)}\n`);
113
+ }
114
+ }
115
+ /**
116
+ * Offer the ~6 MB download. A prompt, never a silent fetch: installing software nobody asked for is
117
+ * not a setup command's job, and a non-interactive stdin answers no.
118
+ */
119
+ async function offerLibreHardwareMonitor(flags) {
120
+ const where = lhmDirectoryWindows() ?? "C:\\ProgramData\\home-hosted\\LibreHardwareMonitor";
121
+ if (flags.download !== true) {
122
+ if (flags.download === false) {
123
+ process.stdout.write(`${dim(`LibreHardwareMonitor is not installed; install it into ${where}, or pass --download`)}\n`);
124
+ return;
125
+ }
126
+ const answer = await prompt(`LibreHardwareMonitor is required to read the sensor. Download it now (~6 MB)? [y/N] `);
127
+ if (!/^y(?:es)?$/i.test(answer.trim())) {
128
+ process.stdout.write(`${dim(`left it alone — install it into ${where} and re-run this command`)}\n`);
129
+ return;
130
+ }
131
+ }
132
+ const result = await installLibreHardwareMonitor({ onProgress: (message) => process.stdout.write(` ${dim(message)}\n`) });
133
+ if (result.error !== null) fail(`the download did not install — ${result.error}`);
134
+ process.stdout.write(` library ${green("installed")} in ${result.dir}\n`);
135
+ }
136
+ var setupTempCommand = defineCommand({
137
+ meta: { name: "setup-temp" },
138
+ args: setupTempArgs,
139
+ async run({ args }) {
140
+ await runSetupTemp({
141
+ wsl: args.wsl === true,
142
+ clear: args.clear === true,
143
+ download: args.download
144
+ });
145
+ }
146
+ });
147
+ //#endregion
148
+ export { setupTempCommand };
149
+
150
+ //# sourceMappingURL=setup-temp-XiuAtiW2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-temp-XiuAtiW2.js","names":[],"sources":["../../src/cli/setup-temp.ts"],"sourcesContent":["import fs from 'node:fs'\nimport process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { bold, dim, fail, green, prompt } from '#src/cli/io'\nimport { GlobalSettingsStore } from '#src/config/settings'\nimport { globalSettingsPath } from '#src/helpers/paths'\nimport { installLibreHardwareMonitor, lhmDirectoryWindows, lhmInstalled, probeWslTemperature, removeWslTemperatureScript, tempCommandFor, windowsScriptPath, writeWslTemperatureScript, wslScriptPath } from '#src/providers/wsl-temperature'\n\n/**\n * `setup-temp` — teach the panel how to read this machine's CPU temperature.\n *\n * `--wsl` is one *source*; the next bridge is another flag beside it, not a second command.\n */\n\nexport const setupTempArgs = {\n wsl: { type: 'boolean', description: 'read the temperature through the Windows host (WSL2)', default: false },\n clear: { type: 'boolean', description: 'stop using a configured command and delete its helper', default: false },\n // No `default`: citty leaves it `undefined` when absent and `false` for `--no-download`, which is\n // what lets one flag express the three outcomes — ask, install, refuse — instead of needing a\n // second flag to say \"no\".\n download: { type: 'boolean', description: 'download LibreHardwareMonitor without asking; --no-download never does (for a script)' },\n} as const\n\n/** The temperature sources `setup-temp` can install. One today; a flag each as more appear. */\nexport type TemperatureSource = 'wsl'\n\n/** Which source a flag names, or null when the invocation asks for no change. */\nexport function sourceFromFlags(flags: { wsl?: boolean, clear?: boolean }): TemperatureSource | null {\n if (flags.clear === true)\n return null\n if (flags.wsl === true)\n return 'wsl'\n return null\n}\n\n/**\n * The refusal for a flag set that cannot mean what it says, or `null`.\n *\n * `download` is a **modifier of `--wsl`**, not a command of its own: only the WSL2 branch fetches\n * anything, and the no-flag branch ends before a source is chosen. Left unreachable it was silently\n * dropped — `setup-temp --download` exited 0 having done nothing, which a script reads as\n * \"installed\" — so the flag is refused instead, naming the one it belongs to.\n *\n * `--clear` is the opposite request, so pairing it with either is refused rather than letting one\n * quietly win.\n */\nexport function flagProblem(flags: { wsl?: boolean, clear?: boolean, download?: boolean }): string | null {\n const download = flags.download === undefined ? null : flags.download === true ? '--download' : '--no-download'\n if (flags.clear === true) {\n if (download !== null)\n return `\\`--clear\\` and \\`${download}\\` ask for opposite things — clear the source, or set one up, not both`\n if (flags.wsl === true)\n return '`--clear` and `--wsl` ask for opposite things — clear the source, or set one up, not both'\n return null\n }\n if (download !== null && flags.wsl !== true)\n return `\\`${download}\\` only means something with \\`--wsl\\` — pass \\`setup-temp --wsl ${download}\\`, or drop it to read the state`\n return null\n}\n\nexport async function runSetupTemp(flags: { wsl?: boolean, clear?: boolean, download?: boolean }): Promise<void> {\n // Before any read: a flag this command cannot honour is a mistake in the invocation, not a\n // property of the machine's config.\n const problem = flagProblem(flags)\n if (problem !== null)\n fail(problem)\n\n const store = new GlobalSettingsStore(globalSettingsPath)\n store.load()\n const host = store.host\n const configured = host.tempCommand.trim().length > 0\n\n if (flags.clear === true) {\n // `--clear` promises to delete the helper as well as the setting, and it used to clear the\n // command only: measured, the file outlived every `--clear`. A stale helper is also the one\n // thing left when the command is already empty, so it is removed on both paths.\n const helper = wslScriptPath()\n const hadHelper = helper !== null && fs.existsSync(helper)\n if (configured)\n store.updateHost({ tempCommand: '' })\n removeWslTemperatureScript(helper)\n if (!configured && !hadHelper) {\n process.stdout.write('no temperature command is set — nothing to clear\\n')\n return\n }\n if (!configured) {\n process.stdout.write(`no temperature command is set — removed the leftover helper at ${dim(helper!)}\\n`)\n return\n }\n process.stdout.write(`${green('temperature command cleared')} — the tile uses the built-in probe again\\n`)\n if (hadHelper)\n process.stdout.write(` ${dim(`helper ${helper!} deleted`)}\\n`)\n return\n }\n\n const source = sourceFromFlags(flags)\n if (source === null) {\n // No flag: say what is going on, so this is the one command a confused person types.\n if (configured) {\n process.stdout.write(`${green('a temperature command is set')}: ${bold(host.tempCommand)}\\n`)\n const probe = await probeWslTemperature(host.tempCommand, host.tempCommandTimeoutMs)\n process.stdout.write(probe.celsius === null\n ? ` ${dim(`it did not answer: ${probe.error ?? 'unknown reason'}`)}\\n`\n : ` last reading: ${green(`${probe.celsius}°C`)}\\n`)\n return\n }\n process.stdout.write('the panel reads the temperature from the kernel when the machine exposes a sensor.\\n')\n process.stdout.write(`this machine: ${host.tempCelsius > 0 ? `threshold ${host.tempCelsius}°C` : 'no temperature alert'}\\n`)\n process.stdout.write(`\\n${dim('if the Host vitals tile says n/a, set a source up:')}\\n`)\n process.stdout.write(` ${bold('setup-temp --wsl')} read it through the Windows host (WSL2)\\n`)\n return\n }\n\n if (source === 'wsl') {\n const { isWsl } = await import('#src/providers/wsl-temperature')\n if (!isWsl()) {\n fail('--wsl is for a WSL2 guest, and this is not one. Run `setup-temp` with no flag to see the options')\n }\n const scriptPath = wslScriptPath()\n if (scriptPath === null) {\n fail('the Windows drive is not mounted, so the helper cannot be written where powershell.exe can read it')\n }\n // The helper only prints a number; the sensor comes from LibreHardwareMonitor, a third-party\n // Windows binary the panel does not ship. Offer to fetch it — someone who just typed this\n // command has no way to know a library is missing, and the tile only ever says `n/a`.\n if (!lhmInstalled())\n await offerLibreHardwareMonitor(flags)\n\n writeWslTemperatureScript(scriptPath)\n const command = tempCommandFor(scriptPath)\n process.stdout.write(` helper ${dim(`${scriptPath} (${windowsScriptPath(scriptPath)} on Windows)`)}\\n`)\n\n // Probe **before** saving. A command that cannot work must not reach the config: the panel would\n // run a failing PowerShell on every sample, and the tile would stay `n/a` while the settings page\n // claimed a source was configured — the one state a person has no way to diagnose.\n const probe = await probeWslTemperature(command, 5000)\n if (probe.celsius === null) {\n // One refusal, whole, on stderr. It used to be built as `${fail('not set up')} — …`, and\n // `fail()` exits before the template is finished, so the reason the probe gave was lost.\n fail(`not set up — the helper did not answer: ${probe.error ?? 'unknown reason'}\\n the script is at ${scriptPath}; the config was left unchanged`)\n }\n\n store.updateHost({ tempCommand: command, tempCommandTimeoutMs: 5000 })\n process.stdout.write(`${green('WSL temperature bridge set up')}\\n`)\n process.stdout.write(` command ${bold(command)}\\n`)\n process.stdout.write(` reading ${green(`${probe.celsius}°C`)}\\n`)\n }\n}\n\n/**\n * Offer the ~6 MB download. A prompt, never a silent fetch: installing software nobody asked for is\n * not a setup command's job, and a non-interactive stdin answers no.\n */\nasync function offerLibreHardwareMonitor(flags: { download?: boolean }): Promise<void> {\n const where = lhmDirectoryWindows() ?? 'C:\\\\ProgramData\\\\home-hosted\\\\LibreHardwareMonitor'\n\n // `undefined` (absent): ask. `true` (`--download`): install. `false` (`--no-download`): refuse.\n if (flags.download !== true) {\n if (flags.download === false) {\n process.stdout.write(`${dim(`LibreHardwareMonitor is not installed; install it into ${where}, or pass --download`)}\\n`)\n return\n }\n const answer = await prompt(`LibreHardwareMonitor is required to read the sensor. Download it now (~6 MB)? [y/N] `)\n if (!/^y(?:es)?$/i.test(answer.trim())) {\n process.stdout.write(`${dim(`left it alone — install it into ${where} and re-run this command`)}\\n`)\n return\n }\n }\n\n const result = await installLibreHardwareMonitor({ onProgress: message => process.stdout.write(` ${dim(message)}\\n`) })\n if (result.error !== null)\n fail(`the download did not install — ${result.error}`)\n process.stdout.write(` library ${green('installed')} in ${result.dir}\\n`)\n}\n\nexport const setupTempCommand = defineCommand({\n meta: { name: 'setup-temp' },\n args: setupTempArgs,\n async run({ args }) {\n await runSetupTemp({ wsl: args.wsl === true, clear: args.clear === true, download: args.download })\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAcA,IAAa,gBAAgB;CAC3B,KAAK;EAAE,MAAM;EAAW,aAAa;EAAwD,SAAS;CAAM;CAC5G,OAAO;EAAE,MAAM;EAAW,aAAa;EAAy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sB;EAAK,CAAC;EACrE,QAAQ,OAAO,MAAM,GAAG,MAAM,+BAA+B,EAAE,GAAG;EAClE,QAAQ,OAAO,MAAM,aAAa,KAAK,OAAO,EAAE,GAAG;EACnD,QAAQ,OAAO,MAAM,aAAa,MAAM,GAAG,MAAM,QAAQ,GAAG,EAAE,GAAG;CACnE;AACF;;;;;AAMA,eAAe,0BAA0B,OAA8C;CACrF,MAAM,QAAQ,oBAAoB,KAAK;CAGvC,IAAI,MAAM,aAAa,MAAM;EAC3B,IAAI,MAAM,aAAa,OAAO;GAC5B,QAAQ,OAAO,MAAM,GAAG,IAAI,0DAA0D,MAAM,qBAAqB,EAAE,GAAG;GACtH;EACF;EACA,MAAM,SAAS,MAAM,OAAO,sFAAsF;EAClH,IAAI,CAAC,cAAc,KAAK,OAAO,KAAK,CAAC,GAAG;GACtC,QAAQ,OAAO,MAAM,GAAG,IAAI,mCAAmC,MAAM,yBAAyB,EAAE,GAAG;GACnG;EACF;CACF;CAEA,MAAM,SAAS,MAAM,4BAA4B,EAAE,aAAY,YAAW,QAAQ,OAAO,MAAM,KAAK,IAAI,OAAO,EAAE,GAAG,EAAE,CAAC;CACvH,IAAI,OAAO,UAAU,MACnB,KAAK,kCAAkC,OAAO,OAAO;CACvD,QAAQ,OAAO,MAAM,aAAa,MAAM,WAAW,EAAE,MAAM,OAAO,IAAI,GAAG;AAC3E;AAEA,IAAa,mBAAmB,cAAc;CAC5C,MAAM,EAAE,MAAM,aAAa;CAC3B,MAAM;CACN,MAAM,IAAI,EAAE,QAAQ;EAClB,MAAM,aAAa;GAAE,KAAK,KAAK,QAAQ;GAAM,OAAO,KAAK,UAAU;GAAM,UAAU,KAAK;EAAS,CAAC;CACpG;AACF,CAAC"}
@@ -0,0 +1,24 @@
1
+ //#region src/shared/shape.ts
2
+ /**
3
+ * A plain object, and nothing else: not `null`, and not an array.
4
+ *
5
+ * Every untyped boundary here narrows to this shape, and it lived as **nine** definitions across
6
+ * `src/` and the UIs: seven strict (one an inline ternary rather than a named function, which is why
7
+ * a search for the name found only some of them) and two — both UIs' `lib/api.ts` — that accepted an
8
+ * array.
9
+ *
10
+ * The `!Array.isArray` half is the one that matters: `typeof [] === 'object'` is true, so without
11
+ * it an array narrows to a record and reading a property off it silently yields `undefined`
12
+ * instead of failing — and iterating it with `Object.entries` yields the *indices*.
13
+ *
14
+ * The two loose copies happened to behave the same on the payloads they see, but only by accident
15
+ * of which properties they read. They use this one now, so the next reader does not have to work
16
+ * that out.
17
+ */
18
+ function isRecord(value) {
19
+ return typeof value === "object" && value !== null && !Array.isArray(value);
20
+ }
21
+ //#endregion
22
+ export { isRecord as t };
23
+
24
+ //# sourceMappingURL=shape-DnTKzjQ2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape-DnTKzjQ2.js","names":[],"sources":["../../src/shared/shape.ts"],"sourcesContent":["/**\n * A plain object, and nothing else: not `null`, and not an array.\n *\n * Every untyped boundary here narrows to this shape, and it lived as **nine** definitions across\n * `src/` and the UIs: seven strict (one an inline ternary rather than a named function, which is why\n * a search for the name found only some of them) and two — both UIs' `lib/api.ts` — that accepted an\n * array.\n *\n * The `!Array.isArray` half is the one that matters: `typeof [] === 'object'` is true, so without\n * it an array narrows to a record and reading a property off it silently yields `undefined`\n * instead of failing — and iterating it with `Object.entries` yields the *indices*.\n *\n * The two loose copies happened to behave the same on the payloads they see, but only by accident\n * of which properties they read. They use this one now, so the next reader does not have to work\n * that out.\n */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAgB,SAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E"}