@serfab/cadre-core 1.14.0 → 1.15.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.
- package/README.md +293 -274
- package/dist/cadre-invite-protocol.d.ts +64 -29
- package/dist/cadre-invite-protocol.js +207 -38
- package/dist/cadre-invite-protocol.js.map +1 -1
- package/dist/cadre-join-request.d.ts +42 -0
- package/dist/cadre-join-request.js +144 -0
- package/dist/cadre-join-request.js.map +1 -0
- package/dist/cadre-node.d.ts +375 -79
- package/dist/cadre-node.js +758 -186
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-database.d.ts +92 -12
- package/dist/control-database.js +323 -142
- package/dist/control-database.js.map +1 -1
- package/dist/control-schema.d.ts +1 -1
- package/dist/control-schema.js +19 -3
- package/dist/control-schema.js.map +1 -1
- package/dist/ed25519-key.d.ts +7 -9
- package/dist/ed25519-key.js +20 -10
- package/dist/ed25519-key.js.map +1 -1
- package/dist/fetch-impl.d.ts +12 -0
- package/dist/fetch-impl.js +23 -0
- package/dist/fetch-impl.js.map +1 -0
- package/dist/file-durable-slot.js +2 -1
- package/dist/file-durable-slot.js.map +1 -1
- package/dist/file-safe-name.d.ts +25 -0
- package/dist/file-safe-name.js +29 -0
- package/dist/file-safe-name.js.map +1 -0
- package/dist/formation-approval.js +5 -11
- package/dist/formation-approval.js.map +1 -1
- package/dist/fs-atomic.d.ts +0 -19
- package/dist/fs-atomic.js +3 -24
- package/dist/fs-atomic.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/dist/invitation-bootstrap.d.ts +50 -12
- package/dist/invitation-bootstrap.js +76 -13
- package/dist/invitation-bootstrap.js.map +1 -1
- package/dist/joined-strand-store.d.ts +7 -0
- package/dist/joined-strand-store.js +9 -0
- package/dist/joined-strand-store.js.map +1 -1
- package/dist/key-store-file.js +2 -1
- package/dist/key-store-file.js.map +1 -1
- package/dist/link-budget.d.ts +9 -4
- package/dist/link-budget.js +9 -4
- package/dist/link-budget.js.map +1 -1
- package/dist/machine-removal.d.ts +78 -0
- package/dist/machine-removal.js +166 -0
- package/dist/machine-removal.js.map +1 -0
- package/dist/membership-connection-gater.d.ts +6 -5
- package/dist/membership-connection-gater.js +6 -5
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/node-claim-payload.d.ts +55 -0
- package/dist/node-claim-payload.js +108 -4
- package/dist/node-claim-payload.js.map +1 -1
- package/dist/node-default-transports.d.ts +27 -0
- package/dist/node-default-transports.js +35 -0
- package/dist/node-default-transports.js.map +1 -0
- package/dist/node-transports.d.ts +30 -0
- package/dist/node-transports.js +40 -0
- package/dist/node-transports.js.map +1 -0
- package/dist/peer-dial.d.ts +124 -27
- package/dist/peer-dial.js +254 -30
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.js +6 -0
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/peer-record.d.ts +6 -45
- package/dist/peer-record.js +8 -50
- package/dist/peer-record.js.map +1 -1
- package/dist/primary-lan-address.d.ts +8 -0
- package/dist/primary-lan-address.js +46 -0
- package/dist/primary-lan-address.js.map +1 -0
- package/dist/provider/client.d.ts +131 -0
- package/dist/provider/client.js +226 -0
- package/dist/provider/client.js.map +1 -0
- package/dist/provider/descriptor.d.ts +41 -0
- package/dist/provider/descriptor.js +103 -0
- package/dist/provider/descriptor.js.map +1 -0
- package/dist/provider/index.d.ts +9 -0
- package/dist/provider/index.js +10 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/oauth.d.ts +125 -0
- package/dist/provider/oauth.js +199 -0
- package/dist/provider/oauth.js.map +1 -0
- package/dist/provider/rent-node.d.ts +101 -0
- package/dist/provider/rent-node.js +220 -0
- package/dist/provider/rent-node.js.map +1 -0
- package/dist/relay-addrs.d.ts +9 -4
- package/dist/relay-addrs.js +9 -4
- package/dist/relay-addrs.js.map +1 -1
- package/dist/relay-reservation.d.ts +51 -16
- package/dist/relay-reservation.js +107 -24
- package/dist/relay-reservation.js.map +1 -1
- package/dist/seed-bootstrap.d.ts +22 -5
- package/dist/seed-bootstrap.js +48 -25
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +54 -0
- package/dist/strand-commit-durability.js +74 -0
- package/dist/strand-commit-durability.js.map +1 -0
- package/dist/strand-database.d.ts +23 -8
- package/dist/strand-database.js +41 -13
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +7 -1
- package/dist/strand-first-sync-gate.js +7 -1
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-protocol.js +4 -1
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-fret-addrs.d.ts +19 -1
- package/dist/strand-fret-addrs.js +27 -9
- package/dist/strand-fret-addrs.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +81 -19
- package/dist/strand-instance-manager.js +216 -105
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-move.d.ts +124 -0
- package/dist/strand-move.js +438 -0
- package/dist/strand-move.js.map +1 -0
- package/dist/strand-network-config.js +7 -6
- package/dist/strand-network-config.js.map +1 -1
- package/dist/strand-peer-redial.d.ts +113 -0
- package/dist/strand-peer-redial.js +236 -0
- package/dist/strand-peer-redial.js.map +1 -0
- package/dist/strand-wake-protocol.js +10 -7
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/types.d.ts +212 -4
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -1
- package/package.json +18 -10
- package/src/cadre-invite-protocol.ts +233 -45
- package/src/cadre-join-request.ts +167 -0
- package/src/cadre-node.ts +10003 -9381
- package/src/control-database.ts +4663 -4451
- package/src/control-schema.ts +19 -3
- package/src/ed25519-key.ts +20 -10
- package/src/fetch-impl.ts +23 -0
- package/src/file-durable-slot.ts +64 -63
- package/src/file-safe-name.ts +32 -0
- package/src/formation-approval.ts +604 -610
- package/src/fs-atomic.ts +92 -117
- package/src/index.ts +789 -722
- package/src/invitation-bootstrap.ts +91 -13
- package/src/joined-strand-store.ts +508 -498
- package/src/key-store-file.ts +142 -141
- package/src/link-budget.ts +9 -4
- package/src/machine-removal.ts +216 -0
- package/src/membership-connection-gater.ts +638 -637
- package/src/node-claim-payload.ts +138 -4
- package/src/node-default-transports.ts +38 -0
- package/src/node-transports.ts +49 -0
- package/src/peer-dial.ts +604 -336
- package/src/peer-join-backfill.ts +6 -0
- package/src/peer-record.ts +159 -202
- package/src/primary-lan-address.ts +47 -0
- package/src/provider/client.ts +326 -0
- package/src/provider/descriptor.ts +129 -0
- package/src/provider/index.ts +59 -0
- package/src/provider/oauth.ts +285 -0
- package/src/provider/rent-node.ts +275 -0
- package/src/relay-addrs.ts +9 -4
- package/src/relay-reservation.ts +1211 -1121
- package/src/seed-bootstrap.ts +1502 -1471
- package/src/strand-commit-durability.ts +116 -0
- package/src/strand-database.ts +46 -14
- package/src/strand-first-sync-gate.ts +7 -1
- package/src/strand-formation-protocol.ts +1039 -1036
- package/src/strand-fret-addrs.ts +179 -145
- package/src/strand-instance-manager.ts +2026 -1883
- package/src/strand-move.ts +585 -0
- package/src/strand-network-config.ts +7 -6
- package/src/strand-peer-redial.ts +307 -0
- package/src/strand-wake-protocol.ts +10 -7
- package/src/types.ts +220 -4
package/src/fs-atomic.ts
CHANGED
|
@@ -1,117 +1,92 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node-only filesystem helpers: atomic file write
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const
|
|
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
|
-
await
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// file so a retry leaves no `.tmp` debris. The destination is only ever
|
|
94
|
-
// swapped by the atomic rename, so the previous bytes stay intact.
|
|
95
|
-
await rm(tmpPath, { force: true }).catch(() => {});
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
await syncDirBestEffort(dir);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Best-effort fsync of a directory so a fresh file's directory entry is
|
|
103
|
-
* durable across power loss. Opening a directory for fsync is not portable
|
|
104
|
-
* (unsupported on Windows and some filesystems), and rename atomicity does not
|
|
105
|
-
* depend on it — so a failure here is logged and swallowed, never surfaced.
|
|
106
|
-
*/
|
|
107
|
-
async function syncDirBestEffort(dir: string): Promise<void> {
|
|
108
|
-
let dirHandle: FileHandle | undefined;
|
|
109
|
-
try {
|
|
110
|
-
dirHandle = await open(dir, 'r');
|
|
111
|
-
await dirHandle.sync();
|
|
112
|
-
} catch (error) {
|
|
113
|
-
log('directory fsync skipped for %s: %o', dir, error);
|
|
114
|
-
} finally {
|
|
115
|
-
await dirHandle?.close().catch(() => {});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Node-only filesystem helpers: atomic file write and the ENOENT check, shared
|
|
3
|
+
* by `key-store-file.ts` and `file-durable-slot.ts`. The filename-safe encoding
|
|
4
|
+
* they also use is cross-platform and lives in `file-safe-name.ts`.
|
|
5
|
+
*
|
|
6
|
+
* This module imports `node:fs/promises`, so — like its consumers — it is kept
|
|
7
|
+
* OUT of the package's cross-platform default entry and is not itself an
|
|
8
|
+
* exported subpath; it is only reachable through the Node-only store modules.
|
|
9
|
+
*/
|
|
10
|
+
import debug from 'debug';
|
|
11
|
+
import { mkdir, rm, rename, open } from 'node:fs/promises';
|
|
12
|
+
import type { FileHandle } from 'node:fs/promises';
|
|
13
|
+
|
|
14
|
+
const log = debug('sereus:cadre:fs-atomic');
|
|
15
|
+
|
|
16
|
+
/** Best-effort POSIX permissions (ignored on Windows / unsupported FSes). */
|
|
17
|
+
export const DIR_MODE = 0o700;
|
|
18
|
+
export const FILE_MODE = 0o600;
|
|
19
|
+
|
|
20
|
+
/** Whether an unknown error is a Node "file/dir not found" (ENOENT). */
|
|
21
|
+
export function isNotFound(error: unknown): boolean {
|
|
22
|
+
return typeof error === 'object' && error !== null
|
|
23
|
+
&& (error as { code?: unknown }).code === 'ENOENT';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Crash-atomic file write: a concurrent reader sees either the complete
|
|
28
|
+
* previous bytes or the complete new bytes, never a torn file. `dir` is created
|
|
29
|
+
* (0700) if absent; the data is written to `tmpPath` (created exclusively,
|
|
30
|
+
* 0600), fsync'd, then atomically renamed onto `finalPath`. A failure at any
|
|
31
|
+
* point removes the temp file and leaves the previous file untouched.
|
|
32
|
+
*
|
|
33
|
+
* `tmpPath` must be a sibling of `finalPath` (same directory) so the rename
|
|
34
|
+
* stays within one filesystem and is therefore atomic, and should carry a
|
|
35
|
+
* random component so concurrent writers (and crash-orphaned leftovers) are
|
|
36
|
+
* collide-free.
|
|
37
|
+
*
|
|
38
|
+
* Durability bar: the temp file is fsync'd before the rename so a power loss
|
|
39
|
+
* cannot surface a file whose bytes never reached the platter, and `dir` is
|
|
40
|
+
* fsync'd afterwards (best-effort — see {@link syncDirBestEffort}) so the
|
|
41
|
+
* rename itself survives a crash. On POSIX `rename(2)` replaces atomically;
|
|
42
|
+
* Node maps to `MoveFileEx(MOVEFILE_REPLACE_EXISTING)` on Windows, which is
|
|
43
|
+
* also atomic — though it can fail with `EPERM`/`EBUSY` if another process
|
|
44
|
+
* holds the destination open. That cross-process case is out of scope for the
|
|
45
|
+
* single-flight in-process callers here; such a failure surfaces to the caller
|
|
46
|
+
* with the previous file left intact.
|
|
47
|
+
*/
|
|
48
|
+
export async function writeFileAtomically(
|
|
49
|
+
dir: string,
|
|
50
|
+
tmpPath: string,
|
|
51
|
+
finalPath: string,
|
|
52
|
+
data: Uint8Array
|
|
53
|
+
): Promise<void> {
|
|
54
|
+
await mkdir(dir, { recursive: true, mode: DIR_MODE });
|
|
55
|
+
// 'wx' creates the temp file exclusively; a name collision (astronomically
|
|
56
|
+
// unlikely given the caller's random component) fails here before we own anything.
|
|
57
|
+
const handle = await open(tmpPath, 'wx', FILE_MODE);
|
|
58
|
+
try {
|
|
59
|
+
try {
|
|
60
|
+
await handle.writeFile(data);
|
|
61
|
+
await handle.sync(); // land bytes on disk before the rename exposes them
|
|
62
|
+
} finally {
|
|
63
|
+
await handle.close().catch(() => {});
|
|
64
|
+
}
|
|
65
|
+
await rename(tmpPath, finalPath);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Any failure after creation (write, sync, or rename): drop the temp
|
|
68
|
+
// file so a retry leaves no `.tmp` debris. The destination is only ever
|
|
69
|
+
// swapped by the atomic rename, so the previous bytes stay intact.
|
|
70
|
+
await rm(tmpPath, { force: true }).catch(() => {});
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
await syncDirBestEffort(dir);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Best-effort fsync of a directory so a fresh file's directory entry is
|
|
78
|
+
* durable across power loss. Opening a directory for fsync is not portable
|
|
79
|
+
* (unsupported on Windows and some filesystems), and rename atomicity does not
|
|
80
|
+
* depend on it — so a failure here is logged and swallowed, never surfaced.
|
|
81
|
+
*/
|
|
82
|
+
async function syncDirBestEffort(dir: string): Promise<void> {
|
|
83
|
+
let dirHandle: FileHandle | undefined;
|
|
84
|
+
try {
|
|
85
|
+
dirHandle = await open(dir, 'r');
|
|
86
|
+
await dirHandle.sync();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
log('directory fsync skipped for %s: %o', dir, error);
|
|
89
|
+
} finally {
|
|
90
|
+
await dirHandle?.close().catch(() => {});
|
|
91
|
+
}
|
|
92
|
+
}
|