@nervur.org/installer-node 0.0.0-stage → 0.37.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +159 -2
  3. package/SECURITY.md +8 -0
  4. package/bin/nervur.js +5 -0
  5. package/cargo/emscripten-module.wasm +0 -0
  6. package/cargo/manifest.json +1 -0
  7. package/cargo/sqlite3.wasm +0 -0
  8. package/cargo/table-i-i.wasm +0 -0
  9. package/cargo/table-i-ii.wasm +0 -0
  10. package/cargo/table-i-iii.wasm +0 -0
  11. package/cargo/table-i-iiii.wasm +0 -0
  12. package/cargo/table-i-iiiii.wasm +0 -0
  13. package/cargo/table-i-iiij.wasm +0 -0
  14. package/cargo/table-i-ij.wasm +0 -0
  15. package/cargo/table-v-ii.wasm +0 -0
  16. package/cargo/table-v-iii.wasm +0 -0
  17. package/cargo/worker.js +30808 -0
  18. package/organs/console/node/guard.d.ts +10 -0
  19. package/organs/console/node/guard.js +52 -0
  20. package/organs/console/node/index.d.ts +4 -0
  21. package/organs/console/node/index.js +5 -0
  22. package/organs/console/node/line.d.ts +16 -0
  23. package/organs/console/node/line.js +150 -0
  24. package/organs/console/node/main.js +51 -0
  25. package/organs/console/node/program.d.ts +1 -0
  26. package/organs/console/node/program.js +5 -0
  27. package/organs/console/node/proof.d.ts +15 -0
  28. package/organs/console/node/proof.js +84 -0
  29. package/organs/console/node/socket.d.ts +15 -0
  30. package/organs/console/node/socket.js +99 -0
  31. package/organs/disk/index.d.ts +1 -0
  32. package/organs/disk/index.js +2 -0
  33. package/organs/disk/node/files.js +162 -0
  34. package/organs/disk/node/main.js +20 -0
  35. package/organs/disk/node/program.d.ts +1 -0
  36. package/organs/disk/node/program.js +5 -0
  37. package/organs/disk/organ.d.ts +5 -0
  38. package/organs/disk/organ.js +69 -0
  39. package/organs/network/node/fill.d.ts +21 -0
  40. package/organs/network/node/fill.js +195 -0
  41. package/organs/network/node/flows.js +66 -0
  42. package/organs/network/node/half.js +260 -0
  43. package/organs/network/node/lines.d.ts +29 -0
  44. package/organs/network/node/lines.js +236 -0
  45. package/organs/network/node/link.d.ts +24 -0
  46. package/organs/network/node/link.js +215 -0
  47. package/organs/network/node/main.js +41 -0
  48. package/organs/network/node/moved.d.ts +2 -0
  49. package/organs/network/node/moved.js +20 -0
  50. package/organs/network/node/near.d.ts +63 -0
  51. package/organs/network/node/near.js +263 -0
  52. package/organs/network/node/program.d.ts +1 -0
  53. package/organs/network/node/program.js +5 -0
  54. package/organs/network/node/schemes.d.ts +1 -0
  55. package/organs/network/node/schemes.js +2 -0
  56. package/organs/network/node/sent.d.ts +13 -0
  57. package/organs/network/node/sent.js +101 -0
  58. package/organs/network/node/served.d.ts +19 -0
  59. package/organs/network/node/served.js +237 -0
  60. package/organs/screen/node/client.js +3 -0
  61. package/organs/screen/node/follow.js +266 -0
  62. package/organs/screen/node/frames.js +26 -0
  63. package/organs/screen/node/held.js +27 -0
  64. package/organs/screen/node/http.js +179 -0
  65. package/organs/screen/node/lay.js +116 -0
  66. package/organs/screen/node/leave.js +27 -0
  67. package/organs/screen/node/linked.js +69 -0
  68. package/organs/screen/node/listen.js +61 -0
  69. package/organs/screen/node/look.js +121 -0
  70. package/organs/screen/node/loop.js +154 -0
  71. package/organs/screen/node/main.js +74 -0
  72. package/organs/screen/node/mirror.js +112 -0
  73. package/organs/screen/node/notice.js +44 -0
  74. package/organs/screen/node/presser.js +11 -0
  75. package/organs/screen/node/presses.js +108 -0
  76. package/organs/screen/node/program.d.ts +1 -0
  77. package/organs/screen/node/program.js +5 -0
  78. package/organs/screen/node/shown.js +205 -0
  79. package/organs/screen/node/standing.js +29 -0
  80. package/organs/screen/node/state.js +80 -0
  81. package/organs/screen/node/tell.js +47 -0
  82. package/organs/screen/node/uid.js +65 -0
  83. package/organs/screen/node/worn.js +23 -0
  84. package/organs/shell/index.d.ts +1 -0
  85. package/organs/shell/index.js +2 -0
  86. package/organs/shell/node/main.js +26 -0
  87. package/organs/shell/node/output.js +70 -0
  88. package/organs/shell/node/pressure.js +14 -0
  89. package/organs/shell/node/program.d.ts +1 -0
  90. package/organs/shell/node/program.js +5 -0
  91. package/organs/shell/node/runs.js +220 -0
  92. package/organs/shell/node/told.js +70 -0
  93. package/organs/shell/organ.d.ts +5 -0
  94. package/organs/shell/organ.js +59 -0
  95. package/package.json +43 -4
  96. package/src/command/act.d.ts +31 -0
  97. package/src/command/act.js +261 -0
  98. package/src/command/answers.d.ts +3 -0
  99. package/src/command/answers.js +232 -0
  100. package/src/command/args.d.ts +14 -0
  101. package/src/command/args.js +220 -0
  102. package/src/command/arrive.d.ts +2 -0
  103. package/src/command/arrive.js +21 -0
  104. package/src/command/asked.d.ts +18 -0
  105. package/src/command/asked.js +49 -0
  106. package/src/command/backup.d.ts +18 -0
  107. package/src/command/backup.js +261 -0
  108. package/src/command/before.d.ts +40 -0
  109. package/src/command/before.js +249 -0
  110. package/src/command/born.d.ts +27 -0
  111. package/src/command/born.js +103 -0
  112. package/src/command/bridge.d.ts +19 -0
  113. package/src/command/bridge.js +152 -0
  114. package/src/command/chain.d.ts +9 -0
  115. package/src/command/chain.js +48 -0
  116. package/src/command/channel.d.ts +29 -0
  117. package/src/command/channel.js +263 -0
  118. package/src/command/choices.d.ts +35 -0
  119. package/src/command/choices.js +173 -0
  120. package/src/command/claim.d.ts +12 -0
  121. package/src/command/claim.js +46 -0
  122. package/src/command/commands.d.ts +16 -0
  123. package/src/command/commands.js +257 -0
  124. package/src/command/ends.d.ts +16 -0
  125. package/src/command/ends.js +78 -0
  126. package/src/command/follow.d.ts +12 -0
  127. package/src/command/follow.js +66 -0
  128. package/src/command/given.d.ts +39 -0
  129. package/src/command/given.js +53 -0
  130. package/src/command/held.d.ts +15 -0
  131. package/src/command/held.js +56 -0
  132. package/src/command/index.d.ts +1 -0
  133. package/src/command/index.js +203 -0
  134. package/src/command/jailer.d.ts +28 -0
  135. package/src/command/jailer.js +135 -0
  136. package/src/command/laid.d.ts +6 -0
  137. package/src/command/laid.js +31 -0
  138. package/src/command/left.d.ts +9 -0
  139. package/src/command/left.js +34 -0
  140. package/src/command/line.d.ts +7 -0
  141. package/src/command/line.js +39 -0
  142. package/src/command/link.d.ts +30 -0
  143. package/src/command/link.js +123 -0
  144. package/src/command/lobes.d.ts +1 -0
  145. package/src/command/lobes.js +10 -0
  146. package/src/command/locks.d.ts +17 -0
  147. package/src/command/locks.js +76 -0
  148. package/src/command/mcp/calls.d.ts +27 -0
  149. package/src/command/mcp/calls.js +155 -0
  150. package/src/command/mcp/notices.d.ts +22 -0
  151. package/src/command/mcp/notices.js +203 -0
  152. package/src/command/mcp/resources.d.ts +31 -0
  153. package/src/command/mcp/resources.js +108 -0
  154. package/src/command/mcp/server.d.ts +19 -0
  155. package/src/command/mcp/server.js +149 -0
  156. package/src/command/mcp/tools.d.ts +39 -0
  157. package/src/command/mcp/tools.js +131 -0
  158. package/src/command/mcp.d.ts +8 -0
  159. package/src/command/mcp.js +39 -0
  160. package/src/command/noticed.d.ts +11 -0
  161. package/src/command/noticed.js +55 -0
  162. package/src/command/older.d.ts +11 -0
  163. package/src/command/older.js +45 -0
  164. package/src/command/open.d.ts +24 -0
  165. package/src/command/open.js +107 -0
  166. package/src/command/passphrase.d.ts +6 -0
  167. package/src/command/passphrase.js +82 -0
  168. package/src/command/reclaim.d.ts +7 -0
  169. package/src/command/reclaim.js +47 -0
  170. package/src/command/refused.d.ts +4 -0
  171. package/src/command/refused.js +27 -0
  172. package/src/command/release.d.ts +27 -0
  173. package/src/command/release.js +153 -0
  174. package/src/command/repo.d.ts +31 -0
  175. package/src/command/repo.js +133 -0
  176. package/src/command/rewrap.d.ts +16 -0
  177. package/src/command/rewrap.js +175 -0
  178. package/src/command/runtime.d.ts +25 -0
  179. package/src/command/runtime.js +175 -0
  180. package/src/command/salvage.d.ts +4 -0
  181. package/src/command/salvage.js +42 -0
  182. package/src/command/screen.d.ts +14 -0
  183. package/src/command/screen.js +62 -0
  184. package/src/command/spawn.d.ts +23 -0
  185. package/src/command/spawn.js +213 -0
  186. package/src/command/start.d.ts +34 -0
  187. package/src/command/start.js +246 -0
  188. package/src/command/state.d.ts +5 -0
  189. package/src/command/state.js +39 -0
  190. package/src/command/token.d.ts +1 -0
  191. package/src/command/token.js +9 -0
  192. package/src/command/trial.d.ts +18 -0
  193. package/src/command/trial.js +108 -0
  194. package/src/command/undone.d.ts +3 -0
  195. package/src/command/undone.js +21 -0
  196. package/src/command/vouch.d.ts +1 -0
  197. package/src/command/vouch.js +15 -0
  198. package/src/command/windows-processes.d.ts +2 -0
  199. package/src/command/windows-processes.js +22 -0
  200. package/src/command/wipe.d.ts +9 -0
  201. package/src/command/wipe.js +105 -0
  202. package/src/command/words.d.ts +5 -0
  203. package/src/command/words.js +53 -0
  204. package/src/door/claim.d.ts +5 -0
  205. package/src/door/claim.js +21 -0
  206. package/src/door/claimed.d.ts +7 -0
  207. package/src/door/claimed.js +110 -0
  208. package/src/door/configuration.d.ts +40 -0
  209. package/src/door/configuration.js +206 -0
  210. package/src/door/design.d.ts +13 -0
  211. package/src/door/design.js +71 -0
  212. package/src/door/digests.d.ts +7 -0
  213. package/src/door/digests.js +36 -0
  214. package/src/door/distribution.d.ts +25 -0
  215. package/src/door/distribution.js +88 -0
  216. package/src/door/door.d.ts +41 -0
  217. package/src/door/door.js +219 -0
  218. package/src/door/dressed.d.ts +34 -0
  219. package/src/door/dressed.js +182 -0
  220. package/src/door/faculties.d.ts +29 -0
  221. package/src/door/faculties.js +88 -0
  222. package/src/door/longest.d.ts +6 -0
  223. package/src/door/longest.js +25 -0
  224. package/src/fills/account-only.d.ts +3 -0
  225. package/src/fills/account-only.js +24 -0
  226. package/src/fills/boot-key.d.ts +21 -0
  227. package/src/fills/boot-key.js +70 -0
  228. package/src/fills/boot-move.d.ts +25 -0
  229. package/src/fills/boot-move.js +86 -0
  230. package/src/fills/bridge.d.ts +13 -0
  231. package/src/fills/bridge.js +86 -0
  232. package/src/fills/chance.d.ts +2 -0
  233. package/src/fills/chance.js +7 -0
  234. package/src/fills/crypto.d.ts +2 -0
  235. package/src/fills/crypto.js +94 -0
  236. package/src/fills/flushed.d.ts +9 -0
  237. package/src/fills/flushed.js +80 -0
  238. package/src/fills/hardware.d.ts +18 -0
  239. package/src/fills/hardware.js +70 -0
  240. package/src/fills/held.d.ts +31 -0
  241. package/src/fills/held.js +171 -0
  242. package/src/fills/keepers.d.ts +23 -0
  243. package/src/fills/keepers.js +151 -0
  244. package/src/fills/keyring.d.ts +19 -0
  245. package/src/fills/keyring.js +131 -0
  246. package/src/fills/pages.d.ts +3 -0
  247. package/src/fills/pages.js +260 -0
  248. package/src/fills/reserve.d.ts +11 -0
  249. package/src/fills/reserve.js +72 -0
  250. package/src/fills/time.d.ts +2 -0
  251. package/src/fills/time.js +29 -0
  252. package/src/fills/unlocker.d.ts +6 -0
  253. package/src/fills/unlocker.js +26 -0
  254. package/src/fills/vitals.d.ts +8 -0
  255. package/src/fills/vitals.js +100 -0
  256. package/src/fills/windows-start.d.ts +2 -0
  257. package/src/fills/windows-start.js +21 -0
  258. package/src/halves/build.d.ts +10 -0
  259. package/src/halves/build.js +219 -0
  260. package/src/halves/end.d.ts +17 -0
  261. package/src/halves/end.js +157 -0
  262. package/src/halves/genome.d.ts +3 -0
  263. package/src/halves/genome.js +21 -0
  264. package/src/halves/handler.d.ts +8 -0
  265. package/src/halves/handler.js +40 -0
  266. package/src/halves/index.d.ts +5 -0
  267. package/src/halves/index.js +6 -0
  268. package/src/halves/laid.d.ts +12 -0
  269. package/src/halves/laid.js +103 -0
  270. package/src/halves/lent.d.ts +6 -0
  271. package/src/halves/lent.js +147 -0
  272. package/src/halves/native.d.ts +12 -0
  273. package/src/halves/native.js +53 -0
  274. package/src/halves/statements.d.ts +23 -0
  275. package/src/halves/statements.js +165 -0
  276. package/src/halves/tokens.d.ts +22 -0
  277. package/src/halves/tokens.js +135 -0
  278. package/src/link/link.d.ts +4 -0
  279. package/src/link/link.js +4 -0
  280. package/src/link/placeholder.d.ts +1 -0
  281. package/src/link/placeholder.js +21 -0
  282. package/src/link/steps.d.ts +52 -0
  283. package/src/link/steps.js +118 -0
  284. package/src/lobes/calls.d.ts +76 -0
  285. package/src/lobes/calls.js +61 -0
  286. package/src/lobes/channel.d.ts +76 -0
  287. package/src/lobes/channel.js +202 -0
  288. package/src/lobes/index.d.ts +1 -0
  289. package/src/lobes/index.js +2 -0
  290. package/src/lobes/lobes.d.ts +15 -0
  291. package/src/lobes/lobes.js +244 -0
  292. package/src/lobes/main.js +107 -0
  293. package/src/lobes/thread.d.ts +22 -0
  294. package/src/lobes/thread.js +270 -0
  295. package/src/organism/act.d.ts +8 -0
  296. package/src/organism/act.js +63 -0
  297. package/src/organism/beat.d.ts +5 -0
  298. package/src/organism/beat.js +45 -0
  299. package/src/organism/compiled.d.ts +2 -0
  300. package/src/organism/compiled.js +24 -0
  301. package/src/organism/folder.d.ts +88 -0
  302. package/src/organism/folder.js +259 -0
  303. package/src/organism/main.d.ts +1 -0
  304. package/src/organism/main.js +11 -0
  305. package/src/organism/organism.d.ts +1 -0
  306. package/src/organism/organism.js +220 -0
  307. package/src/organism/said.d.ts +12 -0
  308. package/src/organism/said.js +30 -0
  309. package/src/organism/told.d.ts +5 -0
  310. package/src/organism/told.js +110 -0
  311. package/src/organism/unlock.d.ts +8 -0
  312. package/src/organism/unlock.js +95 -0
  313. package/src/organism/upgrade.d.ts +24 -0
  314. package/src/organism/upgrade.js +145 -0
  315. package/src/organism/via.d.ts +7 -0
  316. package/src/organism/via.js +20 -0
  317. package/src/service/body.d.ts +8 -0
  318. package/src/service/body.js +34 -0
  319. package/src/service/handler.d.ts +20 -0
  320. package/src/service/handler.js +128 -0
  321. package/src/service/index.d.ts +4 -0
  322. package/src/service/index.js +16 -0
  323. package/src/service/manager.d.ts +18 -0
  324. package/src/service/manager.js +185 -0
  325. package/src/service/service.d.ts +24 -0
  326. package/src/service/service.js +200 -0
  327. package/src/service/swap.d.ts +12 -0
  328. package/src/service/swap.js +74 -0
  329. package/src/service/watchdog.d.ts +6 -0
  330. package/src/service/watchdog.js +31 -0
  331. package/src/tcp/crowd.d.ts +18 -0
  332. package/src/tcp/crowd.js +85 -0
  333. package/src/tcp/dial.d.ts +23 -0
  334. package/src/tcp/dial.js +102 -0
  335. package/src/tcp/frame.d.ts +23 -0
  336. package/src/tcp/frame.js +159 -0
  337. package/src/tcp/listen.d.ts +50 -0
  338. package/src/tcp/listen.js +207 -0
  339. package/src/tcp/source.d.ts +2 -0
  340. package/src/tcp/source.js +26 -0
  341. package/src/version/index.d.ts +1 -0
  342. package/src/version/index.js +2 -0
  343. package/src/version/version.d.ts +1 -0
  344. package/src/version/version.js +2 -0
  345. package/src/work/first.d.ts +11 -0
  346. package/src/work/first.js +91 -0
  347. package/src/work/index.d.ts +2 -0
  348. package/src/work/index.js +15 -0
  349. package/src/work/work.d.ts +20 -0
  350. package/src/work/work.js +136 -0
  351. package/src/ws/dial.d.ts +7 -0
  352. package/src/ws/dial.js +252 -0
  353. package/src/ws/dialing.d.ts +50 -0
  354. package/src/ws/dialing.js +72 -0
  355. package/src/ws/frame.d.ts +32 -0
  356. package/src/ws/frame.js +124 -0
  357. package/src/ws/handshake.d.ts +4 -0
  358. package/src/ws/handshake.js +27 -0
  359. package/src/ws/line.d.ts +45 -0
  360. package/src/ws/line.js +250 -0
  361. package/src/ws/listen.d.ts +42 -0
  362. package/src/ws/listen.js +272 -0
  363. package/src/ws/rfc6455.d.ts +18 -0
  364. package/src/ws/rfc6455.js +187 -0
@@ -0,0 +1,63 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { closeSync, openSync, writeSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import {
5
+ dataText,
6
+ error,
7
+ isFields,
8
+ readText,
9
+ result,
10
+ unhex,
11
+
12
+
13
+ } from '@nervur.org/genome/standard';
14
+ import { listenConsole, } from '../../organs/console/node/index.js';
15
+
16
+
17
+ export const actOf = (home ) => join(home, 'act.sock');
18
+
19
+
20
+
21
+ const refused = (why ) => error('refused', why);
22
+
23
+ const argsOf = (text ) => {
24
+ if (text === undefined) return {};
25
+ const read = readText(text);
26
+ return 'data' in read && isFields(read.data) ? read.data : null;
27
+ };
28
+
29
+ const written = (file , form ) => {
30
+ let opened ;
31
+ try {
32
+ opened = openSync(file, 'wx', 0o600);
33
+ } catch (failed) {
34
+ return `the form cannot be written at ${file}: ${failed instanceof Error ? failed.message : String(failed)}`;
35
+ }
36
+ try {
37
+ writeSync(opened, form);
38
+ return null;
39
+ } finally {
40
+ closeSync(opened);
41
+ }
42
+ };
43
+
44
+ export const actAnswer =
45
+ (acting ) =>
46
+ async ([word, text, ...more]) => {
47
+ const args = argsOf(text);
48
+ if (args === null || more.length > 0) return refused('the act names a word and its args, as data');
49
+ if (word !== 'seal') return refused(`the organism hears the act's seal alone, not ${dataText(word ?? null)}`);
50
+ const { to, file, genome } = isFields(args) ? args : {};
51
+ const key = typeof to === 'string' ? unhex(to) : null;
52
+ if (key === null || 'why' in key || typeof file !== 'string' || typeof genome !== 'string')
53
+ return refused(
54
+ 'a seal names the key it is sealed to, as hex, the file it is written to, and the older genome it is for',
55
+ );
56
+ const made = await acting.seal(key.bytes, genome);
57
+ if ('why' in made) return refused(made.why);
58
+ const why = written(file, made.form);
59
+ return why === null ? result(null) : refused(why);
60
+ };
61
+
62
+ export const listenAct = (home , acting ) =>
63
+ listenConsole(actOf(home), actAnswer(acting));
@@ -0,0 +1,5 @@
1
+ import type { Beating } from './told.js';
2
+ export declare const beatOf: (home: string) => string;
3
+ export declare const heardOf: (home: string) => Beating;
4
+ export declare const beginBeat: (home: string, out: NodeJS.WritableStream | null) => void;
5
+ export declare const endBeat: () => void;
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { BEAT, LONGEST_WAIT } from '../door/longest.js';
5
+
6
+
7
+ export const beatOf = (home ) => join(home, 'organism.beat');
8
+
9
+ export const heardOf = (home ) => ({
10
+ of: () => {
11
+ try {
12
+ return readFileSync(beatOf(home), 'utf8');
13
+ } catch {
14
+ return null;
15
+ }
16
+ },
17
+ quiet: LONGEST_WAIT,
18
+ });
19
+
20
+ let counted = 0;
21
+ let beating = null;
22
+
23
+ export const beginBeat = (home , out ) => {
24
+ endBeat();
25
+ out?.on('error', () => undefined);
26
+ const tell = () => {
27
+ counted += 1;
28
+ out?.write('\n');
29
+ try {
30
+ writeFileSync(beatOf(home), String(counted));
31
+ } catch {
32
+ }
33
+ };
34
+ tell();
35
+ const timer = setInterval(tell, BEAT);
36
+ timer.unref();
37
+ beating = { timer, home };
38
+ };
39
+
40
+ export const endBeat = () => {
41
+ if (beating === null) return;
42
+ clearInterval(beating.timer);
43
+ rmSync(beatOf(beating.home), { force: true });
44
+ beating = null;
45
+ };
@@ -0,0 +1,2 @@
1
+ export declare const compiledOf: (home: string) => string;
2
+ export declare const compileIn: (home: string) => string | null;
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
3
+ import { constants, enableCompileCache } from 'node:module';
4
+ import { join } from 'node:path';
5
+ import { INSTALLER_VERSION } from '../version/index.js';
6
+
7
+ export const compiledOf = (home ) => join(home, 'compiled', INSTALLER_VERSION);
8
+
9
+ export const compileIn = (home ) => {
10
+ if (!existsSync(home)) return null;
11
+ const all = join(home, 'compiled');
12
+ mkdirSync(all, { recursive: true, mode: 0o700 });
13
+ for (const version of readdirSync(all))
14
+ if (version !== INSTALLER_VERSION)
15
+ try {
16
+ rmSync(join(all, version), { recursive: true, force: true });
17
+ } catch {
18
+ }
19
+ const folder = compiledOf(home);
20
+ const { status } = enableCompileCache(folder);
21
+ return status === constants.compileCacheStatus.FAILED || status === constants.compileCacheStatus.DISABLED
22
+ ? null
23
+ : folder;
24
+ };
@@ -0,0 +1,88 @@
1
+ import type { Given } from '@nervur.org/genome/seams';
2
+ import type { Work } from '../work/index.js';
3
+ import { type Size } from '../door/dressed.js';
4
+ import { type Distribution } from '../door/distribution.js';
5
+ type Screened = {
6
+ readonly size?: Size;
7
+ };
8
+ export type Laid = Screened & ({
9
+ readonly port: number;
10
+ readonly bootMode: 'present';
11
+ readonly salt: Uint8Array;
12
+ readonly publicHost?: string;
13
+ readonly ws?: string;
14
+ readonly wss?: string;
15
+ readonly work?: Work;
16
+ readonly witnessEachCommit?: boolean;
17
+ readonly floor?: Distribution;
18
+ readonly design?: Given;
19
+ readonly screen?: boolean;
20
+ readonly reserve?: number;
21
+ readonly claim?: string;
22
+ } | {
23
+ readonly port: number;
24
+ readonly bootMode: 'keyring' | 'hardware';
25
+ readonly publicHost?: string;
26
+ readonly ws?: string;
27
+ readonly wss?: string;
28
+ readonly work?: Work;
29
+ readonly witnessEachCommit?: boolean;
30
+ readonly floor?: Distribution;
31
+ readonly design?: Given;
32
+ readonly screen?: boolean;
33
+ readonly reserve?: number;
34
+ readonly claim?: string;
35
+ } | {
36
+ readonly port: number;
37
+ readonly bootMode: 'remote';
38
+ readonly end: 'present' | 'keyring' | 'file' | 'hardware';
39
+ readonly salt?: Uint8Array;
40
+ readonly keeperSpan?: number;
41
+ readonly publicHost?: string;
42
+ readonly ws?: string;
43
+ readonly wss?: string;
44
+ readonly work?: Work;
45
+ readonly witnessEachCommit?: boolean;
46
+ readonly floor?: Distribution;
47
+ readonly design?: Given;
48
+ readonly screen?: boolean;
49
+ readonly reserve?: number;
50
+ readonly claim?: string;
51
+ } | {
52
+ readonly port: number;
53
+ readonly bootMode: 'file';
54
+ readonly publicHost?: string;
55
+ readonly ws?: string;
56
+ readonly wss?: string;
57
+ readonly work?: Work;
58
+ readonly witnessEachCommit?: boolean;
59
+ readonly floor?: Distribution;
60
+ readonly design?: Given;
61
+ readonly screen?: boolean;
62
+ readonly reserve?: number;
63
+ readonly claim?: string;
64
+ });
65
+ export declare const wsAddressOf: (text: string) => boolean;
66
+ export declare const wssAddressOf: (text: string) => boolean;
67
+ export declare const pidOf: (home: string) => string;
68
+ export declare const logOf: (home: string) => string;
69
+ export declare const stoppedOf: (home: string) => string;
70
+ export declare const ownHome: () => string;
71
+ export declare const typedFor: (organism: string) => (words: string) => string;
72
+ export declare const stoppedSaid: (home: string) => string;
73
+ export declare const versionOf: (home: string) => string;
74
+ export { INSTALLER_VERSION } from '../version/index.js';
75
+ export declare const ranOn: (home: string) => string | null;
76
+ export declare const folderText: (laid: Laid) => string;
77
+ export declare const layFolder: (home: string, laid: Laid) => null | {
78
+ readonly why: string;
79
+ };
80
+ export declare const layFolderAgain: (home: string, laid: Laid) => null | {
81
+ readonly why: string;
82
+ };
83
+ export declare const withWs: (laid: Laid, named: string | null) => Laid;
84
+ export declare const readFolder: (home: string, file?: string) => {
85
+ readonly laid: Laid;
86
+ } | {
87
+ readonly why: string;
88
+ };
@@ -0,0 +1,259 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { dirname, join } from 'node:path';
5
+
6
+ import { hex, unhex } from '@nervur.org/genome/standard';
7
+ import { folderFileOf, nextFolderOf, nodeFiles } from '../fills/boot-move.js';
8
+ import { foldersLaid, laidWhole } from '../fills/flushed.js';
9
+ import { addressAt } from '../tcp/frame.js';
10
+ import { addressOf } from '../ws/frame.js';
11
+
12
+ import { designData, designOf } from '../door/design.js';
13
+ import { sizeOf, } from '../door/dressed.js';
14
+ import { distributionIn, } from '../door/distribution.js';
15
+ import { isClaim } from '../door/claim.js';
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+ export const wsAddressOf = (text ) => addressOf(text) !== null;
94
+
95
+ export const wssAddressOf = (text ) => addressOf(text)?.protocol === 'wss:';
96
+
97
+ const fileOf = folderFileOf;
98
+
99
+ export const pidOf = (home ) => join(home, 'organism.pid');
100
+
101
+ export const logOf = (home ) => join(home, 'organism.log');
102
+
103
+ export const stoppedOf = (home ) => join(home, 'stopped');
104
+ export const ownHome = () => join(homedir(), '.nervur');
105
+
106
+ const shellWord = (word ) =>
107
+ /^[\w@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
108
+
109
+ export const typedFor =
110
+ (organism ) =>
111
+ (words ) => {
112
+ const home = dirname(organism);
113
+ return home === ownHome() ? `nervur ${words}` : `nervur ${words} --home ${shellWord(home)}`;
114
+ };
115
+
116
+ export const stoppedSaid = (home ) =>
117
+ `This organism moved to another device, and this copy stays stopped. While the new copy never ran, ${typedFor(home)('stay')} undoes that.`;
118
+
119
+ export const versionOf = (home ) => join(home, 'organism.version');
120
+
121
+ export { INSTALLER_VERSION } from '../version/index.js';
122
+
123
+ export const ranOn = (home ) =>
124
+ existsSync(versionOf(home)) ? readFileSync(versionOf(home), 'utf8').trim() : null;
125
+
126
+ export const folderText = (laid ) => {
127
+ const { design, ...rest } = laid;
128
+ const kept = 'salt' in rest && rest.salt !== undefined ? { ...rest, salt: hex(rest.salt) } : rest;
129
+ return `${JSON.stringify(design === undefined ? kept : { ...kept, design: designData(design) }, null, 2)}\n`;
130
+ };
131
+
132
+ const written = (home , laid ) => {
133
+ foldersLaid(home, 0o700);
134
+ laidWhole(fileOf(home), folderText(laid), 0o600);
135
+ };
136
+
137
+ export const layFolder = (home , laid ) => {
138
+ if (existsSync(fileOf(home))) return { why: `an organism is already installed at ${home}` };
139
+ written(home, laid);
140
+ return null;
141
+ };
142
+
143
+ export const layFolderAgain = (home , laid ) => {
144
+ if (!existsSync(fileOf(home))) return { why: `no organism is installed at ${home}` };
145
+ nodeFiles.lay(nextFolderOf(home), folderText(laid));
146
+ nodeFiles.rename(nextFolderOf(home), fileOf(home));
147
+ return null;
148
+ };
149
+
150
+ export const withWs = (laid , named ) => {
151
+ if (named === null) return laid;
152
+ if (laid.ws === undefined) return { ...laid, ws: named };
153
+ const plain = !laid.ws.startsWith('wss:');
154
+ return plain && laid.wss === undefined && wssAddressOf(named) ? { ...laid, wss: named } : laid;
155
+ };
156
+
157
+ export const readFolder = (home , file = fileOf(home)) => {
158
+ let value ;
159
+ try {
160
+ value = JSON.parse(readFileSync(file, 'utf8'));
161
+ } catch {
162
+ return { why: `no organism is installed at ${home}` };
163
+ }
164
+ const laid = typeof value === 'object' && value !== null ? laidOf(value) : null;
165
+ return laid === null ? { why: `${file} is not whole` } : { laid };
166
+ };
167
+
168
+ const publicIn = (value ) => {
169
+ if (!('publicHost' in value)) return {};
170
+ const host = value.publicHost;
171
+ return typeof host === 'string' && addressAt(host, 1) !== null ? { publicHost: host } : null;
172
+ };
173
+
174
+ const wsIn = (value ) => {
175
+ if (!('ws' in value)) return {};
176
+ const ws = value.ws;
177
+ return typeof ws === 'string' && wsAddressOf(ws) ? { ws } : null;
178
+ };
179
+
180
+ const wssIn = (value ) => {
181
+ if (!('wss' in value)) return {};
182
+ const wss = value.wss;
183
+ return typeof wss === 'string' && wssAddressOf(wss) ? { wss } : null;
184
+ };
185
+
186
+ const workIn = (value ) => {
187
+ if (!('work' in value)) return {};
188
+ const work = value.work;
189
+ if (typeof work !== 'object' || work === null || !('account' in work) || !('home' in work)) return null;
190
+ const { account, home } = work;
191
+ return typeof account === 'string' && typeof home === 'string' ? { work: { account, home } } : null;
192
+ };
193
+
194
+ const claimIn = (value ) => {
195
+ if (!('claim' in value)) return {};
196
+ const claim = value.claim;
197
+ return typeof claim === 'string' && isClaim(claim) ? { claim } : null;
198
+ };
199
+
200
+ const choicesIn = (value ) => {
201
+ const publicHost = publicIn(value);
202
+ const ws = wsIn(value);
203
+ const wss = wssIn(value);
204
+ const work = workIn(value);
205
+ const claim = claimIn(value);
206
+ const floor = 'floor' in value ? distributionIn(value.floor) : undefined;
207
+ const design = 'design' in value ? designOf(value.design) : undefined;
208
+ const size = 'size' in value ? sizeOf(value.size) : null;
209
+ if (
210
+ publicHost === null ||
211
+ ws === null ||
212
+ wss === null ||
213
+ work === null ||
214
+ claim === null ||
215
+ floor === null ||
216
+ design === null
217
+ )
218
+ return null;
219
+ const witness = 'witnessEachCommit' in value && value.witnessEachCommit === true ? { witnessEachCommit: true } : {};
220
+ const screen = 'screen' in value && typeof value.screen === 'boolean' ? { screen: value.screen } : {};
221
+ return {
222
+ ...publicHost,
223
+ ...ws,
224
+ ...wss,
225
+ ...work,
226
+ ...witness,
227
+ ...screen,
228
+ ...('reserve' in value && typeof value.reserve === 'number' ? { reserve: value.reserve } : {}),
229
+ ...(floor === undefined ? {} : { floor }),
230
+ ...(design === undefined ? {} : { design }),
231
+ ...(size === null ? {} : { size }),
232
+ ...claim,
233
+ };
234
+ };
235
+
236
+ const laidOf = (value ) => {
237
+ const port = 'port' in value ? value.port : null;
238
+ const bootMode = 'bootMode' in value ? value.bootMode : null;
239
+ const reached = choicesIn(value);
240
+ if (typeof port !== 'number' || !Number.isInteger(port) || reached === null) return null;
241
+ if (bootMode === 'file' || bootMode === 'keyring' || bootMode === 'hardware') return { port, bootMode, ...reached };
242
+ const salt = 'salt' in value && typeof value.salt === 'string' ? unhex(value.salt) : null;
243
+ if (bootMode === 'remote') {
244
+ const end = 'end' in value ? value.end : null;
245
+ if (end !== 'present' && end !== 'keyring' && end !== 'file' && end !== 'hardware') return null;
246
+ if (end === 'present' && (salt === null || 'why' in salt)) return null;
247
+ const span = 'keeperSpan' in value && typeof value.keeperSpan === 'number' ? { keeperSpan: value.keeperSpan } : {};
248
+ return {
249
+ port,
250
+ bootMode,
251
+ end,
252
+ ...(salt === null || 'why' in salt ? {} : { salt: salt.bytes }),
253
+ ...span,
254
+ ...reached,
255
+ };
256
+ }
257
+ if (bootMode !== 'present' || salt === null || 'why' in salt) return null;
258
+ return { port, bootMode, salt: salt.bytes, ...reached };
259
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { resolve } from 'node:path';
3
+ import { beginBeat } from './beat.js';
4
+ import { compileIn } from './compiled.js';
5
+
6
+ const [home, , atBoot] = process.argv.slice(2);
7
+ if (home !== undefined) {
8
+ beginBeat(home, atBoot === '--at-boot' ? null : process.stdout);
9
+ compileIn(resolve(home));
10
+ }
11
+ await import('./organism.js');
@@ -0,0 +1 @@
1
+ export {};