@statewalker/webrun-files-composite 0.7.1 → 0.8.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.
- package/LICENSE +21 -0
- package/README.md +219 -144
- package/dist/cjs/index.cjs +770 -28
- package/dist/composite-files-api.d.ts +50 -4
- package/dist/composite-files-api.d.ts.map +1 -1
- package/dist/cow-files-api.d.ts +36 -0
- package/dist/cow-files-api.d.ts.map +1 -0
- package/dist/esm/index.js +762 -29
- package/dist/filtered-files-api.d.ts +167 -0
- package/dist/filtered-files-api.d.ts.map +1 -0
- package/dist/glob-to-regexp.d.ts +56 -0
- package/dist/glob-to-regexp.d.ts.map +1 -0
- package/dist/guarded-files-api.d.ts +64 -0
- package/dist/guarded-files-api.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/overlay-files-api.d.ts +20 -0
- package/dist/overlay-files-api.d.ts.map +1 -0
- package/dist/read-only-files-api.d.ts +21 -0
- package/dist/read-only-files-api.d.ts.map +1 -0
- package/dist/types.d.ts +50 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/composite-files-api.ts +50 -29
- package/src/cow-files-api.ts +244 -0
- package/src/filtered-files-api.ts +257 -0
- package/src/glob-to-regexp.ts +182 -0
- package/src/guarded-files-api.ts +131 -0
- package/src/index.ts +14 -0
- package/src/overlay-files-api.ts +121 -0
- package/src/read-only-files-api.ts +30 -0
- package/src/types.ts +52 -3
|
@@ -1,16 +1,62 @@
|
|
|
1
1
|
import type { FileInfo, FileStats, FilesApi, ListOptions, ReadOptions } from "@statewalker/webrun-files";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Composite `FilesApi` that routes calls to one of several backends based
|
|
4
|
+
* on a path prefix. Mounts are matched by **longest prefix wins**, so a
|
|
5
|
+
* mount at `/a/b` takes precedence over a mount at `/a` for paths under
|
|
6
|
+
* `/a/b/...`. The mount point itself appears in listings as a synthetic
|
|
7
|
+
* directory and cannot be removed.
|
|
8
|
+
*
|
|
9
|
+
* Each backend can use a sub-directory of its own filesystem as the mount
|
|
10
|
+
* root via `fsPath` (constructor `rootPath` for the implicit root mount,
|
|
11
|
+
* `fsPath` argument for additional mounts). Cross-mount `move` is
|
|
12
|
+
* implemented as copy-then-delete; there is no atomicity guarantee.
|
|
13
|
+
*
|
|
14
|
+
* Access control and visibility filtering are intentionally **not** part of
|
|
15
|
+
* this class — wrap with {@link GuardedFilesApi} or {@link FilteredFilesApi}
|
|
16
|
+
* (or both) instead.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const fs = new CompositeFilesApi(localFs, "/projects")
|
|
21
|
+
* .mount("/docs", s3Fs, "/documentation")
|
|
22
|
+
* .mount("/cache", memFs);
|
|
23
|
+
* await fs.write("/readme.md", data); // → localFs:/projects/readme.md
|
|
24
|
+
* await fs.write("/docs/api.md", data); // → s3Fs:/documentation/api.md
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
3
27
|
export declare class CompositeFilesApi implements FilesApi {
|
|
4
28
|
private mounts;
|
|
5
|
-
|
|
29
|
+
/**
|
|
30
|
+
* @param root Default backend used for any path that does not match a
|
|
31
|
+
* more specific mount. All paths are routed here unless `mount()`
|
|
32
|
+
* intercepts them.
|
|
33
|
+
* @param rootPath Optional sub-directory of the root backend to use as
|
|
34
|
+
* the composite filesystem's `/`. For example, `rootPath = "/projects"`
|
|
35
|
+
* makes the composite path `/readme.md` resolve to `/projects/readme.md`
|
|
36
|
+
* in the root backend. Defaults to `"/"` (no remapping).
|
|
37
|
+
*/
|
|
6
38
|
constructor(root: FilesApi, rootPath?: string);
|
|
39
|
+
/**
|
|
40
|
+
* Attaches a backend to handle every composite path under `path`. The
|
|
41
|
+
* mount prefix is normalized; paths under it are resolved against the
|
|
42
|
+
* mount's `fsPath` sub-directory (defaulting to `"/"`).
|
|
43
|
+
*
|
|
44
|
+
* @param path Composite-namespace prefix (e.g. `"/docs"`). Mounting at
|
|
45
|
+
* `"/"` is forbidden — use the constructor `root` argument instead.
|
|
46
|
+
* @param api The backend `FilesApi` to delegate to for paths under
|
|
47
|
+
* `path`. Wrap it in {@link FilteredFilesApi} / {@link GuardedFilesApi}
|
|
48
|
+
* first if you want mount-local filtering or guards.
|
|
49
|
+
* @param fsPath Sub-directory of the mounted backend used as its mount
|
|
50
|
+
* root, e.g. `mount("/docs", s3, "/documentation")` makes
|
|
51
|
+
* `/docs/api.md` resolve to `/documentation/api.md` on `s3`.
|
|
52
|
+
* @returns `this`, for chaining.
|
|
53
|
+
* @throws If `path` normalizes to `"/"`.
|
|
54
|
+
*/
|
|
7
55
|
mount(path: string, api: FilesApi, fsPath?: string): this;
|
|
8
|
-
guard(operations: FileOperation[], check: (path: string) => boolean, message?: string): this;
|
|
9
56
|
private resolve;
|
|
10
57
|
private isMountPoint;
|
|
11
58
|
/** Returns mount prefixes that are direct children of the given path. */
|
|
12
59
|
private childMountPrefixes;
|
|
13
|
-
private checkGuard;
|
|
14
60
|
read(path: string, options?: ReadOptions): AsyncIterable<Uint8Array>;
|
|
15
61
|
write(path: string, content: Iterable<Uint8Array> | AsyncIterable<Uint8Array>): Promise<void>;
|
|
16
62
|
mkdir(path: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composite-files-api.d.ts","sourceRoot":"","sources":["../src/composite-files-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,WAAW,EACZ,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"composite-files-api.d.ts","sourceRoot":"","sources":["../src/composite-files-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,WAAW,EACZ,MAAM,2BAA2B,CAAC;AASnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAC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D;IAID,OAAO,CAAC,aAAa;YAOP,SAAS;IA4BvB,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,iBAAiB;CAQ1B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FilesApi } from "@statewalker/webrun-files";
|
|
2
|
+
/** Options for {@link cow}. */
|
|
3
|
+
export interface CowOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Filename prefix for per-path whiteout markers, stored in the writable
|
|
6
|
+
* layer. A whiteout for `/dir/name` lives at `/dir/<prefix>name`.
|
|
7
|
+
* Defaults to `".wh."`.
|
|
8
|
+
*/
|
|
9
|
+
whiteoutPrefix?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Filename for the opaque-directory marker, stored as a child of a
|
|
12
|
+
* directory whose base subtree has been deleted. Defaults to `".wh..opq"`.
|
|
13
|
+
*/
|
|
14
|
+
opaqueName?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Builds a copy-on-write `FilesApi`: a `writable` layer over a read-only
|
|
18
|
+
* `base`. Reads fall through to `base`; every write goes to `writable`;
|
|
19
|
+
* `base` is never mutated. Deletions are persisted as marker files in
|
|
20
|
+
* `writable` (a per-path whiteout for files, one opaque marker for a deleted
|
|
21
|
+
* base directory), so they survive over any backend and across restarts.
|
|
22
|
+
*
|
|
23
|
+
* @param base The read-only lower layer. Never mutated.
|
|
24
|
+
* @param writable The upper layer that captures all changes and markers.
|
|
25
|
+
* @param opts Marker naming overrides (see {@link CowOptions}).
|
|
26
|
+
* @returns A read/write `FilesApi` composing the two layers.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const fs = cow(releaseFiles, new MemFilesApi());
|
|
31
|
+
* await fs.write("/a.txt", data); // captured in the writable layer
|
|
32
|
+
* await fs.remove("/base-only"); // whiteout marker; base untouched
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function cow(base: FilesApi, writable: FilesApi, opts?: CowOptions): FilesApi;
|
|
36
|
+
//# sourceMappingURL=cow-files-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cow-files-api.d.ts","sourceRoot":"","sources":["../src/cow-files-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,QAAQ,EAGT,MAAM,2BAA2B,CAAC;AAGnC,+BAA+B;AAC/B,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAwMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAEnF"}
|