@nervur.org/installer-node 0.0.0-stage → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +105 -0
- package/README.md +158 -2
- package/SECURITY.md +8 -0
- package/bin/nervur.js +5 -0
- package/cargo/emscripten-module.wasm +0 -0
- package/cargo/manifest.json +1 -0
- package/cargo/sqlite3.wasm +0 -0
- package/cargo/table-i-i.wasm +0 -0
- package/cargo/table-i-ii.wasm +0 -0
- package/cargo/table-i-iii.wasm +0 -0
- package/cargo/table-i-iiii.wasm +0 -0
- package/cargo/table-i-iiiii.wasm +0 -0
- package/cargo/table-i-iiij.wasm +0 -0
- package/cargo/table-i-ij.wasm +0 -0
- package/cargo/table-v-ii.wasm +0 -0
- package/cargo/table-v-iii.wasm +0 -0
- package/cargo/worker.js +30756 -0
- package/organs/console/node/guard.d.ts +10 -0
- package/organs/console/node/guard.js +52 -0
- package/organs/console/node/index.d.ts +4 -0
- package/organs/console/node/index.js +5 -0
- package/organs/console/node/line.d.ts +16 -0
- package/organs/console/node/line.js +150 -0
- package/organs/console/node/main.js +51 -0
- package/organs/console/node/program.d.ts +1 -0
- package/organs/console/node/program.js +5 -0
- package/organs/console/node/proof.d.ts +15 -0
- package/organs/console/node/proof.js +84 -0
- package/organs/console/node/socket.d.ts +15 -0
- package/organs/console/node/socket.js +99 -0
- package/organs/disk/index.d.ts +1 -0
- package/organs/disk/index.js +2 -0
- package/organs/disk/node/files.js +162 -0
- package/organs/disk/node/main.js +20 -0
- package/organs/disk/node/program.d.ts +1 -0
- package/organs/disk/node/program.js +5 -0
- package/organs/disk/organ.d.ts +5 -0
- package/organs/disk/organ.js +69 -0
- package/organs/network/node/fill.d.ts +21 -0
- package/organs/network/node/fill.js +195 -0
- package/organs/network/node/flows.js +66 -0
- package/organs/network/node/half.js +260 -0
- package/organs/network/node/lines.d.ts +29 -0
- package/organs/network/node/lines.js +236 -0
- package/organs/network/node/link.d.ts +24 -0
- package/organs/network/node/link.js +215 -0
- package/organs/network/node/main.js +41 -0
- package/organs/network/node/moved.d.ts +2 -0
- package/organs/network/node/moved.js +20 -0
- package/organs/network/node/near.d.ts +63 -0
- package/organs/network/node/near.js +263 -0
- package/organs/network/node/program.d.ts +1 -0
- package/organs/network/node/program.js +5 -0
- package/organs/network/node/schemes.d.ts +1 -0
- package/organs/network/node/schemes.js +2 -0
- package/organs/network/node/sent.d.ts +13 -0
- package/organs/network/node/sent.js +101 -0
- package/organs/network/node/served.d.ts +19 -0
- package/organs/network/node/served.js +237 -0
- package/organs/screen/node/client.js +3 -0
- package/organs/screen/node/follow.js +266 -0
- package/organs/screen/node/frames.js +26 -0
- package/organs/screen/node/held.js +27 -0
- package/organs/screen/node/http.js +179 -0
- package/organs/screen/node/lay.js +116 -0
- package/organs/screen/node/leave.js +27 -0
- package/organs/screen/node/linked.js +69 -0
- package/organs/screen/node/listen.js +61 -0
- package/organs/screen/node/look.js +121 -0
- package/organs/screen/node/loop.js +154 -0
- package/organs/screen/node/main.js +74 -0
- package/organs/screen/node/mirror.js +112 -0
- package/organs/screen/node/notice.js +44 -0
- package/organs/screen/node/presser.js +11 -0
- package/organs/screen/node/presses.js +108 -0
- package/organs/screen/node/program.d.ts +1 -0
- package/organs/screen/node/program.js +5 -0
- package/organs/screen/node/shown.js +205 -0
- package/organs/screen/node/standing.js +29 -0
- package/organs/screen/node/state.js +80 -0
- package/organs/screen/node/tell.js +47 -0
- package/organs/screen/node/uid.js +65 -0
- package/organs/screen/node/worn.js +23 -0
- package/organs/shell/index.d.ts +1 -0
- package/organs/shell/index.js +2 -0
- package/organs/shell/node/main.js +26 -0
- package/organs/shell/node/output.js +70 -0
- package/organs/shell/node/pressure.js +14 -0
- package/organs/shell/node/program.d.ts +1 -0
- package/organs/shell/node/program.js +5 -0
- package/organs/shell/node/runs.js +220 -0
- package/organs/shell/node/told.js +70 -0
- package/organs/shell/organ.d.ts +5 -0
- package/organs/shell/organ.js +59 -0
- package/package.json +43 -4
- package/src/command/act.d.ts +31 -0
- package/src/command/act.js +256 -0
- package/src/command/answers.d.ts +3 -0
- package/src/command/answers.js +232 -0
- package/src/command/args.d.ts +14 -0
- package/src/command/args.js +220 -0
- package/src/command/arrive.d.ts +2 -0
- package/src/command/arrive.js +21 -0
- package/src/command/asked.d.ts +18 -0
- package/src/command/asked.js +49 -0
- package/src/command/backup.d.ts +18 -0
- package/src/command/backup.js +261 -0
- package/src/command/before.d.ts +41 -0
- package/src/command/before.js +237 -0
- package/src/command/born.d.ts +27 -0
- package/src/command/born.js +103 -0
- package/src/command/bridge.d.ts +19 -0
- package/src/command/bridge.js +152 -0
- package/src/command/chain.d.ts +9 -0
- package/src/command/chain.js +48 -0
- package/src/command/channel.d.ts +29 -0
- package/src/command/channel.js +263 -0
- package/src/command/choices.d.ts +35 -0
- package/src/command/choices.js +173 -0
- package/src/command/claim.d.ts +12 -0
- package/src/command/claim.js +46 -0
- package/src/command/commands.d.ts +16 -0
- package/src/command/commands.js +257 -0
- package/src/command/ends.d.ts +16 -0
- package/src/command/ends.js +78 -0
- package/src/command/follow.d.ts +12 -0
- package/src/command/follow.js +66 -0
- package/src/command/given.d.ts +39 -0
- package/src/command/given.js +53 -0
- package/src/command/held.d.ts +15 -0
- package/src/command/held.js +56 -0
- package/src/command/index.d.ts +1 -0
- package/src/command/index.js +203 -0
- package/src/command/jailer.d.ts +28 -0
- package/src/command/jailer.js +135 -0
- package/src/command/laid.d.ts +6 -0
- package/src/command/laid.js +31 -0
- package/src/command/left.d.ts +9 -0
- package/src/command/left.js +34 -0
- package/src/command/line.d.ts +7 -0
- package/src/command/line.js +39 -0
- package/src/command/link.d.ts +30 -0
- package/src/command/link.js +123 -0
- package/src/command/lobes.d.ts +1 -0
- package/src/command/lobes.js +10 -0
- package/src/command/locks.d.ts +17 -0
- package/src/command/locks.js +76 -0
- package/src/command/mcp/calls.d.ts +27 -0
- package/src/command/mcp/calls.js +155 -0
- package/src/command/mcp/notices.d.ts +22 -0
- package/src/command/mcp/notices.js +203 -0
- package/src/command/mcp/resources.d.ts +31 -0
- package/src/command/mcp/resources.js +108 -0
- package/src/command/mcp/server.d.ts +19 -0
- package/src/command/mcp/server.js +149 -0
- package/src/command/mcp/tools.d.ts +39 -0
- package/src/command/mcp/tools.js +131 -0
- package/src/command/mcp.d.ts +8 -0
- package/src/command/mcp.js +39 -0
- package/src/command/noticed.d.ts +11 -0
- package/src/command/noticed.js +55 -0
- package/src/command/older.d.ts +11 -0
- package/src/command/older.js +45 -0
- package/src/command/open.d.ts +24 -0
- package/src/command/open.js +107 -0
- package/src/command/passphrase.d.ts +6 -0
- package/src/command/passphrase.js +82 -0
- package/src/command/reclaim.d.ts +7 -0
- package/src/command/reclaim.js +47 -0
- package/src/command/refused.d.ts +4 -0
- package/src/command/refused.js +27 -0
- package/src/command/release.d.ts +27 -0
- package/src/command/release.js +153 -0
- package/src/command/repo.d.ts +31 -0
- package/src/command/repo.js +133 -0
- package/src/command/rewrap.d.ts +16 -0
- package/src/command/rewrap.js +175 -0
- package/src/command/runtime.d.ts +25 -0
- package/src/command/runtime.js +175 -0
- package/src/command/salvage.d.ts +4 -0
- package/src/command/salvage.js +42 -0
- package/src/command/screen.d.ts +14 -0
- package/src/command/screen.js +62 -0
- package/src/command/spawn.d.ts +23 -0
- package/src/command/spawn.js +213 -0
- package/src/command/start.d.ts +34 -0
- package/src/command/start.js +246 -0
- package/src/command/state.d.ts +5 -0
- package/src/command/state.js +39 -0
- package/src/command/token.d.ts +1 -0
- package/src/command/token.js +9 -0
- package/src/command/trial.d.ts +17 -0
- package/src/command/trial.js +92 -0
- package/src/command/vouch.d.ts +1 -0
- package/src/command/vouch.js +15 -0
- package/src/command/windows-processes.d.ts +2 -0
- package/src/command/windows-processes.js +22 -0
- package/src/command/wipe.d.ts +9 -0
- package/src/command/wipe.js +105 -0
- package/src/command/words.d.ts +5 -0
- package/src/command/words.js +53 -0
- package/src/door/claim.d.ts +5 -0
- package/src/door/claim.js +21 -0
- package/src/door/claimed.d.ts +7 -0
- package/src/door/claimed.js +110 -0
- package/src/door/configuration.d.ts +40 -0
- package/src/door/configuration.js +206 -0
- package/src/door/design.d.ts +13 -0
- package/src/door/design.js +71 -0
- package/src/door/digests.d.ts +7 -0
- package/src/door/digests.js +36 -0
- package/src/door/distribution.d.ts +25 -0
- package/src/door/distribution.js +88 -0
- package/src/door/door.d.ts +41 -0
- package/src/door/door.js +219 -0
- package/src/door/dressed.d.ts +34 -0
- package/src/door/dressed.js +182 -0
- package/src/door/faculties.d.ts +29 -0
- package/src/door/faculties.js +88 -0
- package/src/door/longest.d.ts +6 -0
- package/src/door/longest.js +25 -0
- package/src/fills/account-only.d.ts +3 -0
- package/src/fills/account-only.js +24 -0
- package/src/fills/boot-key.d.ts +21 -0
- package/src/fills/boot-key.js +70 -0
- package/src/fills/boot-move.d.ts +25 -0
- package/src/fills/boot-move.js +86 -0
- package/src/fills/bridge.d.ts +13 -0
- package/src/fills/bridge.js +86 -0
- package/src/fills/chance.d.ts +2 -0
- package/src/fills/chance.js +7 -0
- package/src/fills/crypto.d.ts +2 -0
- package/src/fills/crypto.js +94 -0
- package/src/fills/flushed.d.ts +9 -0
- package/src/fills/flushed.js +80 -0
- package/src/fills/hardware.d.ts +18 -0
- package/src/fills/hardware.js +70 -0
- package/src/fills/held.d.ts +31 -0
- package/src/fills/held.js +171 -0
- package/src/fills/keepers.d.ts +23 -0
- package/src/fills/keepers.js +151 -0
- package/src/fills/keyring.d.ts +19 -0
- package/src/fills/keyring.js +131 -0
- package/src/fills/pages.d.ts +3 -0
- package/src/fills/pages.js +260 -0
- package/src/fills/reserve.d.ts +11 -0
- package/src/fills/reserve.js +72 -0
- package/src/fills/time.d.ts +2 -0
- package/src/fills/time.js +29 -0
- package/src/fills/unlocker.d.ts +6 -0
- package/src/fills/unlocker.js +26 -0
- package/src/fills/vitals.d.ts +8 -0
- package/src/fills/vitals.js +100 -0
- package/src/fills/windows-start.d.ts +2 -0
- package/src/fills/windows-start.js +21 -0
- package/src/halves/build.d.ts +10 -0
- package/src/halves/build.js +219 -0
- package/src/halves/end.d.ts +17 -0
- package/src/halves/end.js +157 -0
- package/src/halves/genome.d.ts +3 -0
- package/src/halves/genome.js +21 -0
- package/src/halves/handler.d.ts +8 -0
- package/src/halves/handler.js +40 -0
- package/src/halves/index.d.ts +5 -0
- package/src/halves/index.js +6 -0
- package/src/halves/laid.d.ts +12 -0
- package/src/halves/laid.js +103 -0
- package/src/halves/lent.d.ts +6 -0
- package/src/halves/lent.js +147 -0
- package/src/halves/native.d.ts +12 -0
- package/src/halves/native.js +53 -0
- package/src/halves/statements.d.ts +23 -0
- package/src/halves/statements.js +165 -0
- package/src/halves/tokens.d.ts +22 -0
- package/src/halves/tokens.js +135 -0
- package/src/link/link.d.ts +4 -0
- package/src/link/link.js +4 -0
- package/src/link/placeholder.d.ts +1 -0
- package/src/link/placeholder.js +21 -0
- package/src/link/steps.d.ts +52 -0
- package/src/link/steps.js +118 -0
- package/src/lobes/calls.d.ts +76 -0
- package/src/lobes/calls.js +61 -0
- package/src/lobes/channel.d.ts +76 -0
- package/src/lobes/channel.js +202 -0
- package/src/lobes/index.d.ts +1 -0
- package/src/lobes/index.js +2 -0
- package/src/lobes/lobes.d.ts +15 -0
- package/src/lobes/lobes.js +244 -0
- package/src/lobes/main.js +107 -0
- package/src/lobes/thread.d.ts +22 -0
- package/src/lobes/thread.js +270 -0
- package/src/organism/act.d.ts +8 -0
- package/src/organism/act.js +63 -0
- package/src/organism/beat.d.ts +5 -0
- package/src/organism/beat.js +45 -0
- package/src/organism/compiled.d.ts +2 -0
- package/src/organism/compiled.js +24 -0
- package/src/organism/folder.d.ts +88 -0
- package/src/organism/folder.js +259 -0
- package/src/organism/main.d.ts +1 -0
- package/src/organism/main.js +11 -0
- package/src/organism/organism.d.ts +1 -0
- package/src/organism/organism.js +219 -0
- package/src/organism/said.d.ts +12 -0
- package/src/organism/said.js +30 -0
- package/src/organism/told.d.ts +5 -0
- package/src/organism/told.js +110 -0
- package/src/organism/unlock.d.ts +8 -0
- package/src/organism/unlock.js +95 -0
- package/src/organism/upgrade.d.ts +24 -0
- package/src/organism/upgrade.js +145 -0
- package/src/organism/via.d.ts +7 -0
- package/src/organism/via.js +20 -0
- package/src/service/body.d.ts +8 -0
- package/src/service/body.js +34 -0
- package/src/service/handler.d.ts +20 -0
- package/src/service/handler.js +128 -0
- package/src/service/index.d.ts +4 -0
- package/src/service/index.js +16 -0
- package/src/service/manager.d.ts +18 -0
- package/src/service/manager.js +185 -0
- package/src/service/service.d.ts +24 -0
- package/src/service/service.js +200 -0
- package/src/service/swap.d.ts +12 -0
- package/src/service/swap.js +74 -0
- package/src/service/watchdog.d.ts +6 -0
- package/src/service/watchdog.js +31 -0
- package/src/tcp/crowd.d.ts +18 -0
- package/src/tcp/crowd.js +85 -0
- package/src/tcp/dial.d.ts +23 -0
- package/src/tcp/dial.js +102 -0
- package/src/tcp/frame.d.ts +23 -0
- package/src/tcp/frame.js +159 -0
- package/src/tcp/listen.d.ts +50 -0
- package/src/tcp/listen.js +207 -0
- package/src/tcp/source.d.ts +2 -0
- package/src/tcp/source.js +26 -0
- package/src/version/index.d.ts +1 -0
- package/src/version/index.js +2 -0
- package/src/version/version.d.ts +1 -0
- package/src/version/version.js +2 -0
- package/src/work/first.d.ts +11 -0
- package/src/work/first.js +91 -0
- package/src/work/index.d.ts +2 -0
- package/src/work/index.js +15 -0
- package/src/work/work.d.ts +20 -0
- package/src/work/work.js +136 -0
- package/src/ws/dial.d.ts +7 -0
- package/src/ws/dial.js +252 -0
- package/src/ws/dialing.d.ts +50 -0
- package/src/ws/dialing.js +72 -0
- package/src/ws/frame.d.ts +32 -0
- package/src/ws/frame.js +124 -0
- package/src/ws/handshake.d.ts +4 -0
- package/src/ws/handshake.js +27 -0
- package/src/ws/line.d.ts +45 -0
- package/src/ws/line.js +250 -0
- package/src/ws/listen.d.ts +42 -0
- package/src/ws/listen.js +272 -0
- package/src/ws/rfc6455.d.ts +18 -0
- package/src/ws/rfc6455.js +187 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import {
|
|
3
|
+
closeSync,
|
|
4
|
+
fsyncSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
openSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
renameSync,
|
|
10
|
+
rmdirSync,
|
|
11
|
+
rmSync,
|
|
12
|
+
statSync,
|
|
13
|
+
writeSync,
|
|
14
|
+
} from 'node:fs';
|
|
15
|
+
import { basename, dirname, join } from 'node:path';
|
|
16
|
+
import { FRAME_SIZE } from '../../../src/door/longest.js';
|
|
17
|
+
import { error, isFields, result, } from '@nervur.org/genome/standard';
|
|
18
|
+
|
|
19
|
+
const NAME = /^(?!\.{1,2}$)(?!\.git$)[^/\\\0]+$/i;
|
|
20
|
+
|
|
21
|
+
const refused = (message ) => error('refused', message);
|
|
22
|
+
const absent = (message ) => error('absent', message);
|
|
23
|
+
|
|
24
|
+
const namesIn = (args ) => {
|
|
25
|
+
const path = isFields(args) ? args['path'] : undefined;
|
|
26
|
+
if (!Array.isArray(path)) return null;
|
|
27
|
+
const names = path.filter((name) => typeof name === 'string' && NAME.test(name));
|
|
28
|
+
return names.length === path.length ? names.filter((name) => typeof name === 'string') : null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const codeOf = (thrown ) =>
|
|
32
|
+
thrown instanceof Error && 'code' in thrown && typeof thrown.code === 'string' ? thrown.code : '';
|
|
33
|
+
|
|
34
|
+
const failed = (thrown , at ) => {
|
|
35
|
+
const code = codeOf(thrown);
|
|
36
|
+
if (code === 'ENOENT') return absent(`nothing stands at ${at}`);
|
|
37
|
+
if (code === 'ENOTDIR' || code === 'EEXIST' || code === 'EISDIR')
|
|
38
|
+
return refused(`${at}: a file and a folder never share a name`);
|
|
39
|
+
return refused(`${at}: ${thrown instanceof Error ? thrown.message : String(thrown)}`);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const fitsFrame = (size ) => 2 * size + 65_536 <= FRAME_SIZE;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
const standingAt = (at ) => {
|
|
50
|
+
try {
|
|
51
|
+
if (!statSync(at).isDirectory()) return { kind: 'file' };
|
|
52
|
+
} catch (thrown) {
|
|
53
|
+
if (codeOf(thrown) === 'ENOENT' || codeOf(thrown) === 'ENOTDIR') return { kind: 'none' };
|
|
54
|
+
throw thrown;
|
|
55
|
+
}
|
|
56
|
+
const names = readdirSync(at)
|
|
57
|
+
.filter((name) => NAME.test(name))
|
|
58
|
+
.toSorted();
|
|
59
|
+
return names.length === 0 ? { kind: 'none' } : { kind: 'folder', names };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const flush = (at ) => {
|
|
63
|
+
const descriptor = openSync(at, 'r');
|
|
64
|
+
try {
|
|
65
|
+
fsyncSync(descriptor);
|
|
66
|
+
} finally {
|
|
67
|
+
closeSync(descriptor);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const write = (folder , names , bytes ) => {
|
|
72
|
+
if (!(bytes instanceof Uint8Array)) return refused('a write holds its bytes');
|
|
73
|
+
if (!fitsFrame(bytes.length)) return refused(`${names.join('/')} weighs past what one answer carries`);
|
|
74
|
+
const at = join(folder, ...names);
|
|
75
|
+
const standing = standingAt(at);
|
|
76
|
+
if (standing.kind === 'folder') return refused(`${names.join('/')} is a folder that holds something`);
|
|
77
|
+
const parent = dirname(at);
|
|
78
|
+
mkdirSync(parent, { recursive: true, mode: 0o700 });
|
|
79
|
+
if (standing.kind === 'none') rmSync(at, { recursive: true, force: true });
|
|
80
|
+
const beside = join(parent, `.${basename(at)}.${process.pid}.new`);
|
|
81
|
+
const descriptor = openSync(beside, 'w', 0o600);
|
|
82
|
+
try {
|
|
83
|
+
writeSync(descriptor, bytes);
|
|
84
|
+
fsyncSync(descriptor);
|
|
85
|
+
} finally {
|
|
86
|
+
closeSync(descriptor);
|
|
87
|
+
}
|
|
88
|
+
renameSync(beside, at);
|
|
89
|
+
flush(parent);
|
|
90
|
+
return result(null);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const emptied = (at ) => {
|
|
94
|
+
try {
|
|
95
|
+
if (!statSync(at).isDirectory() || readdirSync(at).length > 0) return false;
|
|
96
|
+
} catch (thrown) {
|
|
97
|
+
if (codeOf(thrown) === 'ENOENT' || codeOf(thrown) === 'ENOTDIR') return false;
|
|
98
|
+
throw thrown;
|
|
99
|
+
}
|
|
100
|
+
rmdirSync(at);
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const pruned = (folder , names ) => {
|
|
105
|
+
for (let depth = names.length - 1; depth > 0; depth -= 1) {
|
|
106
|
+
const above = join(folder, ...names.slice(0, depth));
|
|
107
|
+
if (!emptied(above)) return above;
|
|
108
|
+
}
|
|
109
|
+
return folder;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const remove = (folder , names ) => {
|
|
113
|
+
const at = join(folder, ...names);
|
|
114
|
+
const standing = standingAt(at);
|
|
115
|
+
if (standing.kind === 'folder') return refused(`${names.join('/')} is a folder that holds something`);
|
|
116
|
+
if (standing.kind === 'none') {
|
|
117
|
+
emptied(at);
|
|
118
|
+
return absent(`nothing stands at ${names.join('/')}`);
|
|
119
|
+
}
|
|
120
|
+
rmSync(at, { force: true });
|
|
121
|
+
flush(pruned(folder, names));
|
|
122
|
+
return result(null);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const bare = (at , method ) => {
|
|
126
|
+
if (method === 'list') {
|
|
127
|
+
const standing = standingAt(at);
|
|
128
|
+
return result({ names: standing.kind === 'folder' ? [...standing.names] : [] });
|
|
129
|
+
}
|
|
130
|
+
if (method === 'read') return absent('the folder is no file');
|
|
131
|
+
if (method === 'write') return refused('the folder itself is not a file');
|
|
132
|
+
if (method === 'remove') return refused('the folder itself stays');
|
|
133
|
+
return error('unavailable', `the disk holds no method ${method}`);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const filesUnder =
|
|
137
|
+
(folder ) =>
|
|
138
|
+
(method , args ) => {
|
|
139
|
+
const names = namesIn(args);
|
|
140
|
+
if (names === null) return refused('a path is a list of names, none empty, climbing or reaching .git');
|
|
141
|
+
const at = join(folder, ...names);
|
|
142
|
+
const shown = names.join('/');
|
|
143
|
+
try {
|
|
144
|
+
if (names.length === 0) return bare(at, method);
|
|
145
|
+
if (method === 'read') {
|
|
146
|
+
if (standingAt(at).kind !== 'file') return absent(`no file stands at ${shown}`);
|
|
147
|
+
if (!fitsFrame(statSync(at).size)) return refused(`${shown} weighs past what one answer carries`);
|
|
148
|
+
return result({ bytes: new Uint8Array(readFileSync(at)) });
|
|
149
|
+
}
|
|
150
|
+
if (method === 'list') {
|
|
151
|
+
const standing = standingAt(at);
|
|
152
|
+
return standing.kind === 'folder'
|
|
153
|
+
? result({ names: [...standing.names] })
|
|
154
|
+
: absent(`no folder stands at ${shown}`);
|
|
155
|
+
}
|
|
156
|
+
if (method === 'write') return write(folder, names, isFields(args) ? args['bytes'] : undefined);
|
|
157
|
+
if (method === 'remove') return remove(folder, names);
|
|
158
|
+
} catch (thrown) {
|
|
159
|
+
return failed(thrown, shown);
|
|
160
|
+
}
|
|
161
|
+
return error('unavailable', `the disk holds no method ${method}`);
|
|
162
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { chmodSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { DISK } from '../index.js';
|
|
4
|
+
import { isFields, readText } from '@nervur.org/genome/standard';
|
|
5
|
+
import { processIo, refuseHalf, serveHalf } from '../../../src/halves/index.js';
|
|
6
|
+
import { filesUnder } from './files.js';
|
|
7
|
+
|
|
8
|
+
const stop = () => process.exit(0);
|
|
9
|
+
const io = processIo();
|
|
10
|
+
const read = readText(process.argv[2] ?? '');
|
|
11
|
+
const folder = 'data' in read && isFields(read.data) ? read.data['folder'] : undefined;
|
|
12
|
+
if (typeof folder !== 'string') {
|
|
13
|
+
refuseHalf(io, 'the disk is started with its folder as its reach');
|
|
14
|
+
process.exitCode = 1;
|
|
15
|
+
} else {
|
|
16
|
+
mkdirSync(folder, { recursive: true, mode: 0o700 });
|
|
17
|
+
chmodSync(folder, 0o700);
|
|
18
|
+
process.on('SIGTERM', stop);
|
|
19
|
+
serveHalf(io, DISK.blueprint, filesUnder(folder), stop);
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PROGRAM: string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const PATH = {
|
|
5
|
+
type: 'array',
|
|
6
|
+
items: { type: 'string', pattern: '^[^./\\\\][^/\\\\]*$' },
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const BYTES = { type: 'string', contentEncoding: 'base16' };
|
|
10
|
+
|
|
11
|
+
const AT = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: { path: PATH },
|
|
14
|
+
required: ['path'],
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const BLUEPRINT = {
|
|
19
|
+
name: 'nervur.disk',
|
|
20
|
+
version: '0.1.40',
|
|
21
|
+
description: 'Whole files under the one folder its reach names, read, written, listed and removed.',
|
|
22
|
+
methods: {
|
|
23
|
+
read: {
|
|
24
|
+
description: "A file's bytes.",
|
|
25
|
+
args: AT,
|
|
26
|
+
result: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: { bytes: BYTES },
|
|
29
|
+
required: ['bytes'],
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
},
|
|
32
|
+
errors: ['absent'],
|
|
33
|
+
},
|
|
34
|
+
list: {
|
|
35
|
+
description: 'The names in a folder.',
|
|
36
|
+
args: AT,
|
|
37
|
+
result: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: { names: { type: 'array', items: { type: 'string' } } },
|
|
40
|
+
required: ['names'],
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
},
|
|
43
|
+
errors: ['absent'],
|
|
44
|
+
},
|
|
45
|
+
write: {
|
|
46
|
+
description: "Writes a file's bytes whole, making the folders its path names.",
|
|
47
|
+
args: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: { path: PATH, bytes: BYTES },
|
|
50
|
+
required: ['path', 'bytes'],
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
remove: {
|
|
55
|
+
description: 'Removes a file, or a folder that holds nothing.',
|
|
56
|
+
irreversible: true,
|
|
57
|
+
args: AT,
|
|
58
|
+
errors: ['absent'],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const DISK
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
= {
|
|
67
|
+
id: 'disk',
|
|
68
|
+
blueprint: BLUEPRINT,
|
|
69
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type BridgeTransportSeam, type CarriersHalf, type CarriersSeam, type Exchange, type HostHalf, type WebCarrier } from '@nervur.org/genome/seams';
|
|
2
|
+
import { type Answer, type Data } from '@nervur.org/genome/standard';
|
|
3
|
+
import type { Carrier } from './lines.js';
|
|
4
|
+
import { type Counts, type Near, type Restart } from './near.js';
|
|
5
|
+
export type { Restart } from './near.js';
|
|
6
|
+
export type NetworkHalfState = CarriersHalf & Readonly<Counts>;
|
|
7
|
+
export type NodeNetwork = {
|
|
8
|
+
readonly carriers: Omit<CarriersSeam, 'half'> & {
|
|
9
|
+
readonly web: WebCarrier;
|
|
10
|
+
readonly half: () => NetworkHalfState;
|
|
11
|
+
};
|
|
12
|
+
readonly reached: Promise<readonly string[]>;
|
|
13
|
+
readonly failed: Promise<string>;
|
|
14
|
+
readonly close: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export declare const taken: (near: Near, kind: 'tcp' | 'web', exchange: Exchange) => {
|
|
17
|
+
readonly half: Exchange;
|
|
18
|
+
readonly carrier: Carrier;
|
|
19
|
+
} | null;
|
|
20
|
+
export declare const askedOf: (near: Near) => (method: string, args: Data, within?: number) => Promise<Answer>;
|
|
21
|
+
export declare const nodeNetwork: (bridge: BridgeTransportSeam, half: HostHalf, restart?: Restart) => NodeNetwork;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import {
|
|
3
|
+
NO_REST,
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
} from '@nervur.org/genome/seams';
|
|
11
|
+
import { error, } from '@nervur.org/genome/standard';
|
|
12
|
+
import { LONGEST_TIMEOUT } from '../../../src/door/longest.js';
|
|
13
|
+
import { addressesIn, fieldIn, responseIn, textIn, wantedIn } from './link.js';
|
|
14
|
+
|
|
15
|
+
import { stillOf } from './sent.js';
|
|
16
|
+
import { holding, nearOf, pulled, startHalf, } from './near.js';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const RESTART = { first: 1000, most: 60_000, within: LONGEST_TIMEOUT };
|
|
21
|
+
|
|
22
|
+
const GRACE = 2000;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const whyOf = (answer ) =>
|
|
37
|
+
'error' in answer ? { why: answer.error.message } : { why: 'the half answered no why' };
|
|
38
|
+
|
|
39
|
+
const webOver = (near ) => {
|
|
40
|
+
const asked = askedOf(near);
|
|
41
|
+
let sent = 0;
|
|
42
|
+
return {
|
|
43
|
+
request: async (request, rest, wait) => {
|
|
44
|
+
sent += 1;
|
|
45
|
+
const flow = `s${sent}`;
|
|
46
|
+
const { promise: lapsed, resolve: lapse } = Promise.withResolvers ();
|
|
47
|
+
const backstop = stillOf(wait + GRACE, () =>
|
|
48
|
+
lapse(error('unavailable', `network's half answered nothing within ${wait + GRACE} ms`)),
|
|
49
|
+
);
|
|
50
|
+
if (request.body.more) near.going.set(flow, () => (backstop.moved(), rest()));
|
|
51
|
+
const { body, ...head } = request;
|
|
52
|
+
const args = {
|
|
53
|
+
request: { ...head, headers: { ...head.headers }, body: body.bytes, more: body.more },
|
|
54
|
+
wait,
|
|
55
|
+
flow,
|
|
56
|
+
};
|
|
57
|
+
const answer = await Promise.race([asked('request', args), lapsed]);
|
|
58
|
+
backstop.end();
|
|
59
|
+
if (!('result' in answer)) {
|
|
60
|
+
near.going.delete(flow);
|
|
61
|
+
return whyOf(answer);
|
|
62
|
+
}
|
|
63
|
+
const response = responseIn(answer.result);
|
|
64
|
+
if (response === null) return { why: 'the half answered no response' };
|
|
65
|
+
return { response, rest: response.body.more ? pulled(near, flow) : NO_REST };
|
|
66
|
+
},
|
|
67
|
+
serve: async (endpoint, arrived) => {
|
|
68
|
+
near.serves.set(endpoint, arrived);
|
|
69
|
+
const answer = await asked('serve', { endpoint });
|
|
70
|
+
const origin = 'result' in answer ? textIn(answer.result, 'origin') : null;
|
|
71
|
+
return origin === null ? whyOf(answer) : { origin };
|
|
72
|
+
},
|
|
73
|
+
respond: (exchange, response, rest) => {
|
|
74
|
+
const own = taken(near, 'web', exchange);
|
|
75
|
+
if (own === null) return;
|
|
76
|
+
if (response.body.more) near.going.set(`e${own.half}`, rest);
|
|
77
|
+
const { body, ...head } = response;
|
|
78
|
+
void asked('respond', {
|
|
79
|
+
exchange: own.half,
|
|
80
|
+
response: { ...head, headers: { ...head.headers }, body: body.bytes, more: body.more },
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const openedOver =
|
|
87
|
+
(near ) =>
|
|
88
|
+
(exchange) => {
|
|
89
|
+
const held = near.exchanges.tcp.get(exchange);
|
|
90
|
+
if (held !== undefined && held.start === near.starts && near.link?.connected === true)
|
|
91
|
+
void askedOf(near)('opened', { exchange: held.half, carrier: held.carrier });
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const tcpOver = (
|
|
95
|
+
near ,
|
|
96
|
+
reach ,
|
|
97
|
+
fail ,
|
|
98
|
+
) => {
|
|
99
|
+
const asked = askedOf(near);
|
|
100
|
+
return {
|
|
101
|
+
listen: async (endpoint, arrived, addresses, declared) => {
|
|
102
|
+
const told = (now ) => {
|
|
103
|
+
reach(now);
|
|
104
|
+
addresses(now);
|
|
105
|
+
};
|
|
106
|
+
near.listens.set(endpoint, { arrived, addresses: told, declared });
|
|
107
|
+
const answer = await asked('listen', { endpoint });
|
|
108
|
+
const found = 'result' in answer ? addressesIn(answer.result) : null;
|
|
109
|
+
if (found === null) {
|
|
110
|
+
const why = whyOf(answer);
|
|
111
|
+
fail(why.why);
|
|
112
|
+
return why;
|
|
113
|
+
}
|
|
114
|
+
reach(found);
|
|
115
|
+
return { addresses: found };
|
|
116
|
+
},
|
|
117
|
+
bounds: (words) => {
|
|
118
|
+
near.words = words;
|
|
119
|
+
if (near.link?.connected === true) void near.link.ask('bounds', { words: { ...words } });
|
|
120
|
+
},
|
|
121
|
+
reply: (exchange, bytes) => {
|
|
122
|
+
const own = taken(near, 'tcp', exchange);
|
|
123
|
+
if (own !== null) void asked('reply', { exchange: own.half, carrier: own.carrier, bytes });
|
|
124
|
+
},
|
|
125
|
+
opened: openedOver(near),
|
|
126
|
+
hold: (lines, arrived, held, challenged) => {
|
|
127
|
+
holding(near, { wanted: lines, arrived, held, challenged });
|
|
128
|
+
if (near.link?.connected === true) void near.link.ask('hold', { lines: wantedIn(lines) });
|
|
129
|
+
},
|
|
130
|
+
send: async (address, bytes, wait, ward) => {
|
|
131
|
+
const args = { address, bytes, wait, ...(ward === undefined ? {} : { ward }) };
|
|
132
|
+
const answer = await asked('send', args, wait + GRACE);
|
|
133
|
+
if (!('result' in answer)) return whyOf(answer);
|
|
134
|
+
const reply = fieldIn(answer.result, 'reply');
|
|
135
|
+
return reply === null || reply instanceof Uint8Array ? { reply } : { why: 'the half answered no reply' };
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const taken = (
|
|
141
|
+
near ,
|
|
142
|
+
kind ,
|
|
143
|
+
exchange ,
|
|
144
|
+
) => {
|
|
145
|
+
const held = near.exchanges[kind].get(exchange);
|
|
146
|
+
near.exchanges[kind].delete(exchange);
|
|
147
|
+
return held !== undefined && held.start === near.starts && near.link?.connected === true
|
|
148
|
+
? { half: held.half, carrier: held.carrier }
|
|
149
|
+
: null;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const askedOf =
|
|
153
|
+
(near ) =>
|
|
154
|
+
(method , args , within ) => {
|
|
155
|
+
const link = near.link;
|
|
156
|
+
const why = () => error('unavailable', near.down || "network's half is down");
|
|
157
|
+
if (link?.connected === true) return link.ask(method, args, within);
|
|
158
|
+
if (link === null || near.closed) return Promise.resolve(why());
|
|
159
|
+
return new Promise((done) => {
|
|
160
|
+
near.waiting.push((now) => done(now === null ? why() : now.ask(method, args, within)));
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const nodeNetwork = (bridge , half , restart = RESTART) => {
|
|
165
|
+
const near = nearOf(restart);
|
|
166
|
+
let standing = half;
|
|
167
|
+
const { promise: reached, resolve: reach } = Promise.withResolvers ();
|
|
168
|
+
const { promise: failed, resolve: fail } = Promise.withResolvers ();
|
|
169
|
+
startHalf(near, bridge, () => standing, restart);
|
|
170
|
+
return {
|
|
171
|
+
carriers: {
|
|
172
|
+
...tcpOver(near, reach, fail),
|
|
173
|
+
web: webOver(near),
|
|
174
|
+
get schemes() {
|
|
175
|
+
return near.schemes;
|
|
176
|
+
},
|
|
177
|
+
release: (next) => {
|
|
178
|
+
standing = next;
|
|
179
|
+
near.again?.();
|
|
180
|
+
},
|
|
181
|
+
half: () => ({
|
|
182
|
+
down: near.link?.connected === true ? null : near.down,
|
|
183
|
+
restarts: near.restarts,
|
|
184
|
+
...near.counts,
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
reached,
|
|
188
|
+
failed,
|
|
189
|
+
close: async () => {
|
|
190
|
+
near.closed = true;
|
|
191
|
+
if (near.timer !== null) clearTimeout(near.timer);
|
|
192
|
+
await near.link?.close();
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const STILL = 60_000;
|
|
17
|
+
|
|
18
|
+
export const flowsOf = (wants ) => {
|
|
19
|
+
let still = STILL;
|
|
20
|
+
const came = new Map ();
|
|
21
|
+
const going = new Map ();
|
|
22
|
+
const idle = new Map ();
|
|
23
|
+
const ended = (way , flow ) => {
|
|
24
|
+
clearTimeout(idle.get(way + flow));
|
|
25
|
+
idle.delete(way + flow);
|
|
26
|
+
if (way === 'came') return void came.delete(flow);
|
|
27
|
+
const given = going.get(flow);
|
|
28
|
+
going.delete(flow);
|
|
29
|
+
return given;
|
|
30
|
+
};
|
|
31
|
+
const stirred = (way , flow ) => {
|
|
32
|
+
clearTimeout(idle.get(way + flow));
|
|
33
|
+
const timer = setTimeout(() => ended(way, flow)?.({ why: 'the body stood still too long' }), still);
|
|
34
|
+
timer.unref();
|
|
35
|
+
idle.set(way + flow, timer);
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
bound: (wait) => {
|
|
39
|
+
still = wait ?? STILL;
|
|
40
|
+
},
|
|
41
|
+
came: (flow, rest) => {
|
|
42
|
+
came.set(flow, rest);
|
|
43
|
+
stirred('came', flow);
|
|
44
|
+
},
|
|
45
|
+
wanted: (flow) => () =>
|
|
46
|
+
new Promise((given) => {
|
|
47
|
+
going.set(flow, given);
|
|
48
|
+
stirred('going', flow);
|
|
49
|
+
wants(flow);
|
|
50
|
+
}),
|
|
51
|
+
pull: (flow) => {
|
|
52
|
+
const rest = came.get(flow);
|
|
53
|
+
if (rest === undefined) return null;
|
|
54
|
+
stirred('came', flow);
|
|
55
|
+
return rest().then((piece) => {
|
|
56
|
+
if ('why' in piece || !piece.more) ended('came', flow);
|
|
57
|
+
return piece;
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
put: (flow, piece) => {
|
|
61
|
+
if (!going.has(flow)) return false;
|
|
62
|
+
ended('going', flow)?.(piece);
|
|
63
|
+
return true;
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
};
|