@rljson/fs-agent 0.2.0 → 0.2.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.
- package/README.api.md +128 -5
- package/README.architecture.md +52 -3
- package/README.md +2 -2
- package/README.public.md +42 -5
- package/README.tests.md +44 -13
- package/dist/README.api.md +128 -5
- package/dist/README.architecture.md +52 -3
- package/dist/README.md +2 -2
- package/dist/README.public.md +42 -5
- package/dist/README.tests.md +44 -13
- package/dist/fs-agent.d.ts +101 -9
- package/dist/fs-agent.js +4977 -4436
- package/dist/fs-atomic-write.d.ts +11 -0
- package/dist/fs-history.d.ts +83 -0
- package/dist/fs-scanner.d.ts +19 -0
- package/dist/fs-send.d.ts +14 -1
- package/dist/fs-signals.d.ts +45 -2
- package/dist/fs-stamps.d.ts +8 -0
- package/dist/fs_agent_version.d.ts +2 -0
- package/dist/index.d.ts +5 -3
- package/package.json +28 -42
|
@@ -28,6 +28,17 @@ export declare const atomicTmpPath: (filePath: string) => string;
|
|
|
28
28
|
* @param content - Bytes to write.
|
|
29
29
|
*/
|
|
30
30
|
export declare const atomicWriteFile: (filePath: string, content: Buffer | string) => Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* {@link atomicWriteFile}, synchronously.
|
|
33
|
+
*
|
|
34
|
+
* For the agent's own bookkeeping files — the signal log and the state file —
|
|
35
|
+
* which are written from places that cannot wait, and which a host reads while
|
|
36
|
+
* the agent runs. Written in place, a crash between the truncate and the write
|
|
37
|
+
* left an empty file, and the next start could not read the history it held.
|
|
38
|
+
* @param filePath - Destination path.
|
|
39
|
+
* @param content - Bytes to write.
|
|
40
|
+
*/
|
|
41
|
+
export declare const atomicWriteFileSync: (filePath: string, content: Buffer | string) => void;
|
|
31
42
|
/**
|
|
32
43
|
* Writes a stream to `filePath` through a staging file, one chunk at a time.
|
|
33
44
|
*
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Db } from '@rljson/db';
|
|
2
|
+
import { RefStamp } from '@rljson/rljson';
|
|
3
|
+
import { FsChainEntry } from './fs-edit-chain.ts';
|
|
4
|
+
/** One entry of the history, as a person is shown it. */
|
|
5
|
+
export interface FsHistoryEntry extends FsChainEntry {
|
|
6
|
+
/**
|
|
7
|
+
* `edit` — a change one node made; `merge` — two lineages joined, `previous`
|
|
8
|
+
* names both; `root` — where a lineage began.
|
|
9
|
+
*/
|
|
10
|
+
kind: 'edit' | 'merge' | 'root';
|
|
11
|
+
/**
|
|
12
|
+
* When the authoring node made the edit, epoch ms by THAT node's clock.
|
|
13
|
+
* Absent for a merge and a root: both are derived from their content so
|
|
14
|
+
* every node writes the same entry, and carry no time.
|
|
15
|
+
*/
|
|
16
|
+
at?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The announcement that first carried the entry to the fleet, as this node
|
|
19
|
+
* learned it — the order no clock decides. Absent until this node learned
|
|
20
|
+
* it, which for its own newest edit is a round trip to the hub.
|
|
21
|
+
*/
|
|
22
|
+
stamp?: RefStamp;
|
|
23
|
+
}
|
|
24
|
+
/** What {@link walkFsHistory} lists. */
|
|
25
|
+
export interface FsHistoryOptions {
|
|
26
|
+
/** The entry to start from. The agent defaults it to its own head. */
|
|
27
|
+
from?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Where the previous page stopped: its {@link FsHistoryPage.cursor}. Wins
|
|
30
|
+
* over `from`.
|
|
31
|
+
*/
|
|
32
|
+
cursor?: string;
|
|
33
|
+
/**
|
|
34
|
+
* How many entries one page holds. Default {@link FS_HISTORY_PAGE}, at most
|
|
35
|
+
* {@link DEFAULT_MAX_WALK}.
|
|
36
|
+
*/
|
|
37
|
+
limit?: number;
|
|
38
|
+
}
|
|
39
|
+
/** One page of a history. */
|
|
40
|
+
export interface FsHistoryPage {
|
|
41
|
+
/** Newest first. */
|
|
42
|
+
entries: FsHistoryEntry[];
|
|
43
|
+
/**
|
|
44
|
+
* Pass back as `cursor` for the next page. Absent when nothing is left to
|
|
45
|
+
* list. Opaque: its shape may change in any release.
|
|
46
|
+
*/
|
|
47
|
+
cursor?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Entries this page reached as a `previous` and could not read — history
|
|
50
|
+
* this node does not hold. Nothing older than them can be listed, and a host
|
|
51
|
+
* should say so rather than show the list as complete.
|
|
52
|
+
*/
|
|
53
|
+
missing: string[];
|
|
54
|
+
}
|
|
55
|
+
/** How many entries a page holds when the caller does not say. */
|
|
56
|
+
export declare const FS_HISTORY_PAGE = 50;
|
|
57
|
+
/** How a walk reads the chain: one entry, and the stamp it has. */
|
|
58
|
+
export interface FsHistorySource {
|
|
59
|
+
/** One entry, or `undefined` when this node cannot read it. */
|
|
60
|
+
entry(head: string): Promise<FsChainEntry | undefined>;
|
|
61
|
+
/** The entry's stamp, or `undefined` while this node does not know it. */
|
|
62
|
+
stamp(head: string): RefStamp | undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* One page of a chain's history, newest first. See the file header for the
|
|
66
|
+
* order.
|
|
67
|
+
* @param source - How to read the chain.
|
|
68
|
+
* @param options - Where to start, or continue, and how much to list.
|
|
69
|
+
* @returns The page.
|
|
70
|
+
*/
|
|
71
|
+
export declare const walkFsHistory: (source: FsHistorySource, options: FsHistoryOptions) => Promise<FsHistoryPage>;
|
|
72
|
+
/**
|
|
73
|
+
* The history of a chain in a database this process does not own — the store
|
|
74
|
+
* of an fs-agent running in another process, opened read-only by its host.
|
|
75
|
+
*
|
|
76
|
+
* **Writes nothing.** No table is created: the stamps are read when their
|
|
77
|
+
* table is there and are absent when it is not.
|
|
78
|
+
* @param db - The database holding the chain.
|
|
79
|
+
* @param treeKey - The route's trees table key.
|
|
80
|
+
* @param options - Where to start, or continue, and how much to list.
|
|
81
|
+
* @returns The page.
|
|
82
|
+
*/
|
|
83
|
+
export declare const readFsHistory: (db: Db, treeKey: string, options: FsHistoryOptions) => Promise<FsHistoryPage>;
|
package/dist/fs-scanner.d.ts
CHANGED
|
@@ -194,6 +194,18 @@ export declare class FsScanner {
|
|
|
194
194
|
private _pendingScan;
|
|
195
195
|
constructor(rootPath: string, options?: FsScanOptions);
|
|
196
196
|
get tree(): FsTree | null;
|
|
197
|
+
/**
|
|
198
|
+
* The files the last pass left out because they were not finished yet —
|
|
199
|
+
* seen for the first time, or written to while it ran. A later pass reads
|
|
200
|
+
* them once they settle.
|
|
201
|
+
* @returns Relative paths, `/`-separated.
|
|
202
|
+
*/
|
|
203
|
+
get deferred(): readonly string[];
|
|
204
|
+
/**
|
|
205
|
+
* How long a file has to be quiet before a pass reads it.
|
|
206
|
+
* @returns Milliseconds.
|
|
207
|
+
*/
|
|
208
|
+
get settleMs(): number;
|
|
197
209
|
/**
|
|
198
210
|
* When the pass that produced {@link tree} began — 0 before the first. A
|
|
199
211
|
* caller that wrote to the folder tells from it whether that pass could have
|
|
@@ -267,6 +279,13 @@ export declare class FsScanner {
|
|
|
267
279
|
* @returns True when the ignore list covers this path.
|
|
268
280
|
*/
|
|
269
281
|
private _shouldIgnorePath;
|
|
282
|
+
/**
|
|
283
|
+
* Whether the sync never sees a path: the ignore list, as the scan applies
|
|
284
|
+
* it.
|
|
285
|
+
* @param relativePath - Relative to the root, either separator.
|
|
286
|
+
* @returns `true` when no tree of this folder can hold the path.
|
|
287
|
+
*/
|
|
288
|
+
ignores(relativePath: string): boolean;
|
|
270
289
|
watch(): Promise<void>;
|
|
271
290
|
/**
|
|
272
291
|
* One safety-rescan pass: rescans the tree and, if its content differs from
|
package/dist/fs-send.d.ts
CHANGED
|
@@ -15,6 +15,11 @@ export interface AuthoringQuestion {
|
|
|
15
15
|
maxRatio: number;
|
|
16
16
|
/** A folder holding more than this may not end up with this many or fewer. */
|
|
17
17
|
allGoneMinFiles: number;
|
|
18
|
+
/**
|
|
19
|
+
* Paths an earlier refusal held back. While any of them is still gone, the
|
|
20
|
+
* disappearance is still refused, however few of its files are left.
|
|
21
|
+
*/
|
|
22
|
+
heldBack?: ReadonlySet<string>;
|
|
18
23
|
}
|
|
19
24
|
/** What {@link planAuthoring} decided. */
|
|
20
25
|
export type AuthoringPlan = {
|
|
@@ -42,10 +47,18 @@ export type AuthoringPlan = {
|
|
|
42
47
|
* - the watcher did not see them go, so a person deleting files while the
|
|
43
48
|
* agent runs is an ordinary edit;
|
|
44
49
|
* - it is large: more than `minFiles` and more than `maxRatio` of the folder,
|
|
45
|
-
* or a folder of more than `allGoneMinFiles` left with that many or fewer
|
|
50
|
+
* or a folder of more than `allGoneMinFiles` left with that many or fewer —
|
|
51
|
+
* or it is still part of a disappearance an earlier refusal held back.
|
|
46
52
|
*
|
|
47
53
|
* A few files deleted while the agent was down stay below the floors and are
|
|
48
54
|
* authored like any other edit.
|
|
55
|
+
*
|
|
56
|
+
* **A refusal holds its files until they are back.** A refused folder that
|
|
57
|
+
* fills up again one file at a time — a backup copied in, a drive coming back
|
|
58
|
+
* — shrinks below the floors part-way, and without the hold the files still
|
|
59
|
+
* to come would be authored as deleted, on every node, while they are being
|
|
60
|
+
* copied. A held file is let go when it is back, when the head no longer has
|
|
61
|
+
* it, or when the watcher sees it deleted after it came back.
|
|
49
62
|
* @param q - The folder, the head, and the floors.
|
|
50
63
|
* @returns `unchanged`, `author` with the delta against the head, or
|
|
51
64
|
* `refused` with the files that disappeared.
|
package/dist/fs-signals.d.ts
CHANGED
|
@@ -37,6 +37,14 @@ export type FsSignalAction =
|
|
|
37
37
|
| 'required';
|
|
38
38
|
/** One thing that happened to a folder, in a form a program can act on. */
|
|
39
39
|
export interface FsSignal {
|
|
40
|
+
/**
|
|
41
|
+
* This signal's identity: a hash of what happened, unique within the log.
|
|
42
|
+
*
|
|
43
|
+
* Derived rather than counted, so a log written before ids existed gets the
|
|
44
|
+
* same ids on every read, and a host can key a row, or remember what a
|
|
45
|
+
* person has seen, by it.
|
|
46
|
+
*/
|
|
47
|
+
id: string;
|
|
40
48
|
/** What happened. */
|
|
41
49
|
kind: FsSignalKind;
|
|
42
50
|
/** When, epoch ms. */
|
|
@@ -57,6 +65,21 @@ export interface FsSignal {
|
|
|
57
65
|
decidedBy?: FsSignalDecidedBy;
|
|
58
66
|
/** Where the version that lost the path was kept, when one was. */
|
|
59
67
|
copyPath?: string;
|
|
68
|
+
/**
|
|
69
|
+
* For a signal about several paths, where each one's own version went:
|
|
70
|
+
* original → copy. Only for the paths in {@link paths}.
|
|
71
|
+
*
|
|
72
|
+
* `join/conflicted` keeps a machine's edit beside the network's version, and
|
|
73
|
+
* `join/recovered` moves a file the history removed into
|
|
74
|
+
* `.fsagent-recovered/`; without this a host could name the files but not
|
|
75
|
+
* show where they went.
|
|
76
|
+
*/
|
|
77
|
+
copies?: Readonly<Record<string, string>>;
|
|
78
|
+
/**
|
|
79
|
+
* The chain entry this belongs to, when it belongs to one — for a merge
|
|
80
|
+
* conflict, the merge. A host can show the signal next to that revision.
|
|
81
|
+
*/
|
|
82
|
+
head?: string;
|
|
60
83
|
/** The edit this belongs to, when it belongs to one. */
|
|
61
84
|
timeId?: string;
|
|
62
85
|
/** One sentence for a person. Never a stack trace. */
|
|
@@ -89,8 +112,8 @@ export interface FsSignalLog {
|
|
|
89
112
|
*/
|
|
90
113
|
totals: Record<string, number>;
|
|
91
114
|
}
|
|
92
|
-
/** What a signal says before the sink stamps and bounds it. */
|
|
93
|
-
export type FsSignalInput = Omit<FsSignal, 'at' | 'paths' | 'pathCount'> & {
|
|
115
|
+
/** What a signal says before the sink stamps, identifies and bounds it. */
|
|
116
|
+
export type FsSignalInput = Omit<FsSignal, 'id' | 'at' | 'paths' | 'pathCount'> & {
|
|
94
117
|
/** The affected paths; sorted, capped and counted by the sink. */
|
|
95
118
|
paths: readonly string[];
|
|
96
119
|
/** Overrides the clock, for a test that needs a fixed stamp. */
|
|
@@ -154,6 +177,26 @@ export declare class FsSignals {
|
|
|
154
177
|
* @param raw - What was read from disk.
|
|
155
178
|
*/
|
|
156
179
|
restore(raw: unknown): void;
|
|
180
|
+
/**
|
|
181
|
+
* The copies of the paths a signal kept, or nothing.
|
|
182
|
+
*
|
|
183
|
+
* The cap bounds the signal, and a copy of a path the signal no longer names
|
|
184
|
+
* could not be explained; an empty map is left out rather than kept.
|
|
185
|
+
* @param copies - Original → copy, as the caller gave it.
|
|
186
|
+
* @param kept - The paths the signal names.
|
|
187
|
+
* @returns The `copies` field to spread, if any.
|
|
188
|
+
*/
|
|
189
|
+
private static _keptCopies;
|
|
190
|
+
/**
|
|
191
|
+
* An id for a signal: a hash of what it says, made unique within the log.
|
|
192
|
+
*
|
|
193
|
+
* Two signals that say the same thing in the same millisecond are possible —
|
|
194
|
+
* a refusal raised twice at once — and must still be two rows, so a repeat
|
|
195
|
+
* gets a counter rather than the same id.
|
|
196
|
+
* @param signal - The signal, without its id.
|
|
197
|
+
* @returns The id.
|
|
198
|
+
*/
|
|
199
|
+
private _uniqueId;
|
|
157
200
|
/**
|
|
158
201
|
* Whether a restored entry is shaped like a signal.
|
|
159
202
|
*
|
package/dist/fs-stamps.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { Db } from '@rljson/db';
|
|
2
2
|
import { RefStamp } from '@rljson/rljson';
|
|
3
|
+
/**
|
|
4
|
+
* Every stamp a route's chain entries carry, read without writing — for a host
|
|
5
|
+
* that opened another process's store read-only.
|
|
6
|
+
* @param db - The database holding the chain.
|
|
7
|
+
* @param treeKey - The route's trees table key.
|
|
8
|
+
* @returns Entry → stamp; empty when the table does not exist.
|
|
9
|
+
*/
|
|
10
|
+
export declare const readFsStamps: (db: Db, treeKey: string) => Promise<Map<string, RefStamp>>;
|
|
3
11
|
/**
|
|
4
12
|
* The stamp of every chain entry, as this node learned it.
|
|
5
13
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { FsSignals, SIGNAL_LOG_FILE, SIGNAL_LOG_MAX, SIGNAL_ONCE_MAX, SIGNAL_PATHS_MAX, type FsSignal, type FsSignalAction, type FsSignalDecidedBy, type FsSignalInput, type FsSignalKind, type FsSignalLog, } from './fs-signals.ts';
|
|
2
|
-
export { FsAgent, SYNC_ERROR_FILE, type FsAgentOptions, type RestoreOptions, type TimeoutConfig, } from './fs-agent.ts';
|
|
3
|
-
export { ATOMIC_TMP_PREFIX, atomicTmpPath, atomicWriteFile, atomicWriteStream, } from './fs-atomic-write.ts';
|
|
2
|
+
export { BlobUnavailableError, DiskFullError, FsAgent, MassDeleteRefusedError, PartialRestoreError, RestoreIncompleteError, SYNC_ERROR_FILE, UnwritablePathError, type FsAgentOptions, type RestoreOptions, type TimeoutConfig, } from './fs-agent.ts';
|
|
3
|
+
export { ATOMIC_TMP_PREFIX, atomicTmpPath, atomicWriteFile, atomicWriteFileSync, atomicWriteStream, } from './fs-atomic-write.ts';
|
|
4
|
+
export { FS_HISTORY_PAGE, readFsHistory, walkFsHistory, type FsHistoryEntry, type FsHistoryOptions, type FsHistoryPage, type FsHistorySource, } from './fs-history.ts';
|
|
5
|
+
export { readFsStamps } from './fs-stamps.ts';
|
|
4
6
|
export { compileIgnore, globToRegExp, type IgnoreMatcher, } from './fs-ignore.ts';
|
|
5
|
-
export type { AntiEntropyStatus } from './fs-receive.ts';
|
|
7
|
+
export type { AntiEntropyStatus, ReceiveOutcome, Relation, } from './fs-receive.ts';
|
|
6
8
|
export { createFsChainTables, FS_EDIT_ACTION, FsEditChain, type FsAppendOptions, type FsChainEntry, type FsEditData, } from './fs-edit-chain.ts';
|
|
7
9
|
export { FsBlobAdapter, type BlobToFileOptions, type FileBlobMeta, type FileToBlobOptions, } from './fs-blob-adapter.ts';
|
|
8
10
|
export { FsDbAdapter, type StoreFsTreeOptions } from './fs-db-adapter.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rljson/fs-agent",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Rljson fs-agent description",
|
|
5
5
|
"homepage": "https://github.com/rljson/fs-agent",
|
|
6
6
|
"bugs": "https://github.com/rljson/fs-agent/issues",
|
|
@@ -19,34 +19,28 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"type": "module",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "pnpm exec vite build && tsc && node scripts/copy-readme-to-dist.js",
|
|
24
|
-
"test": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm exec vitest run --coverage --no-file-parallelism && pnpm run lint",
|
|
25
|
-
"prebuild": "npm run test",
|
|
26
|
-
"prepublishOnly": "npm run build",
|
|
27
|
-
"lint": "pnpm exec eslint .",
|
|
28
|
-
"updateGoldens": "cross-env UPDATE_GOLDENS=true pnpm test"
|
|
29
|
-
},
|
|
30
22
|
"devDependencies": {
|
|
31
|
-
"@rljson/
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
23
|
+
"@rljson/dna-rljson": "0.2.0",
|
|
24
|
+
"@rljson/server": "0.0.77",
|
|
25
|
+
"@tssuite/helix-js": "0.4.1",
|
|
26
|
+
"@types/node": "^26.6.5",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^8.71.2",
|
|
28
|
+
"@typescript-eslint/parser": "^8.71.2",
|
|
29
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
36
30
|
"cross-env": "^10.1.0",
|
|
37
|
-
"eslint": "~
|
|
38
|
-
"eslint-plugin-jsdoc": "^
|
|
39
|
-
"eslint-plugin-tsdoc": "^0.5.
|
|
40
|
-
"globals": "^17.
|
|
31
|
+
"eslint": "~10.13.0",
|
|
32
|
+
"eslint-plugin-jsdoc": "^65.3.15",
|
|
33
|
+
"eslint-plugin-tsdoc": "^0.5.4",
|
|
34
|
+
"globals": "^17.13.0",
|
|
41
35
|
"jsdoc": "^4.0.5",
|
|
42
36
|
"read-pkg": "^10.1.0",
|
|
43
|
-
"typescript": "~
|
|
44
|
-
"typescript-eslint": "^8.
|
|
45
|
-
"vite": "^
|
|
46
|
-
"vite-node": "^
|
|
47
|
-
"vite-plugin-dts": "^
|
|
37
|
+
"typescript": "~6.0.3",
|
|
38
|
+
"typescript-eslint": "^8.71.2",
|
|
39
|
+
"vite": "^8.3.4",
|
|
40
|
+
"vite-node": "^6.0.0",
|
|
41
|
+
"vite-plugin-dts": "^5.1.2",
|
|
48
42
|
"vite-tsconfig-paths": "^6.1.1",
|
|
49
|
-
"vitest": "^
|
|
43
|
+
"vitest": "^5.0.5",
|
|
50
44
|
"vitest-dom": "^0.1.1"
|
|
51
45
|
},
|
|
52
46
|
"dependencies": {
|
|
@@ -56,22 +50,14 @@
|
|
|
56
50
|
"@rljson/io": "0.0.85",
|
|
57
51
|
"@rljson/json": "0.0.23",
|
|
58
52
|
"@rljson/rljson": "0.0.86",
|
|
59
|
-
"socket.io": "^4.8.
|
|
60
|
-
"socket.io-client": "^4.8.
|
|
53
|
+
"socket.io": "^4.8.4",
|
|
54
|
+
"socket.io-client": "^4.8.4"
|
|
61
55
|
},
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"@rljson/io": "0.0.85",
|
|
71
|
-
"@rljson/json": "0.0.23",
|
|
72
|
-
"@rljson/rljson": "0.0.86",
|
|
73
|
-
"@rljson/server": "0.0.76"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
"packageManager": "pnpm@10.11.0"
|
|
77
|
-
}
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "pnpm exec vite build && tsc && node scripts/copy-readme-to-dist.js",
|
|
58
|
+
"test": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm exec vitest run --coverage --no-file-parallelism && pnpm run lint",
|
|
59
|
+
"prebuild": "npm run test",
|
|
60
|
+
"lint": "pnpm exec eslint .",
|
|
61
|
+
"updateGoldens": "cross-env UPDATE_GOLDENS=true pnpm test"
|
|
62
|
+
}
|
|
63
|
+
}
|