@rljson/fs-agent 0.1.0 → 0.2.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.
@@ -0,0 +1,83 @@
1
+ /** How two heads stand — see `FsEditChain.relate`. */
2
+ export type Relation = {
3
+ verdict: 'same' | 'behind' | 'ahead' | 'incomplete';
4
+ } | {
5
+ verdict: 'fork';
6
+ base: string | undefined;
7
+ };
8
+ /** What {@link receive} needs from the agent. */
9
+ export interface ReceiveDeps {
10
+ /** This node's head, or `undefined` before it has one. */
11
+ ownHead(): string | undefined;
12
+ /** Authors whatever the folder holds beyond the own head, first. */
13
+ flushLocal(): Promise<void>;
14
+ /** How the own head and an arrived head stand. */
15
+ relate(ours: string, theirs: string): Promise<Relation>;
16
+ /** The tree ref a head names, or `undefined` when it cannot be read. */
17
+ treeRefOf(head: string): Promise<string | undefined>;
18
+ /**
19
+ * Writes a head's tree into the folder, deleting what it lacks, and makes it
20
+ * this node's head. `refused` when it could not — nothing was adopted then.
21
+ */
22
+ applyBehind(head: string): Promise<'applied' | 'refused'>;
23
+ /** Makes `head` — one state under another name — this node's head. */
24
+ adopt(head: string): Promise<void>;
25
+ /** Announces this node's head again. */
26
+ announceOwn(): void;
27
+ /** Merges a forked head into this node's; see `merge3`. */
28
+ merge(theirs: string, base: string | undefined): Promise<'merged' | 'deferred' | 'refused'>;
29
+ /** Says that nothing could be decided about `head`. */
30
+ blocked(head: string, reason: string): void;
31
+ }
32
+ /**
33
+ * Whether this node agrees with the head the hub said last, and what receiving
34
+ * it made this node do — `FsAgent.antiEntropyStatus`.
35
+ */
36
+ export interface AntiEntropyStatus {
37
+ /** Whether this node's head was not the hub's after receiving it. */
38
+ diverged: boolean;
39
+ /** Since when, epoch ms by this node's clock. */
40
+ divergedSince: number | null;
41
+ /** The head the hub said last. */
42
+ hubRef: string | null;
43
+ /** This node's head now. */
44
+ localRef: string | null;
45
+ /** How often the hub's head made this node act. */
46
+ repairs: number;
47
+ /**
48
+ * What it did last: `pull` applied or adopted it, `push` announced this
49
+ * node's own, `merge` merged the two, `blocked` could decide nothing.
50
+ */
51
+ lastRepair: {
52
+ action: 'pull' | 'push' | 'merge' | 'blocked';
53
+ at: number;
54
+ hubRef: string;
55
+ localRef: string;
56
+ /** How often in a row the same hub head made it act. */
57
+ attempt: number;
58
+ } | null;
59
+ }
60
+ /** What {@link receive} did. */
61
+ export type ReceiveOutcome = 'no-head' | 'in-sync' | 'applied' | 'refused' | 'announced' | 'adopted' | 'merged' | 'deferred' | 'blocked';
62
+ /**
63
+ * What a node does with a head that arrived.
64
+ *
65
+ * The chain is the only order:
66
+ *
67
+ * | relation | action |
68
+ * | --- | --- |
69
+ * | `behind` — theirs descends from ours | apply it, deleting what it lacks, and adopt it |
70
+ * | `ahead` — ours descends from theirs | announce ours |
71
+ * | `fork`, same content | converge on the smaller ref, on every node |
72
+ * | `fork` | merge against the base |
73
+ * | `incomplete` | nothing; say so |
74
+ *
75
+ * Deleting on `behind` is correct by construction: whoever made the head held
76
+ * this node's state and chose not to have the file. Work this node has not
77
+ * authored yet is authored first, so it can never be overwritten by a head
78
+ * that never saw it — it turns a `behind` into a `fork`.
79
+ * @param head - The head that arrived.
80
+ * @param deps - The agent.
81
+ * @returns What was done.
82
+ */
83
+ export declare const receive: (head: string, deps: ReceiveDeps) => Promise<ReceiveOutcome>;
@@ -76,13 +76,6 @@ export type FsChangeCallback = (change: FsChange) => void | Promise<void>;
76
76
  * already covered.
77
77
  */
78
78
  export declare const DEFAULT_SETTLE_MS = 100;
79
- /**
80
- * Default for {@link FsScanOptions.settleMinBytes}.
81
- *
82
- * One megabyte: above the size anything is written in a single operation, and
83
- * at the order where a copy takes long enough for a scan to land inside it.
84
- */
85
- export declare const DEFAULT_SETTLE_MIN_BYTES: number;
86
79
  export interface FsScanOptions {
87
80
  /** Patterns to ignore (glob patterns) */
88
81
  ignore?: string[];
@@ -123,22 +116,6 @@ export interface FsScanOptions {
123
116
  * waiting for the five-second safety rescan.
124
117
  */
125
118
  settleMs?: number;
126
- /**
127
- * Below this size a file is never held back for settling.
128
- *
129
- * The two halves of the rule cost different things. Asking "did it change
130
- * since this scan began" is free and catches a write that lands while the
131
- * scan runs. Asking "has it been quiet for a moment" catches a writer whose
132
- * gaps are wider than one scan — and costs every file that much latency.
133
- *
134
- * So the second half is spent only where the hazard is, which the register
135
- * names: *"eine große Datei wird 0,3 Sekunden nach dem ersten Byte gelesen
136
- * und als vollständiger Stand an alle verteilt"*. A document somebody saves
137
- * is written in one go and propagates as fast as it ever did; a
138
- * multi-megabyte copy waits a moment longer, and the alternative for it is
139
- * being published truncated.
140
- */
141
- settleMinBytes?: number;
142
119
  }
143
120
  /**
144
121
  * Scans and watches file system changes, extracting RLJSON tree structure
@@ -186,6 +163,8 @@ export declare class FsScanner {
186
163
  * {@link _scanDirectory}.
187
164
  */
188
165
  private _scanStartedAt;
166
+ /** When the pass that produced {@link tree} began; 0 before the first. */
167
+ private _treeStartedAt;
189
168
  /**
190
169
  * Large files whose size this scanner has seen but not yet seen settle.
191
170
  *
@@ -206,10 +185,60 @@ export declare class FsScanner {
206
185
  private _vanishedDuringScan;
207
186
  /** The scan pass running right now, if any. See {@link _scanAfterNow}. */
208
187
  private _activeScan;
188
+ /**
189
+ * Files this process wrote whole a moment ago — by an atomic rename — keyed
190
+ * by relative path. See {@link noteWrite}.
191
+ */
192
+ private readonly _ownWrites;
209
193
  /** The single follow-up pass everyone who arrived mid-scan is waiting on. */
210
194
  private _pendingScan;
211
195
  constructor(rootPath: string, options?: FsScanOptions);
212
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;
209
+ /**
210
+ * When the pass that produced {@link tree} began — 0 before the first. A
211
+ * caller that wrote to the folder tells from it whether that pass could have
212
+ * read its write half-done.
213
+ * @returns Epoch ms.
214
+ */
215
+ get treeStartedAt(): number;
216
+ /**
217
+ * The folder as it is now: a scan guaranteed to have STARTED after this
218
+ * call, sharing one pass with anyone else asking meanwhile. What a caller
219
+ * that acts on the folder must use — {@link tree} is the last pass, which
220
+ * may have run while something was still writing.
221
+ * @returns The tree.
222
+ */
223
+ scanFresh(): Promise<FsTree>;
224
+ /**
225
+ * Tells the scanner a file was just written whole by this process, with the
226
+ * given content. The next scan takes it as written — never as a copy still
227
+ * in progress, whatever its timestamp says. A file that changed since is
228
+ * read as usual.
229
+ *
230
+ * Without it, a write in the second half of the millisecond a scan starts
231
+ * in reads as "changed during this scan" — Node rounds an mtime to the
232
+ * nearest millisecond, the scan's start is truncated — and the scan reused
233
+ * the version BEFORE the write: measured as a receiver announcing the
234
+ * previous save of a file it had just applied, which reverted the writer's
235
+ * own copy.
236
+ * @param relativePath - The file, `/`-separated.
237
+ * @param blobId - Its content.
238
+ * @param size - Its size as written.
239
+ * @param mtime - Its mtime as written, ms.
240
+ */
241
+ noteWrite(relativePath: string, blobId: string, size: number, mtime: number): void;
213
242
  /** Whether a watcher is currently installed. */
214
243
  get isWatching(): boolean;
215
244
  get rootPath(): string;
@@ -250,6 +279,13 @@ export declare class FsScanner {
250
279
  * @returns True when the ignore list covers this path.
251
280
  */
252
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;
253
289
  watch(): Promise<void>;
254
290
  /**
255
291
  * One safety-rescan pass: rescans the tree and, if its content differs from
@@ -303,6 +339,17 @@ export declare class FsScanner {
303
339
  * @param err - The caught value
304
340
  * @returns A message string
305
341
  */
342
+ /**
343
+ * What a watcher error does off Windows: nothing that could crash.
344
+ *
345
+ * An FSWatcher with no `'error'` listener throws what it emits, and Node's
346
+ * recursive watcher on Linux emits ENOENT when a directory is deleted while
347
+ * it walks it — the agent died of a user deleting a nested folder. There is
348
+ * nothing to reinstall: the watcher stays, and the safety rescan picks up
349
+ * whatever it missed. Anything other than a vanished directory is said.
350
+ * @param err - The error the watcher emitted.
351
+ */
352
+ private static _onWatchError;
306
353
  private static _errMessage;
307
354
  /**
308
355
  * Whether a caught value is a "no longer there" filesystem error.
@@ -0,0 +1,53 @@
1
+ /** What {@link planAuthoring} is asked. */
2
+ export interface AuthoringQuestion {
3
+ /** The folder as it was just scanned, `path → blobId`. */
4
+ folder: ReadonlyMap<string, string>;
5
+ /** The folder as this node's own head describes it. */
6
+ head: ReadonlyMap<string, string>;
7
+ /**
8
+ * Paths the watcher saw deleted since the head was authored. A deleted
9
+ * directory covers everything below it.
10
+ */
11
+ watched: ReadonlySet<string>;
12
+ /** Below this many disappeared files, nothing is refused for its size. */
13
+ minFiles: number;
14
+ /** Above `minFiles`, the largest share of the folder that may disappear. */
15
+ maxRatio: number;
16
+ /** A folder holding more than this may not end up with this many or fewer. */
17
+ allGoneMinFiles: number;
18
+ }
19
+ /** What {@link planAuthoring} decided. */
20
+ export type AuthoringPlan = {
21
+ kind: 'unchanged';
22
+ } | {
23
+ kind: 'author';
24
+ changed: string[];
25
+ removed: string[];
26
+ } | {
27
+ kind: 'refused';
28
+ disappeared: string[];
29
+ held: number;
30
+ };
31
+ /**
32
+ * Whether this node may author an edit for what its folder looks like now.
33
+ *
34
+ * **The sender answers for the honesty of its edits.** A failed mount, an
35
+ * emptied disk or a drive that did not come back looks to the scanner like a
36
+ * person deleting most of the folder. Once authored, every peer would apply
37
+ * it. So a disappearance is refused HERE, at the source, when all of these
38
+ * hold:
39
+ *
40
+ * - the files are gone: their content is nowhere else in the folder, so a
41
+ * folder renamed while the agent was down is an ordinary edit;
42
+ * - the watcher did not see them go, so a person deleting files while the
43
+ * agent runs is an ordinary edit;
44
+ * - 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.
46
+ *
47
+ * A few files deleted while the agent was down stay below the floors and are
48
+ * authored like any other edit.
49
+ * @param q - The folder, the head, and the floors.
50
+ * @returns `unchanged`, `author` with the delta against the head, or
51
+ * `refused` with the files that disappeared.
52
+ */
53
+ export declare const planAuthoring: (q: AuthoringQuestion) => AuthoringPlan;
@@ -0,0 +1,212 @@
1
+ /** What a {@link FsSignal} is about. */
2
+ export type FsSignalKind =
3
+ /**
4
+ * Two machines changed one file at once, or one deleted what the other
5
+ * edited. Nothing was lost: both versions were kept (see `copyPath`), or the
6
+ * edit was. Which version keeps the path follows the order the fleet heard
7
+ * them in — which is not who edited last, so a person may want to look.
8
+ */
9
+ 'conflict/arbitrary'
10
+ /** A directory and a file at one path: both kept, a person decides. */
11
+ | 'collision/type'
12
+ /** A deletion was refused by the mass-delete guard and will not arrive. */
13
+ | 'deletion/refused'
14
+ /** A joining machine moved files the history had removed out of the way. */
15
+ | 'join/recovered'
16
+ /** A joining machine kept its own edit of a path beside the network's. */
17
+ | 'join/conflicted'
18
+ /** A divergence was found that cannot be repaired without losing work. */
19
+ | 'repair/blocked'
20
+ /** A path could not be written: locked, impossible, or the disk is full. */
21
+ | 'path/unwritable';
22
+ /** Who or what chose the outcome. */
23
+ export type FsSignalDecidedBy =
24
+ /** The edit chain: a fact about which edit came after which. */
25
+ 'chain'
26
+ /** Decided by the hub's stamps: which version reached the fleet later. */
27
+ | 'stamp'
28
+ /** A guard refused, so nothing was chosen. */
29
+ | 'guard';
30
+ /** Whether a person has to do something. */
31
+ export type FsSignalAction =
32
+ /** Resolved; nothing to do. */
33
+ 'none'
34
+ /** Resolved, but somebody may want to look — a kept copy, an arbitrary pick. */
35
+ | 'review'
36
+ /** NOT resolved. It stays this way until a person acts. */
37
+ | 'required';
38
+ /** One thing that happened to a folder, in a form a program can act on. */
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;
48
+ /** What happened. */
49
+ kind: FsSignalKind;
50
+ /** When, epoch ms. */
51
+ at: number;
52
+ /**
53
+ * The paths it affected, sorted.
54
+ *
55
+ * Capped at {@link SIGNAL_PATHS_MAX} with `pathCount` carrying the true
56
+ * number, because a mass deletion names thousands and a signal has to stay
57
+ * small enough to keep.
58
+ */
59
+ paths: readonly string[];
60
+ /** How many paths were affected, which may exceed `paths.length`. */
61
+ pathCount: number;
62
+ /** Whether a person has to do something. */
63
+ action: FsSignalAction;
64
+ /** How the outcome was chosen, where something chose it. */
65
+ decidedBy?: FsSignalDecidedBy;
66
+ /** Where the version that lost the path was kept, when one was. */
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;
83
+ /** The edit this belongs to, when it belongs to one. */
84
+ timeId?: string;
85
+ /** One sentence for a person. Never a stack trace. */
86
+ detail?: string;
87
+ }
88
+ /** How many signals {@link FsSignals.all} keeps. */
89
+ export declare const SIGNAL_LOG_MAX = 200;
90
+ /** How many paths one signal names before it only counts them. */
91
+ export declare const SIGNAL_PATHS_MAX = 20;
92
+ /**
93
+ * How many distinct {@link FsSignals.addOnce} keys are remembered.
94
+ *
95
+ * Bounded because a key can be derived from live state — the pair of refs a
96
+ * divergence is between, say — and a churning fleet produces new pairs
97
+ * indefinitely. Dropping the oldest means such a signal may be reported again
98
+ * later, which is noise rather than a falsehood; an unbounded set would be a
99
+ * leak, and this package has shipped two of those.
100
+ */
101
+ export declare const SIGNAL_ONCE_MAX = 500;
102
+ /** The file {@link FsSignals} persists to, inside the synced folder. */
103
+ export declare const SIGNAL_LOG_FILE = ".fsagent-signals.json";
104
+ /** What {@link FsSignals.persisted} writes and reads. */
105
+ export interface FsSignalLog {
106
+ /** The newest signals, oldest first, at most {@link SIGNAL_LOG_MAX}. */
107
+ signals: FsSignal[];
108
+ /**
109
+ * How many of each kind have EVER been recorded, including dropped ones.
110
+ *
111
+ * Survives the cap and survives a restart, so "and 1 240 more" is answerable.
112
+ */
113
+ totals: Record<string, number>;
114
+ }
115
+ /** What a signal says before the sink stamps, identifies and bounds it. */
116
+ export type FsSignalInput = Omit<FsSignal, 'id' | 'at' | 'paths' | 'pathCount'> & {
117
+ /** The affected paths; sorted, capped and counted by the sink. */
118
+ paths: readonly string[];
119
+ /** Overrides the clock, for a test that needs a fixed stamp. */
120
+ at?: number;
121
+ };
122
+ /**
123
+ * The signal sink: bounded, countable, subscribable.
124
+ *
125
+ * Deliberately has no I/O of its own. The agent owns the folder and the error
126
+ * log, so it owns the writing too — this stays a pure structure that a test can
127
+ * drive without a filesystem, which is also what keeps its own tests honest.
128
+ */
129
+ export declare class FsSignals {
130
+ private readonly _signals;
131
+ private readonly _totals;
132
+ private readonly _listeners;
133
+ private readonly _once;
134
+ /**
135
+ * Records one signal.
136
+ * @param input - What happened.
137
+ * @returns The signal as recorded, stamped and bounded.
138
+ */
139
+ add(input: FsSignalInput): FsSignal;
140
+ /**
141
+ * Records a signal at most once per agent, for a standing condition.
142
+ *
143
+ * A misconfiguration is true for the life of the process, so reporting it per
144
+ * event would bury everything else.
145
+ * @param key - What is being reported once.
146
+ * @param input - What happened.
147
+ * @returns The signal, or `undefined` if this key was already reported.
148
+ */
149
+ addOnce(key: string, input: FsSignalInput): FsSignal | undefined;
150
+ /** Every signal kept, oldest first. */
151
+ get all(): readonly FsSignal[];
152
+ /** Only the signals a person still has to act on. */
153
+ get needingAction(): readonly FsSignal[];
154
+ /**
155
+ * How many of each kind have ever been recorded, dropped ones included.
156
+ * @returns The counts, keyed by kind.
157
+ */
158
+ totals(): Readonly<Record<string, number>>;
159
+ /**
160
+ * Subscribes to signals as they happen.
161
+ * @param listener - Called once per signal.
162
+ * @returns Unsubscribes.
163
+ */
164
+ subscribe(listener: (signal: FsSignal) => void): () => void;
165
+ /**
166
+ * What to persist.
167
+ * @returns The log, ready to serialise.
168
+ */
169
+ persisted(): FsSignalLog;
170
+ /**
171
+ * Restores a persisted log, so a host that starts later still sees what
172
+ * happened while it was not running.
173
+ *
174
+ * Tolerant by construction: a log that cannot be understood is skipped
175
+ * rather than thrown, because a corrupt notification file must never stop a
176
+ * folder from syncing.
177
+ * @param raw - What was read from disk.
178
+ */
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;
200
+ /**
201
+ * Whether a restored entry is shaped like a signal.
202
+ *
203
+ * Only the fields something downstream reads without checking. A log written
204
+ * by a newer build may carry a `kind` this one has never heard of, and that
205
+ * is kept rather than dropped: an unknown kind is still a true record of
206
+ * something that happened, and dropping it would make a downgrade lose
207
+ * history.
208
+ * @param value - The entry.
209
+ * @returns Whether it can be kept.
210
+ */
211
+ private static _isSignal;
212
+ }
@@ -0,0 +1,102 @@
1
+ import { Db } from '@rljson/db';
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>>;
11
+ /**
12
+ * The stamp of every chain entry, as this node learned it.
13
+ *
14
+ * **A version's stamp is the stamp of the announcement that first carried it
15
+ * to the fleet.** A head arrives with a stamp; the entries below it that no
16
+ * earlier announcement carried — the edits a node made offline, say — reached
17
+ * the fleet with it, so they get it too. The walk stops at the first entry that
18
+ * already has a stamp. An entry keeps the first stamp it was given.
19
+ *
20
+ * A walk can stop short — at a row that cannot be read yet, or at the budget.
21
+ * The entry it stopped at stays OPEN: stamped, its ancestors not yet, and
22
+ * {@link settle} resumes it. Without that, everything below the gap stayed
23
+ * unstamped for good, because the next walk stops at the stamped entry above
24
+ * it, and every merge that needed one of those stamps deferred for ever.
25
+ *
26
+ * Kept in the route's own database, because a conflict can be about a version
27
+ * introduced long ago and its stamp has to outlive a restart.
28
+ */
29
+ export declare class FsStamps {
30
+ private readonly _db;
31
+ private readonly _treeKey;
32
+ private readonly _previousOf;
33
+ private readonly _byEntry;
34
+ /** Stamped entries whose ancestors have not been walked yet. */
35
+ private readonly _open;
36
+ /** The highest epoch heard, per domain. */
37
+ private readonly _maxEpoch;
38
+ constructor(_db: Db, _treeKey: string, _previousOf: (entry: string) => Promise<readonly string[] | undefined>);
39
+ /** The table the stamps are kept in. */
40
+ get table(): string;
41
+ /** How many walks stopped short and wait for {@link settle}. */
42
+ get open(): number;
43
+ /** Creates the table if absent, and loads what it holds. */
44
+ init(): Promise<void>;
45
+ /**
46
+ * The stamp an entry reached the fleet with.
47
+ * @param entry - The chain entry.
48
+ * @returns Its stamp, or `undefined` while nobody has told this node.
49
+ */
50
+ get(entry: string): RefStamp | undefined;
51
+ /**
52
+ * Records the stamp a head arrived with, for it and for every entry below it
53
+ * no earlier announcement carried.
54
+ * @param head - The announced head.
55
+ * @param stamp - The stamp it arrived with. A malformed one is ignored.
56
+ * @param maxWalk - How many rows to read; past it the walk stays open.
57
+ */
58
+ heard(head: string, stamp: unknown, maxWalk?: number): Promise<void>;
59
+ /**
60
+ * Resumes every walk that stopped short.
61
+ *
62
+ * Not part of {@link heard}: a row that cannot be read can cost a blocked
63
+ * read each time it is asked for, and an announcement arrives every few
64
+ * seconds. Only a merge that is missing a stamp calls this.
65
+ * @param maxWalk - How many rows to read; past it the walks stay open.
66
+ */
67
+ settle(maxWalk?: number): Promise<void>;
68
+ /**
69
+ * The highest epoch this node has heard in a domain — what a hub taking
70
+ * office here has to continue above.
71
+ * @param domain - The domain.
72
+ * @returns The epoch, or `0` when none was heard.
73
+ */
74
+ maxEpoch(domain: string): number;
75
+ /** The highest epoch heard in every domain this node has heard of. */
76
+ get epochs(): Readonly<Record<string, number>>;
77
+ /**
78
+ * Records an entry's stamp, and the epoch it carries.
79
+ * @param entry - The chain entry.
80
+ * @param stamp - Its stamp.
81
+ */
82
+ private _set;
83
+ /**
84
+ * Walks down from open entries, giving every unstamped entry it reaches the
85
+ * stamp it was reached with, and stores what changed.
86
+ *
87
+ * Earliest stamp first: an entry two announcements carried belongs to the
88
+ * earlier one, and a walk resumed late must not lose it to a later walk that
89
+ * happens to be fewer steps away.
90
+ * @param seeds - The open entries to walk from.
91
+ * @param changed - Entries stamped by the caller, to be stored too.
92
+ * @param maxWalk - How many rows to read.
93
+ */
94
+ private _walk;
95
+ /**
96
+ * Whether `a` was stamped before `b`.
97
+ * @param a - A stamped entry.
98
+ * @param b - Another.
99
+ * @returns `true` when `a`'s stamp is the earlier, ties broken on the entry.
100
+ */
101
+ private _before;
102
+ }
@@ -0,0 +1,2 @@
1
+ /** The version of the `@rljson/fs-agent` package. */
2
+ export declare const fsAgentVersion = "0.2.1";
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { FsAgent, REFUSED_DELETION_LOG_MAX, SYNC_ERROR_FILE, type FsAgentOptions, type RefusedDeletion, type RestoreOptions, type TimeoutConfig, } from './fs-agent.ts';
2
- export { ATOMIC_TMP_PREFIX, atomicTmpPath, atomicWriteFile, atomicWriteStream, } from './fs-atomic-write.ts';
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 { 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';
3
6
  export { compileIgnore, globToRegExp, type IgnoreMatcher, } from './fs-ignore.ts';
4
- export { antiEntropyDecision, DEFAULT_ANTI_ENTROPY, FsAntiEntropy, type AntiEntropyAction, type AntiEntropyDecision, type AntiEntropyDeps, type AntiEntropyOptions, type AntiEntropyStatus, type AntiEntropyView, type HubAnnouncement, type Reachability, } from './fs-anti-entropy.ts';
5
- export { BE, BG, BQ, BR, BUCKET_SYNC_PREFIXES, decodeEntries, decodeRoots, decodeWanted, encodeEntries, encodeRoots, encodeWanted, FsBucketSync, isBucketSync, type BucketSyncHost, } from './fs-bucket-sync.ts';
6
- export { BUCKET_COUNT, bucketOf, bucketRoots, differingBuckets, entriesInBuckets, reconcile, TOMBSTONE_BLOB, type BucketRoots, type ManifestEntry, type ReconcilePlan, } from './fs-manifest.ts';
7
- export { createFsChainTables, FS_EDIT_ACTION, FsEditChain, compareTimeId, planRemovals, type FsAppendOptions, type FsChainEntry, type FsEditData, type RemovalPlan, type RemovalQuestion, } from './fs-edit-chain.ts';
7
+ export type { AntiEntropyStatus, ReceiveOutcome, Relation, } from './fs-receive.ts';
8
+ export { createFsChainTables, FS_EDIT_ACTION, FsEditChain, type FsAppendOptions, type FsChainEntry, type FsEditData, } from './fs-edit-chain.ts';
8
9
  export { FsBlobAdapter, type BlobToFileOptions, type FileBlobMeta, type FileToBlobOptions, } from './fs-blob-adapter.ts';
9
10
  export { FsDbAdapter, type StoreFsTreeOptions } from './fs-db-adapter.ts';
10
- export { compareTips, conflictCopyName, decideWinner, DIR_MARKER, findCommonAncestor, formatConflictTimestamp, FsConflictResolver, fsTreeToContentMap, threeWayMerge, type BranchTip, type ConflictCopy, type ConflictResolverDeps, type ContentMap, type MergePlan, } from './fs-conflict-resolver.ts';
11
11
  export { FsScanner, type FsChange, type FsChangeCallback, type FsChangeType, type FsNodeMeta, type FsScanOptions, type FsTree, } from './fs-scanner.ts';
12
12
  export { runClientServerSetup, type ClientServerSetupOptions, type ClientServerSetupResult, } from './client-server/client-server-setup.ts';