@johnhenry/sitefile 0.0.8 → 0.0.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.9 (2026-12-01)
4
+
5
+ - **Buckets: mutable named file trees in the store, served by name and snapshotted to images** (johnhenry/sitefile#340, PR #351, commit 6a6102a0):
6
+ `sitefile bucket create|ls|rm <name>`, `bucket put|get|rm <name>/<path>`, `bucket ls <name>[/prefix]`,
7
+ `bucket snapshot <name> -t <tag>` (an image of the bucket's current files: the image `build -t` makes from a recipe
8
+ that copies them, same ID) and `bucket restore <tag> <name>`. A bucket is plain files under
9
+ `$SITEFILE_HOME/buckets/<name>/` with its metadata beside the tree; `sitefile serve bucket:<name>[/prefix]` serves it
10
+ (also in a servers file, as `source: bucket:docs`, and with `-d`) through the site handler, so `_redirects`,
11
+ `_headers` and every serve option work as for a folder, and **follows changes** (a request after a put sees it within
12
+ 250 ms; `--reload`/`--watch` also reload open pages). Files are written by temp file and rename under the store lock;
13
+ `put --batch` and `restore --batch` publish a set of changes with one rename. Bucket names are lowercase and one path
14
+ segment; paths refuse `..`, absolute and backslash paths, NUL, non-portable names and case collisions; a bucket never
15
+ follows a symbolic link nor reads a hard-linked file; `restore` and a directory `put` never replace different content
16
+ without `--overwrite`; `put` from stdin is limited (`--max-bytes`, default 256 MiB); `rm` of a bucket that holds files
17
+ or is served needs `-f`. `bucket snapshot` leaves hidden files out by default (an image serves every file it holds; `--include-hidden` opts in), a `--batch` swap is journaled (a data-only journal, fsynced before the first rename) and recovered from the directory state, journal or not, so neither a crash nor a power cut loses the old tree (and `bucket rm` removes what could bring a bucket back before the bucket, a sweep never takes a staged tree a journal names, a failed flush stops the swap before its first rename), a read never writes when the bucket is intact, every read of a file (the staged copy included) goes through one guarded no-follow, non-blocking, size-bounded open, every conflict of `restore` and `put <dir>` (empty directories included) is found before the first write, one planted link marks only its own bucket in `bucket ls`, a reload reads only the files that changed, and `--max-bytes` caps what `serve`, `snapshot` and `restore` hold in memory. an undeletable scratch leftover is warned about once and never blocks a write, `bucket ls` reports a broken swap entry as its own problem, `bucket rm` warns before removing, says "IS removed" on a late failure and unlinks a planted link, and a staged file is flushed before it is made read-only. `cache du` lists the `buckets` (never evictable). Both implementations, with conformance
18
+ cases `ok-bucket` and `err-bucket-*`, `examples/buckets/`, and the decisions in docs/CLI.md, "Buckets". The
19
+ conformance step cases gained `stdin`, `scrub` and `expect`.
20
+
21
+ - Fix: `serve -d --watch <context>` reported itself ready, and answered requests with 404 from an empty tree, while its first build was still running (seen once in CI as conformance `watch/detached-build` step 1: TypeScript 404, Rust 200). The detached worker now builds first and starts listening, and records `ready`, only when the first build has finished (a failed first build still counts: the server then shows the error, as before), so `serve -d` returns when the site is there. Until then nothing is bound, so a connection is refused rather than answered. The wait for a build context is up to 120 seconds instead of 15. Both implementations (`src/cli/serve-worker.ts`, `rust/src/cli/servers.rs`), each with a test that holds the first build back on a named pipe and asserts nothing is answered meanwhile (johnhenry/sitefile#354).
22
+
3
23
  ## 0.0.8 (2026-12-01)
4
24
 
5
25
  - Fix: on Windows, a plugin or tool that starts Node exited with code 134 (`Assertion failed: ncrypto::CSPRNG(nullptr, 0)`) on Node 26.14.0, because the scrubbed environment had no `SystemRoot`. On Windows only, the environment of a JavaScript plugin's Node process (and its `--version` check) and of a `TOOL` now also holds `SystemRoot`, copied from the build's environment (nothing is added if it has none); on other platforms the environment is unchanged, and no other variable is passed on. Both implementations (`src/plugins/env.ts`, `rust/src/plugins/env.rs`), with unit tests that run the Windows case on any system (johnhenry/sitefile#350).
package/README.md CHANGED
@@ -223,7 +223,8 @@ sitefile build [context] -t name[:tag] # also store the build as an image
223
223
  sitefile images | image inspect|diff|prune | tag | rmi | save
224
224
  sitefile cache info | cache prune [--older-than days] # TRANSFORM result cache
225
225
  sitefile cache du # cache sizes; SITEFILE_CACHE_MAX bounds them (default 1G)
226
- sitefile serve [-d] [--name n] [-p [host:]port] [--spa] <image|./dir|site.zip>
226
+ sitefile serve [-d] [--name n] [-p [host:]port] [--spa] <image|./dir|site.zip|bucket:name>
227
+ sitefile bucket create|ls|rm <name> | put|get|rm <name>/<path> | snapshot <name> -t <tag> | restore <tag> <name> # mutable named file trees
227
228
  sitefile serve --watch [-p [host:]port] [--spa] [context] # build in memory, serve, live reload
228
229
  sitefile servers [-a] | server stop|rm [-f]|restart|logs [-f] <name>
229
230
  sitefile up | down | ps [-f sitefile.servers.yaml] # several servers from one file, like docker compose
@@ -306,6 +307,11 @@ sitefile serve -d --name site -p 8080 hello:1 # serve it, in the background
306
307
  sitefile servers; sitefile server logs site; sitefile server stop site; sitefile server rm site
307
308
  ```
308
309
 
310
+ A **bucket** is the mutable counterpart: a named tree of files in the same store, where files are put and changed
311
+ (`sitefile bucket create site; sitefile bucket put site ./dist; sitefile serve bucket:site`). A server on a bucket
312
+ follows its changes, and `sitefile bucket snapshot site -t site:1` writes an image of its current files, the image
313
+ `build` would make from a recipe that copies them. See [docs/CLI.md](docs/CLI.md#buckets).
314
+
309
315
  `serve` serves GET/HEAD only on `127.0.0.1` (never `0.0.0.0` unless you ask for it in `-p`), with ETags,
310
316
  correct MIME types and no directory listings; it serves `/404.html` for missing paths, `/about` from
311
317
  `/about.html`, and honours the site's `_redirects` and `_headers` (exact paths and `/*` splats). `EXPORT / AS oci` (or `build -o site.oci.tar`) writes the
@@ -0,0 +1,22 @@
1
+ import type { ServerState } from './servers.js';
2
+ import type { Store } from './store.js';
3
+ /** How often a server on a bucket looks for changes. */
4
+ export declare const BUCKET_POLL_MS = 250;
5
+ /**
6
+ * Keep a server on `bucket:<name>[/prefix]` current. Every {@link BUCKET_POLL_MS} the bucket directory is
7
+ * compared with what was last read (size, mtime, ctime and inode of every entry; links are never followed): the
8
+ * poll only `lstat`s, so its cost is proportional to the number of entries, never to their size. On a change
9
+ * `reload` runs (it reads only the files whose stamp changed, see `BucketReadCache`), so a request made after a put
10
+ * sees the new files within that interval. A reload that fails (a symbolic link planted in the bucket, the bucket
11
+ * removed, a file gone mid-read) is reported once through `onError` and the last good copy stays; it is tried again
12
+ * on the next change and after a second. Returns a function that stops it.
13
+ * Twin: `follow_bucket` in rust/src/bucket.rs.
14
+ */
15
+ export declare function followBucket(store: Store, source: Extract<ServerState['source'], {
16
+ kind: 'bucket';
17
+ }>, o: {
18
+ readonly reload: () => Promise<void>;
19
+ readonly onError: (e: unknown) => void;
20
+ readonly pollMs?: number;
21
+ readonly retryMs?: number;
22
+ }): () => void;
@@ -0,0 +1,65 @@
1
+ import path from 'node:path';
2
+ import { Buckets } from './bucket.js';
3
+ import { SitefileError } from './errors.js';
4
+ import { pollSnapshot } from './watch.js';
5
+ /** How often a server on a bucket looks for changes. */
6
+ export const BUCKET_POLL_MS = 250;
7
+ /**
8
+ * Keep a server on `bucket:<name>[/prefix]` current. Every {@link BUCKET_POLL_MS} the bucket directory is
9
+ * compared with what was last read (size, mtime, ctime and inode of every entry; links are never followed): the
10
+ * poll only `lstat`s, so its cost is proportional to the number of entries, never to their size. On a change
11
+ * `reload` runs (it reads only the files whose stamp changed, see `BucketReadCache`), so a request made after a put
12
+ * sees the new files within that interval. A reload that fails (a symbolic link planted in the bucket, the bucket
13
+ * removed, a file gone mid-read) is reported once through `onError` and the last good copy stays; it is tried again
14
+ * on the next change and after a second. Returns a function that stops it.
15
+ * Twin: `follow_bucket` in rust/src/bucket.rs.
16
+ */
17
+ export function followBucket(store, source, o) {
18
+ const dir = path.join(Buckets.open(store).root, source.name);
19
+ let stopped = false;
20
+ let timer;
21
+ let last;
22
+ let lastError = '';
23
+ let failedAt;
24
+ const stamp = async () => {
25
+ const snap = await pollSnapshot({ dirs: [dir], files: [dir] });
26
+ return [...snap.entries()].sort(([a], [b]) => (a < b ? -1 : 1)).map(([p, s]) => `${p}\0${s}`).join('\n');
27
+ };
28
+ const tick = async () => {
29
+ try {
30
+ const now = await stamp();
31
+ if (stopped)
32
+ return;
33
+ // The first look reloads too: the server read the bucket before this stamp was taken, and a change in
34
+ // between must not be missed (`reload` keeps the tree it has when nothing differs).
35
+ // A reload that failed is tried again a second later even if nothing changed since: the failure may have been
36
+ // a file that vanished mid-read (a change made while we looked), which leaves nothing new to see.
37
+ const retry = failedAt !== undefined && Date.now() - failedAt >= (o.retryMs ?? 1000);
38
+ if (now !== last || retry) {
39
+ last = now;
40
+ try {
41
+ await o.reload();
42
+ lastError = '';
43
+ failedAt = undefined;
44
+ }
45
+ catch (e) {
46
+ failedAt = Date.now();
47
+ const text = e instanceof SitefileError ? `error[${e.code}]: ${e.message}` : String(e?.message ?? e);
48
+ if (text !== lastError)
49
+ o.onError(e);
50
+ lastError = text;
51
+ }
52
+ }
53
+ }
54
+ finally {
55
+ if (!stopped)
56
+ timer = setTimeout(() => void tick(), o.pollMs ?? BUCKET_POLL_MS);
57
+ }
58
+ };
59
+ void tick();
60
+ return () => {
61
+ stopped = true;
62
+ clearTimeout(timer);
63
+ };
64
+ }
65
+ //# sourceMappingURL=bucket-follow.js.map
@@ -0,0 +1,270 @@
1
+ import { type Stats } from 'node:fs';
2
+ import { SitefileError } from './errors.js';
3
+ import type { Store } from './store.js';
4
+ import { Tree, type FileNode } from './tree.js';
5
+ /**
6
+ * Buckets: named, mutable file trees owned by the store (docs/CLI.md, "Buckets"). Twin: rust/src/bucket.rs.
7
+ *
8
+ * $SITEFILE_HOME/buckets/<name>/ the files, plain (what `serve bucket:<name>` serves)
9
+ * $SITEFILE_HOME/buckets/.meta/<name>.json {"created": "<iso>"}, beside the tree and never in it
10
+ * $SITEFILE_HOME/buckets/.tmp/ files being written (renamed into place when whole)
11
+ * $SITEFILE_HOME/buckets/.staging/ a `--batch` tree being built, swapped in with two renames
12
+ * $SITEFILE_HOME/buckets/.swap/ the journal and the displaced tree of a swap in progress (never swept)
13
+ *
14
+ * Every change holds the store lock. A file is written to `.tmp` and renamed into place, so a reader sees
15
+ * the old file or the new one, never half of it. Nothing here follows a symbolic link, and a file with
16
+ * more than one hard link is never read: a bucket directory another program has planted links in is
17
+ * refused, not read through.
18
+ */
19
+ export declare const BUCKET_NAME_MAX = 63;
20
+ /** What `bucket put` accepts from stdin or a file unless `--max-bytes` says otherwise. */
21
+ export declare const DEFAULT_PUT_MAX_BYTES: number;
22
+ /** Validate a bucket name (`E_USAGE`). The grammar is lowercase on purpose: two names never differ only in case. */
23
+ export declare function checkBucketName(name: string): string;
24
+ /**
25
+ * The segments of a path inside a bucket (`a/b/c.txt`), NFC. Refused: NUL, backslashes, `..` and `.`, a leading
26
+ * `/` (absolute), empty segments, names Windows cannot hold, and over-long names. A single trailing `/` is
27
+ * dropped (the caller decides whether a directory is fine).
28
+ */
29
+ export declare function checkBucketPath(raw: string): string[];
30
+ /** `name/path/inside` → its name and the segments of what follows the first `/` (none for a bare name). */
31
+ export declare function splitBucketRef(arg: string): {
32
+ name: string;
33
+ segs: string[];
34
+ slash: boolean;
35
+ };
36
+ /** `bucket:<name>[/prefix]` as `serve` and the servers file write it, or undefined when `arg` is not one. */
37
+ export declare function parseBucketSource(arg: string): {
38
+ name: string;
39
+ prefix: string | undefined;
40
+ } | undefined;
41
+ export declare const bucketLabel: (name: string, prefix?: string) => string;
42
+ /** What the tests may hook and count (never set in production). */
43
+ export declare const bucketHooks: {
44
+ beforeRead?: (file: string) => void | Promise<void>;
45
+ /** Called at each point of a swap; a test throws {@link SwapCrash} to stop the protocol there as a crash would (nothing is cleaned up). */
46
+ crash?: (point: 'swap-journal' | 'swap-displaced' | 'swap-placed' | 'rm-cleaned' | 'rm-displaced') => void;
47
+ /** Called before every flush with the path; a test throws to make that flush fail. */
48
+ flush?: (path: string) => void;
49
+ /** Where warnings go (default: standard error). */
50
+ warn?: (message: string) => void;
51
+ };
52
+ /** Thrown by a test's `bucketHooks.crash`: the swap stops where it is and leaves everything as a crash would. */
53
+ export declare class SwapCrash extends Error {
54
+ }
55
+ export declare const bucketStats: {
56
+ fileReads: number;
57
+ };
58
+ /** The most bytes `serve`, `snapshot` and `restore` hold in memory for a bucket unless `--max-bytes` says otherwise. */
59
+ export declare const DEFAULT_LOAD_MAX_BYTES: number;
60
+ /** A file that vanished or changed between being listed and being read: the whole read is tried again. */
61
+ export declare class BucketRace extends SitefileError {
62
+ }
63
+ /**
64
+ * The bytes and mode of a regular file with one link. It is opened without following a symbolic link and without
65
+ * blocking (a FIFO swapped in after `st` was taken must not hang the command, which may hold the store lock), and
66
+ * the open file must still be the one `st` described. On Windows there is no `O_NOFOLLOW`, no FIFO in a directory
67
+ * and no stable inode here: a reparse point swapped in is caught by the file-type and link-count checks only.
68
+ */
69
+ export declare function readRegular(file: string, st: Stats, what: string): Promise<{
70
+ bytes: Uint8Array;
71
+ mode: number;
72
+ }>;
73
+ export interface BucketEntry {
74
+ readonly path: string;
75
+ readonly size: number;
76
+ readonly mode: number;
77
+ /** The file on disk and what was seen of it (a read checks it is still that file). */
78
+ readonly file: string;
79
+ readonly st: Stats;
80
+ /** Size, mtime, ctime and inode: what says a file is the one read before. */
81
+ readonly stamp: string;
82
+ }
83
+ /** Files already read, by path: a reload reads only the files whose stamp changed and shares the others. */
84
+ export type BucketReadCache = Map<string, {
85
+ stamp: string;
86
+ node: FileNode;
87
+ }>;
88
+ /**
89
+ * Every file under `dir` (a real directory) with `lstat` only, as bucket-relative paths: nothing is read, so the cost is
90
+ * proportional to the number of entries. A file or directory that vanishes during the walk is skipped. Symbolic links
91
+ * and hard-linked files are errors that say which link to remove, special files are `E_UNSUPPORTED_FILE`, and two names
92
+ * that differ only in Unicode normalization are `E_PATH_COLLISION`. `o.dirs` receives every directory, empty ones too.
93
+ */
94
+ export declare function scanDirectory(dir: string, name: string, relBase: readonly string[], o?: {
95
+ dirs?: string[];
96
+ }): Promise<BucketEntry[]>;
97
+ export interface BucketSummary {
98
+ readonly name: string;
99
+ readonly created: string;
100
+ readonly files: number;
101
+ readonly size: number;
102
+ /** Set when the bucket cannot be read (a link planted in it): the sentence that says what to do. */
103
+ readonly problem?: string;
104
+ }
105
+ export type PutResult = 'created' | 'replaced' | 'unchanged';
106
+ /** What a bulk change does to a bucket (`put` of a directory, `restore`). */
107
+ export interface BucketChange {
108
+ readonly writes: ReadonlyArray<readonly [string, FileNode]>;
109
+ /** Remove the files that are not among `writes`, after the writes (`restore --delete`). */
110
+ readonly deleteOthers: boolean;
111
+ }
112
+ export interface BucketChangeResult {
113
+ readonly written: number;
114
+ readonly unchanged: number;
115
+ readonly removed: number;
116
+ }
117
+ export declare class Buckets {
118
+ readonly store: Store;
119
+ readonly root: string;
120
+ private constructor();
121
+ static open(store: Store): Buckets;
122
+ private dirOf;
123
+ private metaFile;
124
+ private get tmpDir();
125
+ private get stagingDir();
126
+ /** `.swap/<name>.json` is the journal of a `--batch` swap, `.swap/<name>.old` the displaced tree: the sweep never touches either. */
127
+ private get swapDir();
128
+ private journalOf;
129
+ private oldOf;
130
+ private scratch;
131
+ /**
132
+ * A `--batch` swap is: build the new tree in `.staging/<bucket>.<token>`, journal `.swap/<name>.json` = `{"token": "<hex>"}`
133
+ * (data only: every path is derived from the bucket name and a token matching /^[a-f0-9]{16,64}$/, never read from
134
+ * the journal), rename the bucket to `.swap/<name>.old`, rename the staged tree to the bucket, remove the journal,
135
+ * remove `.old`. Durability, in this order: every staged file and directory is fsynced; the journal is written to a
136
+ * temporary file, fsynced, renamed, and `.swap` is fsynced, all BEFORE the first bucket rename (else power loss could
137
+ * keep that rename and lose the journal); after each rename that matters the directories it changed are fsynced (the
138
+ * bucket's parent and `.swap` after the first, the parent and `.staging` after the second, `.swap` after the
139
+ * journal's removal). Windows cannot fsync a directory: files are flushed (FlushFileBuffers) and NTFS journals its
140
+ * own metadata, but the order of two renames across a power loss is not guaranteed there; recovery below does not
141
+ * depend on the journal for that reason.
142
+ *
143
+ * Recovery runs under the lock before anything else touches the bucket, and decides from the directory state
144
+ * (J journal, D bucket directory, O `.swap/<name>.old`, S the staged tree `.staging/<name>.<token>`):
145
+ *
146
+ * J D O S action
147
+ * - - - . nothing (no such bucket)
148
+ * - y - . nothing
149
+ * - y y . keep O: a leftover of a finished swap; only the next successful swap of this bucket, or
150
+ * `bucket rm`, removes it, never create or a sweep
151
+ * - - y . put O back as D (power loss kept the first rename and lost the journal)
152
+ * y y - . the swap never began or was rolled back: remove S and J
153
+ * y y y . the swap finished: remove O, S and J
154
+ * y - y . the new tree was never placed: put O back as D, remove S and J (rolled back, not finished)
155
+ * y - - y O is gone and D is not there: the complete staged tree becomes D, J is removed
156
+ * y - - - nothing left to restore: remove J
157
+ *
158
+ * `bucket rm` runs the other way round: it recovers, then removes O, J and every S of the bucket and fsyncs `.swap`
159
+ * and `.staging`, failing loudly if it cannot, and only then renames D away, so a crash inside it leaves D (or
160
+ * nothing), never an O that the next command would put back: a removed bucket cannot come back with old contents.
161
+ * No removal of an O, J or S is ever ignored.
162
+ *
163
+ * A journal that is unreadable, empty, garbage or not UTF-8 names no token: the state is decided from D, O and J's
164
+ * existence alone. Running recovery again changes nothing.
165
+ */
166
+ private needsRecovery;
167
+ /** Recover for a writer: under the lock, before it works on the bucket. */
168
+ recover(name: string): Promise<void>;
169
+ /**
170
+ * Recover for a reader: an intact bucket (its directory is there) is served as it is, leftovers and all, so a read
171
+ * never writes (the store may be read-only). Only a bucket whose directory is missing is recovered, which needs
172
+ * the lock (it also waits for a swap in progress); if that is impossible the read fails and says why.
173
+ */
174
+ private recoverForRead;
175
+ /** {@link recover} for a caller that holds the lock. */
176
+ recoverLocked(name: string): Promise<void>;
177
+ /** A swap of this bucket has begun and not ended (a reader that finds the bucket missing waits for it). */
178
+ private swapPending;
179
+ /**
180
+ * Run a read of the bucket. A `--batch` swap in progress (or interrupted) is waited for or recovered first, and a
181
+ * read that is cut by a swap (the bucket's directory is another one now, or missing during the swap) is repeated,
182
+ * bounded: a reader sees the old tree or the new one, whatever kind of read it is.
183
+ */
184
+ private reading;
185
+ /** What is at the bucket's name: a directory, a link (planted: `rm` may remove it), or nothing. */
186
+ kindOf(name: string): Promise<'dir' | 'link' | undefined>;
187
+ /** The bucket's directory when it exists as a real directory (never a symbolic link), else `E_NOT_FOUND`. */
188
+ realDir(name: string): Promise<string>;
189
+ /**
190
+ * The directory at `segs` below the bucket, each component checked with `lstat`: a symbolic link anywhere on
191
+ * the way is refused. A component is found by its NFC spelling, as the readers do.
192
+ */
193
+ resolveDirectory(name: string, segs: readonly string[]): Promise<string>;
194
+ private resolveDir;
195
+ create(name: string): Promise<void>;
196
+ /**
197
+ * Delete the scratch files an interrupted write left (older than an hour). The caller holds the lock, and has
198
+ * recovered the bucket it works on: only `.tmp` and `.staging` are swept, never `.swap`, where a swap in progress
199
+ * keeps the tree it displaced.
200
+ */
201
+ private sweepScratch;
202
+ /** The token a journal names, if it names one: data, never a path. */
203
+ private journalToken;
204
+ createdOf(name: string): Promise<string>;
205
+ stats(name: string): Promise<{
206
+ files: number;
207
+ size: number;
208
+ }>;
209
+ /** Every bucket; one that cannot be read (a link planted in it) carries a `problem` and the others are listed all the same. */
210
+ list(): Promise<BucketSummary[]>;
211
+ /** Remove a bucket. The caller has already refused what should be refused (files, running servers). */
212
+ remove(name: string): Promise<void>;
213
+ /** The files under `prefix` (a directory, or a single file), without their contents. */
214
+ listFiles(name: string, prefix: readonly string[]): Promise<BucketEntry[]>;
215
+ /** One file's bytes, with the sandbox rules of every read. */
216
+ get(name: string, segs: readonly string[]): Promise<{
217
+ bytes: Uint8Array;
218
+ mode: number;
219
+ }>;
220
+ /**
221
+ * The tree of a bucket (or of a directory `prefix` of it, re-rooted): every file, hidden ones too, read through
222
+ * the sandbox. The origin of its files is `bucket:<name>`.
223
+ *
224
+ * Listing is by `lstat`; only files whose stamp (size, mtime, ctime, inode) differs from `o.cache` are read, and the
225
+ * others are the very nodes of the last load, so a reload holds the changed files once, not the bucket twice. The
226
+ * cache is replaced by the files of this load. More than `o.maxBytes` (default {@link DEFAULT_LOAD_MAX_BYTES}) is
227
+ * `E_TOO_LARGE` before any byte is read. `o.locked`: the caller holds the store lock (no recovery is attempted).
228
+ */
229
+ loadTree(name: string, prefix?: readonly string[], o?: {
230
+ cache?: BucketReadCache;
231
+ maxBytes?: number;
232
+ locked?: boolean;
233
+ }): Promise<Tree>;
234
+ private loadOnce;
235
+ /**
236
+ * Put one file. `source` yields its bytes (stdin, a file); it is staged in `.tmp` first (so a failed or
237
+ * oversized transfer changes nothing) and renamed into place under the lock.
238
+ */
239
+ putFile(name: string, segs: readonly string[], source: AsyncIterable<Uint8Array>, mode: number, maxBytes: number): Promise<{
240
+ result: PutResult;
241
+ size: number;
242
+ }>;
243
+ /** The directory that will hold `segs`' last segment, created as needed, every step checked. The caller holds the lock. */
244
+ private prepareParent;
245
+ /** The on-disk name of `seg` among `entries` (the same NFC name), `undefined` when absent; a name that differs only in case is `E_PATH_COLLISION`. */
246
+ private matchEntry;
247
+ /** Move the staged file `tmp` to `segs`: the one rename that makes it visible. The caller holds the lock. */
248
+ private place;
249
+ /**
250
+ * Apply a bulk change. By default each file is written atomically on its own; with `batch` the whole
251
+ * resulting tree is built beside the bucket and swapped in (see {@link recover}), so a reader sees all of the
252
+ * change or none of it. **Nothing is written** when a conflict is found, and every conflict is found first: a file
253
+ * that would replace different content without `overwrite`, a file where a directory is (an empty one too), a name
254
+ * that differs only in case from a file or an empty directory, a file where a directory has to be. Existing files
255
+ * are listed by `lstat` and read only when a write names the same path, so the bucket is not held in memory.
256
+ */
257
+ apply(name: string, change: BucketChange, o: {
258
+ overwrite: boolean;
259
+ batch: boolean;
260
+ }): Promise<BucketChangeResult>;
261
+ /**
262
+ * Build the new tree in `.staging` (unchanged files are copied from the bucket, changed ones written) and swap it
263
+ * for the bucket directory: journal, displace, place, unjournal. The caller holds the lock. Empty directories are
264
+ * not carried over (a tree has none).
265
+ */
266
+ private swapIn;
267
+ /** Remove a file, or (with `recursive`) a directory and everything in it; empty parents go too. */
268
+ removePath(name: string, segs: readonly string[], recursive: boolean): Promise<void>;
269
+ private removeLocked;
270
+ }