@rljson/fs-agent 0.0.85 → 0.2.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.
@@ -68,6 +68,14 @@ export type FsChangeCallback = (change: FsChange) => void | Promise<void>;
68
68
  /**
69
69
  * Options for scanning
70
70
  */
71
+ /**
72
+ * Default for {@link FsScanOptions.settleMs}.
73
+ *
74
+ * Matched to the agent's debounce: below it a scan can still catch a copy
75
+ * mid-flight, and above it every new file pays latency for a hazard that is
76
+ * already covered.
77
+ */
78
+ export declare const DEFAULT_SETTLE_MS = 100;
71
79
  export interface FsScanOptions {
72
80
  /** Patterns to ignore (glob patterns) */
73
81
  ignore?: string[];
@@ -88,6 +96,26 @@ export interface FsScanOptions {
88
96
  * after a restart. Omit to disable (default: full read+hash every scan).
89
97
  */
90
98
  scanCachePath?: string;
99
+ /**
100
+ * How long to wait before coming back for a file that was still being
101
+ * written.
102
+ *
103
+ * A copy takes seconds, and for those seconds the file on disk is a PREFIX
104
+ * of the real one. Reading it there produces a blob of the prefix, and a
105
+ * blob is what gets announced — so the fleet is told a truncated file is the
106
+ * complete state, and on every peer it then IS the complete state.
107
+ *
108
+ * Measured before this existed: a 2 MB file written in 8 slices was hashed
109
+ * at 262 144 bytes, matching the field report exactly — *"eine große Datei
110
+ * wird 0,3 Sekunden nach dem ersten Byte gelesen und als vollständiger Stand
111
+ * an alle verteilt"*.
112
+ *
113
+ * The cost is latency: a new file waits this long before it can propagate.
114
+ * Kept at the same order as the agent's debounce so it adds nothing a user
115
+ * would notice, and a deferral schedules its own follow-up scan rather than
116
+ * waiting for the five-second safety rescan.
117
+ */
118
+ settleMs?: number;
91
119
  }
92
120
  /**
93
121
  * Scans and watches file system changes, extracting RLJSON tree structure
@@ -98,6 +126,15 @@ export declare class FsScanner {
98
126
  private _watcher;
99
127
  private _changeCallbacks;
100
128
  private _options;
129
+ /**
130
+ * The ignore list, compiled once.
131
+ *
132
+ * Compiled rather than re-read per entry because a scan of a production
133
+ * catalogue asks this question once per file, and a glob is a regular
134
+ * expression that should be built once. `fs-ignore.ts` carries the
135
+ * compatibility rule that keeps every prefix pattern working.
136
+ */
137
+ private readonly _ignoreMatcher;
101
138
  private _bs;
102
139
  private _paused;
103
140
  private _missedChangesDuringPause;
@@ -111,6 +148,33 @@ export declare class FsScanner {
111
148
  private _stopRequested;
112
149
  /** Path→content cache backing {@link FsScanOptions.scanCachePath} (unused when unset). */
113
150
  private _scanCachePath?;
151
+ /**
152
+ * Paths this scan refused to read because they were still being written.
153
+ *
154
+ * Counted so {@link scan} knows to come back, and reported so a folder that
155
+ * never settles is diagnosable rather than mysteriously stale.
156
+ */
157
+ private _unsettledDuringScan;
158
+ /**
159
+ * When the scan now running began.
160
+ *
161
+ * A file whose timestamp is newer than this is still being written: the
162
+ * bytes moved while this scan was in progress. See the gate in
163
+ * {@link _scanDirectory}.
164
+ */
165
+ private _scanStartedAt;
166
+ /** When the pass that produced {@link tree} began; 0 before the first. */
167
+ private _treeStartedAt;
168
+ /**
169
+ * Large files whose size this scanner has seen but not yet seen settle.
170
+ *
171
+ * path → the size observed last time. A file leaves the map the scan after
172
+ * its size stops changing, which is when it is finally read. Bounded by the
173
+ * number of large files being written at once, which is a handful.
174
+ */
175
+ private readonly _growing;
176
+ /** Pending follow-up scan for {@link _unsettledDuringScan}. */
177
+ private _settleTimer;
114
178
  /** Last-scan cache (loaded from disk); consulted to skip re-read/re-hash. */
115
179
  private _blobCache;
116
180
  /** Cache rebuilt during the CURRENT scan; becomes `_blobCache` at the end (self-pruning). */
@@ -121,10 +185,48 @@ export declare class FsScanner {
121
185
  private _vanishedDuringScan;
122
186
  /** The scan pass running right now, if any. See {@link _scanAfterNow}. */
123
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;
124
193
  /** The single follow-up pass everyone who arrived mid-scan is waiting on. */
125
194
  private _pendingScan;
126
195
  constructor(rootPath: string, options?: FsScanOptions);
127
196
  get tree(): FsTree | null;
197
+ /**
198
+ * When the pass that produced {@link tree} began — 0 before the first. A
199
+ * caller that wrote to the folder tells from it whether that pass could have
200
+ * read its write half-done.
201
+ * @returns Epoch ms.
202
+ */
203
+ get treeStartedAt(): number;
204
+ /**
205
+ * The folder as it is now: a scan guaranteed to have STARTED after this
206
+ * call, sharing one pass with anyone else asking meanwhile. What a caller
207
+ * that acts on the folder must use — {@link tree} is the last pass, which
208
+ * may have run while something was still writing.
209
+ * @returns The tree.
210
+ */
211
+ scanFresh(): Promise<FsTree>;
212
+ /**
213
+ * Tells the scanner a file was just written whole by this process, with the
214
+ * given content. The next scan takes it as written — never as a copy still
215
+ * in progress, whatever its timestamp says. A file that changed since is
216
+ * read as usual.
217
+ *
218
+ * Without it, a write in the second half of the millisecond a scan starts
219
+ * in reads as "changed during this scan" — Node rounds an mtime to the
220
+ * nearest millisecond, the scan's start is truncated — and the scan reused
221
+ * the version BEFORE the write: measured as a receiver announcing the
222
+ * previous save of a file it had just applied, which reverted the writer's
223
+ * own copy.
224
+ * @param relativePath - The file, `/`-separated.
225
+ * @param blobId - Its content.
226
+ * @param size - Its size as written.
227
+ * @param mtime - Its mtime as written, ms.
228
+ */
229
+ noteWrite(relativePath: string, blobId: string, size: number, mtime: number): void;
128
230
  /** Whether a watcher is currently installed. */
129
231
  get isWatching(): boolean;
130
232
  get rootPath(): string;
@@ -146,12 +248,12 @@ export declare class FsScanner {
146
248
  *
147
249
  * `fs.watch` in recursive mode reports a path RELATIVE TO THE ROOT
148
250
  * (`sub/dir/.fsagent-tmp-abc`), while the ignore patterns are basenames.
149
- * {@link _shouldIgnore} tests `startsWith`, so a nested match never fired:
251
+ * The matcher tested a basename only, so a nested match never fired:
150
252
  * every atomic write the agent itself makes during a restore came back as a
151
253
  * change event, each event triggered a scan, and the debounce that batches a
152
254
  * push was reset before it could fire.
153
255
  *
154
- * Measured on the customer's folder: after a 3 642-file restore the watcher
256
+ * Measured on a large production folder: after a 3 642-file restore the watcher
155
257
  * reported the SAME newly added file nine times and the agent never emitted a
156
258
  * ref for it — `[fs] added: …/probe-….txt` nine times, no `sync:out`. The
157
259
  * file did not fail to arrive; it was never sent.
@@ -159,10 +261,12 @@ export declare class FsScanner {
159
261
  * Every segment is tested, because the pattern may match a directory as
160
262
  * easily as a file.
161
263
  * @param relativePath - Path as the watcher reports it.
162
- * @returns True when any segment matches an ignore pattern.
264
+ * @param isDirectory - Whether the path is a directory, when the caller
265
+ * knows. A directory-only pattern (`build/`) needs it; the watcher cannot
266
+ * say, and not knowing never widens what is ignored.
267
+ * @returns True when the ignore list covers this path.
163
268
  */
164
269
  private _shouldIgnorePath;
165
- private _shouldIgnore;
166
270
  watch(): Promise<void>;
167
271
  /**
168
272
  * One safety-rescan pass: rescans the tree and, if its content differs from
@@ -170,6 +274,38 @@ export declare class FsScanner {
170
274
  * notification so syncToDb reconciles the drift. Paused/stopped scanners and
171
275
  * scan failures are no-ops.
172
276
  */
277
+ /**
278
+ * Re-reads the folder once a file this scan would not read has settled.
279
+ *
280
+ * Through the coalescer, like the safety rescan, so a settle landing inside
281
+ * a burst does not add a whole extra pass. Notifies unconditionally: the
282
+ * caller already knows something was deferred, and the point is to get the
283
+ * file out now rather than on the five-second rescan.
284
+ * @param path - The path that was deferred, for the change event.
285
+ */
286
+ /**
287
+ * Carries a file's PREVIOUS node into the scan being built, because the file
288
+ * on disk right now is still being written.
289
+ *
290
+ * A path simply left out of a tree reads as a DELETION to every peer that
291
+ * holds it, so a user saving over a document would have it deleted
292
+ * everywhere. Reusing the last node says the truthful thing instead: as far
293
+ * as the network is concerned this change has not happened yet.
294
+ *
295
+ * A file nobody has ever seen has no previous node and IS left out, which is
296
+ * correct — it cannot be a deletion of something no peer holds.
297
+ *
298
+ * The node must go into `trees` as well as into the parent's children. It is
299
+ * the kind of thing that looks redundant and is not: leaving it out gave the
300
+ * root a child hash with no node behind it, and the whole folder came out
301
+ * empty.
302
+ * @param relativePath - The deferred path.
303
+ * @param trees - The node map this scan is building.
304
+ * @param childTrees - The parent's child nodes.
305
+ * @param childRefs - The parent's child hashes.
306
+ */
307
+ private _reuse;
308
+ private _rescanAfterSettle;
173
309
  private _runSafetyRescan;
174
310
  /**
175
311
  * Path+blobId content fingerprint used by the safety rescan to detect drift
@@ -184,6 +320,17 @@ export declare class FsScanner {
184
320
  * @param err - The caught value
185
321
  * @returns A message string
186
322
  */
323
+ /**
324
+ * What a watcher error does off Windows: nothing that could crash.
325
+ *
326
+ * An FSWatcher with no `'error'` listener throws what it emits, and Node's
327
+ * recursive watcher on Linux emits ENOENT when a directory is deleted while
328
+ * it walks it — the agent died of a user deleting a nested folder. There is
329
+ * nothing to reinstall: the watcher stays, and the safety rescan picks up
330
+ * whatever it missed. Anything other than a vanished directory is said.
331
+ * @param err - The error the watcher emitted.
332
+ */
333
+ private static _onWatchError;
187
334
  private static _errMessage;
188
335
  /**
189
336
  * Whether a caught value is a "no longer there" filesystem error.
@@ -209,12 +356,12 @@ export declare class FsScanner {
209
356
  * callback, so those scans all run AT ONCE. Copying 1 200 tiny files into a
210
357
  * watched folder took 1 200 concurrent full scans: the CPU sat 82% idle
211
358
  * waiting on the filesystem, RSS climbed from 263 MB to 785 MB, and after two
212
- * minutes the peer had received nothing. On the customer's 3 702-file folder
359
+ * minutes the peer had received nothing. On a 3 702-file folder
213
360
  * the same burst wedged the client outright.
214
361
  *
215
362
  * Started-after is the part that cannot be traded away. Joining a scan that
216
363
  * began BEFORE the event would let a push carry a tree that predates the file
217
- * that triggered it — which is precisely the partial trees the lab saw
364
+ * that triggered it — which is precisely the partial trees a real fleet saw
218
365
  * advertised: 64 nodes, then 103, then 204, each a stale snapshot of a folder
219
366
  * that already held twelve hundred files. So a caller either starts a scan
220
367
  * now, or waits for the one that begins when the current pass ends. A burst
@@ -235,6 +382,22 @@ export declare class FsScanner {
235
382
  */
236
383
  private _pauseLooksStuck;
237
384
  private _notifyChange;
385
+ /**
386
+ * What the last completed scan saw on disk for one path.
387
+ *
388
+ * The agent asks this to decide whether a restore may skip writing a file:
389
+ * a matching blobId means the bytes are already right, and the recorded
390
+ * size and mtime are what a `stat` is checked against. Reading it from here
391
+ * rather than from the tree is deliberate — mtime is no longer part of a
392
+ * tree node, precisely so refs do not depend on it.
393
+ * @param relativePath - Path relative to the scan root.
394
+ * @returns What the scan recorded, or `undefined` if it saw no such file.
395
+ */
396
+ knownFile(relativePath: string): {
397
+ mtime: number;
398
+ size: number;
399
+ blobId: string;
400
+ } | undefined;
238
401
  onChange(callback: FsChangeCallback): void;
239
402
  offChange(callback: FsChangeCallback): void;
240
403
  stopWatch(): void;
@@ -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,169 @@
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
+ /** What happened. */
41
+ kind: FsSignalKind;
42
+ /** When, epoch ms. */
43
+ at: number;
44
+ /**
45
+ * The paths it affected, sorted.
46
+ *
47
+ * Capped at {@link SIGNAL_PATHS_MAX} with `pathCount` carrying the true
48
+ * number, because a mass deletion names thousands and a signal has to stay
49
+ * small enough to keep.
50
+ */
51
+ paths: readonly string[];
52
+ /** How many paths were affected, which may exceed `paths.length`. */
53
+ pathCount: number;
54
+ /** Whether a person has to do something. */
55
+ action: FsSignalAction;
56
+ /** How the outcome was chosen, where something chose it. */
57
+ decidedBy?: FsSignalDecidedBy;
58
+ /** Where the version that lost the path was kept, when one was. */
59
+ copyPath?: string;
60
+ /** The edit this belongs to, when it belongs to one. */
61
+ timeId?: string;
62
+ /** One sentence for a person. Never a stack trace. */
63
+ detail?: string;
64
+ }
65
+ /** How many signals {@link FsSignals.all} keeps. */
66
+ export declare const SIGNAL_LOG_MAX = 200;
67
+ /** How many paths one signal names before it only counts them. */
68
+ export declare const SIGNAL_PATHS_MAX = 20;
69
+ /**
70
+ * How many distinct {@link FsSignals.addOnce} keys are remembered.
71
+ *
72
+ * Bounded because a key can be derived from live state — the pair of refs a
73
+ * divergence is between, say — and a churning fleet produces new pairs
74
+ * indefinitely. Dropping the oldest means such a signal may be reported again
75
+ * later, which is noise rather than a falsehood; an unbounded set would be a
76
+ * leak, and this package has shipped two of those.
77
+ */
78
+ export declare const SIGNAL_ONCE_MAX = 500;
79
+ /** The file {@link FsSignals} persists to, inside the synced folder. */
80
+ export declare const SIGNAL_LOG_FILE = ".fsagent-signals.json";
81
+ /** What {@link FsSignals.persisted} writes and reads. */
82
+ export interface FsSignalLog {
83
+ /** The newest signals, oldest first, at most {@link SIGNAL_LOG_MAX}. */
84
+ signals: FsSignal[];
85
+ /**
86
+ * How many of each kind have EVER been recorded, including dropped ones.
87
+ *
88
+ * Survives the cap and survives a restart, so "and 1 240 more" is answerable.
89
+ */
90
+ totals: Record<string, number>;
91
+ }
92
+ /** What a signal says before the sink stamps and bounds it. */
93
+ export type FsSignalInput = Omit<FsSignal, 'at' | 'paths' | 'pathCount'> & {
94
+ /** The affected paths; sorted, capped and counted by the sink. */
95
+ paths: readonly string[];
96
+ /** Overrides the clock, for a test that needs a fixed stamp. */
97
+ at?: number;
98
+ };
99
+ /**
100
+ * The signal sink: bounded, countable, subscribable.
101
+ *
102
+ * Deliberately has no I/O of its own. The agent owns the folder and the error
103
+ * log, so it owns the writing too — this stays a pure structure that a test can
104
+ * drive without a filesystem, which is also what keeps its own tests honest.
105
+ */
106
+ export declare class FsSignals {
107
+ private readonly _signals;
108
+ private readonly _totals;
109
+ private readonly _listeners;
110
+ private readonly _once;
111
+ /**
112
+ * Records one signal.
113
+ * @param input - What happened.
114
+ * @returns The signal as recorded, stamped and bounded.
115
+ */
116
+ add(input: FsSignalInput): FsSignal;
117
+ /**
118
+ * Records a signal at most once per agent, for a standing condition.
119
+ *
120
+ * A misconfiguration is true for the life of the process, so reporting it per
121
+ * event would bury everything else.
122
+ * @param key - What is being reported once.
123
+ * @param input - What happened.
124
+ * @returns The signal, or `undefined` if this key was already reported.
125
+ */
126
+ addOnce(key: string, input: FsSignalInput): FsSignal | undefined;
127
+ /** Every signal kept, oldest first. */
128
+ get all(): readonly FsSignal[];
129
+ /** Only the signals a person still has to act on. */
130
+ get needingAction(): readonly FsSignal[];
131
+ /**
132
+ * How many of each kind have ever been recorded, dropped ones included.
133
+ * @returns The counts, keyed by kind.
134
+ */
135
+ totals(): Readonly<Record<string, number>>;
136
+ /**
137
+ * Subscribes to signals as they happen.
138
+ * @param listener - Called once per signal.
139
+ * @returns Unsubscribes.
140
+ */
141
+ subscribe(listener: (signal: FsSignal) => void): () => void;
142
+ /**
143
+ * What to persist.
144
+ * @returns The log, ready to serialise.
145
+ */
146
+ persisted(): FsSignalLog;
147
+ /**
148
+ * Restores a persisted log, so a host that starts later still sees what
149
+ * happened while it was not running.
150
+ *
151
+ * Tolerant by construction: a log that cannot be understood is skipped
152
+ * rather than thrown, because a corrupt notification file must never stop a
153
+ * folder from syncing.
154
+ * @param raw - What was read from disk.
155
+ */
156
+ restore(raw: unknown): void;
157
+ /**
158
+ * Whether a restored entry is shaped like a signal.
159
+ *
160
+ * Only the fields something downstream reads without checking. A log written
161
+ * by a newer build may carry a `kind` this one has never heard of, and that
162
+ * is kept rather than dropped: an unknown kind is still a true record of
163
+ * something that happened, and dropping it would make a downgrade lose
164
+ * history.
165
+ * @param value - The entry.
166
+ * @returns Whether it can be kept.
167
+ */
168
+ private static _isSignal;
169
+ }
@@ -0,0 +1,94 @@
1
+ import { Db } from '@rljson/db';
2
+ import { RefStamp } from '@rljson/rljson';
3
+ /**
4
+ * The stamp of every chain entry, as this node learned it.
5
+ *
6
+ * **A version's stamp is the stamp of the announcement that first carried it
7
+ * to the fleet.** A head arrives with a stamp; the entries below it that no
8
+ * earlier announcement carried — the edits a node made offline, say — reached
9
+ * the fleet with it, so they get it too. The walk stops at the first entry that
10
+ * already has a stamp. An entry keeps the first stamp it was given.
11
+ *
12
+ * A walk can stop short — at a row that cannot be read yet, or at the budget.
13
+ * The entry it stopped at stays OPEN: stamped, its ancestors not yet, and
14
+ * {@link settle} resumes it. Without that, everything below the gap stayed
15
+ * unstamped for good, because the next walk stops at the stamped entry above
16
+ * it, and every merge that needed one of those stamps deferred for ever.
17
+ *
18
+ * Kept in the route's own database, because a conflict can be about a version
19
+ * introduced long ago and its stamp has to outlive a restart.
20
+ */
21
+ export declare class FsStamps {
22
+ private readonly _db;
23
+ private readonly _treeKey;
24
+ private readonly _previousOf;
25
+ private readonly _byEntry;
26
+ /** Stamped entries whose ancestors have not been walked yet. */
27
+ private readonly _open;
28
+ /** The highest epoch heard, per domain. */
29
+ private readonly _maxEpoch;
30
+ constructor(_db: Db, _treeKey: string, _previousOf: (entry: string) => Promise<readonly string[] | undefined>);
31
+ /** The table the stamps are kept in. */
32
+ get table(): string;
33
+ /** How many walks stopped short and wait for {@link settle}. */
34
+ get open(): number;
35
+ /** Creates the table if absent, and loads what it holds. */
36
+ init(): Promise<void>;
37
+ /**
38
+ * The stamp an entry reached the fleet with.
39
+ * @param entry - The chain entry.
40
+ * @returns Its stamp, or `undefined` while nobody has told this node.
41
+ */
42
+ get(entry: string): RefStamp | undefined;
43
+ /**
44
+ * Records the stamp a head arrived with, for it and for every entry below it
45
+ * no earlier announcement carried.
46
+ * @param head - The announced head.
47
+ * @param stamp - The stamp it arrived with. A malformed one is ignored.
48
+ * @param maxWalk - How many rows to read; past it the walk stays open.
49
+ */
50
+ heard(head: string, stamp: unknown, maxWalk?: number): Promise<void>;
51
+ /**
52
+ * Resumes every walk that stopped short.
53
+ *
54
+ * Not part of {@link heard}: a row that cannot be read can cost a blocked
55
+ * read each time it is asked for, and an announcement arrives every few
56
+ * seconds. Only a merge that is missing a stamp calls this.
57
+ * @param maxWalk - How many rows to read; past it the walks stay open.
58
+ */
59
+ settle(maxWalk?: number): Promise<void>;
60
+ /**
61
+ * The highest epoch this node has heard in a domain — what a hub taking
62
+ * office here has to continue above.
63
+ * @param domain - The domain.
64
+ * @returns The epoch, or `0` when none was heard.
65
+ */
66
+ maxEpoch(domain: string): number;
67
+ /** The highest epoch heard in every domain this node has heard of. */
68
+ get epochs(): Readonly<Record<string, number>>;
69
+ /**
70
+ * Records an entry's stamp, and the epoch it carries.
71
+ * @param entry - The chain entry.
72
+ * @param stamp - Its stamp.
73
+ */
74
+ private _set;
75
+ /**
76
+ * Walks down from open entries, giving every unstamped entry it reaches the
77
+ * stamp it was reached with, and stores what changed.
78
+ *
79
+ * Earliest stamp first: an entry two announcements carried belongs to the
80
+ * earlier one, and a walk resumed late must not lose it to a later walk that
81
+ * happens to be fewer steps away.
82
+ * @param seeds - The open entries to walk from.
83
+ * @param changed - Entries stamped by the caller, to be stored too.
84
+ * @param maxWalk - How many rows to read.
85
+ */
86
+ private _walk;
87
+ /**
88
+ * Whether `a` was stamped before `b`.
89
+ * @param a - A stamped entry.
90
+ * @param b - Another.
91
+ * @returns `true` when `a`'s stamp is the earlier, ties broken on the entry.
92
+ */
93
+ private _before;
94
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
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';
1
2
  export { FsAgent, SYNC_ERROR_FILE, type FsAgentOptions, type RestoreOptions, type TimeoutConfig, } from './fs-agent.ts';
2
- export { antiEntropyDecision, DEFAULT_ANTI_ENTROPY, FsAntiEntropy, type AntiEntropyAction, type AntiEntropyDecision, type AntiEntropyDeps, type AntiEntropyOptions, type AntiEntropyStatus, type AntiEntropyView, type HubAnnouncement, } from './fs-anti-entropy.ts';
3
+ export { ATOMIC_TMP_PREFIX, atomicTmpPath, atomicWriteFile, atomicWriteStream, } from './fs-atomic-write.ts';
4
+ export { compileIgnore, globToRegExp, type IgnoreMatcher, } from './fs-ignore.ts';
5
+ export type { AntiEntropyStatus } from './fs-receive.ts';
6
+ export { createFsChainTables, FS_EDIT_ACTION, FsEditChain, type FsAppendOptions, type FsChainEntry, type FsEditData, } from './fs-edit-chain.ts';
3
7
  export { FsBlobAdapter, type BlobToFileOptions, type FileBlobMeta, type FileToBlobOptions, } from './fs-blob-adapter.ts';
4
8
  export { FsDbAdapter, type StoreFsTreeOptions } from './fs-db-adapter.ts';
5
- 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';
6
9
  export { FsScanner, type FsChange, type FsChangeCallback, type FsChangeType, type FsNodeMeta, type FsScanOptions, type FsTree, } from './fs-scanner.ts';
7
10
  export { runClientServerSetup, type ClientServerSetupOptions, type ClientServerSetupResult, } from './client-server/client-server-setup.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/fs-agent",
3
- "version": "0.0.85",
3
+ "version": "0.2.0",
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",
@@ -28,7 +28,7 @@
28
28
  "updateGoldens": "cross-env UPDATE_GOLDENS=true pnpm test"
29
29
  },
30
30
  "devDependencies": {
31
- "@rljson/server": "0.0.71",
31
+ "@rljson/server": "0.0.76",
32
32
  "@types/node": "^25.3.1",
33
33
  "@typescript-eslint/eslint-plugin": "^8.56.1",
34
34
  "@typescript-eslint/parser": "^8.56.1",
@@ -50,12 +50,12 @@
50
50
  "vitest-dom": "^0.1.1"
51
51
  },
52
52
  "dependencies": {
53
- "@rljson/bs": "0.0.27",
54
- "@rljson/db": "0.0.48",
53
+ "@rljson/bs": "0.0.29",
54
+ "@rljson/db": "0.1.1",
55
55
  "@rljson/hash": "0.0.19",
56
- "@rljson/io": "0.0.80",
56
+ "@rljson/io": "0.0.85",
57
57
  "@rljson/json": "0.0.23",
58
- "@rljson/rljson": "0.0.83",
58
+ "@rljson/rljson": "0.0.86",
59
59
  "socket.io": "^4.8.3",
60
60
  "socket.io-client": "^4.8.3"
61
61
  },
@@ -64,13 +64,13 @@
64
64
  "esbuild"
65
65
  ],
66
66
  "overrides": {
67
- "@rljson/bs": "0.0.27",
68
- "@rljson/db": "0.0.48",
67
+ "@rljson/bs": "0.0.29",
68
+ "@rljson/db": "0.1.1",
69
69
  "@rljson/hash": "0.0.19",
70
- "@rljson/io": "0.0.80",
70
+ "@rljson/io": "0.0.85",
71
71
  "@rljson/json": "0.0.23",
72
- "@rljson/rljson": "0.0.83",
73
- "@rljson/server": "0.0.71"
72
+ "@rljson/rljson": "0.0.86",
73
+ "@rljson/server": "0.0.76"
74
74
  }
75
75
  },
76
76
  "packageManager": "pnpm@10.11.0"