@emdzej/bimmerz-vfs 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,131 @@
1
+ # PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree
8
+ to them as both strict obligations and conditions to all
9
+ your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the
14
+ software to do everything you might do with the software
15
+ that would otherwise infringe the licensor's copyright
16
+ in it for any permitted purpose. However, you may
17
+ only distribute the software according to [Distribution
18
+ License](#distribution-license) and make changes or new works
19
+ based on the software according to [Changes and New Works
20
+ License](#changes-and-new-works-license).
21
+
22
+ ## Distribution License
23
+
24
+ The licensor grants you an additional copyright license
25
+ to distribute copies of the software. Your license
26
+ to distribute covers distributing the software with
27
+ changes and new works permitted by [Changes and New Works
28
+ License](#changes-and-new-works-license).
29
+
30
+ ## Notices
31
+
32
+ You must ensure that anyone who gets a copy of any part of
33
+ the software from you also gets a copy of these terms or the
34
+ URL for them above, as well as copies of any plain-text lines
35
+ beginning with `Required Notice:` that the licensor provided
36
+ with the software. For example:
37
+
38
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
39
+
40
+ ## Changes and New Works License
41
+
42
+ The licensor grants you an additional copyright license to
43
+ make changes and new works based on the software for any
44
+ permitted purpose.
45
+
46
+ ## Patent License
47
+
48
+ The licensor grants you a patent license for the software that
49
+ covers patent claims the licensor can license, or becomes able
50
+ to license, that you would infringe by using the software.
51
+
52
+ ## Noncommercial Purposes
53
+
54
+ Any noncommercial purpose is a permitted purpose.
55
+
56
+ ## Personal Uses
57
+
58
+ Personal use for research, experiment, and testing for
59
+ the benefit of public knowledge, personal study, private
60
+ entertainment, hobby projects, amateur pursuits, or religious
61
+ observance, without any anticipated commercial application,
62
+ is use for a permitted purpose.
63
+
64
+ ## Noncommercial Organizations
65
+
66
+ Use by any charitable organization, educational institution,
67
+ public research organization, public safety or health
68
+ organization, environmental protection organization,
69
+ or government institution is use for a permitted purpose
70
+ regardless of the source of funding or obligations resulting
71
+ from the funding.
72
+
73
+ ## Fair Use
74
+
75
+ You may have "fair use" rights for the software under the
76
+ law. These terms do not limit them.
77
+
78
+ ## No Other Rights
79
+
80
+ These terms do not allow you to sublicense or transfer any of
81
+ your licenses to anyone else, or prevent the licensor from
82
+ granting licenses to anyone else. These terms do not imply
83
+ any other licenses.
84
+
85
+ ## Patent Defense
86
+
87
+ If you make any written claim that the software infringes or
88
+ contributes to infringement of any patent, your patent license
89
+ for the software granted under these terms ends immediately. If
90
+ your company makes such a claim, your patent license ends
91
+ immediately for work on behalf of your company.
92
+
93
+ ## Violations
94
+
95
+ The first time you are notified in writing that you have
96
+ violated any of these terms, or done anything with the software
97
+ not covered by your licenses, your licenses can nonetheless
98
+ continue if you come into full compliance with these terms,
99
+ and take practical steps to correct past violations, within
100
+ 32 days of receiving notice. Otherwise, all your licenses
101
+ end immediately.
102
+
103
+ ## No Liability
104
+
105
+ ***As far as the law allows, the software comes as is, without
106
+ any warranty or condition, and the licensor will not be liable
107
+ to you for any damages arising out of these terms or the use
108
+ or nature of the software, under any kind of legal claim.***
109
+
110
+ ## Definitions
111
+
112
+ The **licensor** is the individual or entity offering these
113
+ terms, and the **software** is the software the licensor makes
114
+ available under these terms.
115
+
116
+ **You** refers to the individual or entity agreeing to these
117
+ terms.
118
+
119
+ **Your company** is any legal entity, sole proprietorship,
120
+ or other kind of organization that you work for, plus all
121
+ organizations that have control over, are under the control of,
122
+ or are under common control with that organization. **Control**
123
+ means ownership of substantially all the assets of an entity,
124
+ or the power to direct its management and policies by vote,
125
+ contract, or otherwise. Control can be direct or indirect.
126
+
127
+ **Your licenses** are all the licenses granted to you for the
128
+ software under these terms.
129
+
130
+ **Use** means anything you do with the software requiring one
131
+ of your licenses.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # @emdzej/bimmerz-vfs
2
+
3
+ Read-only virtual file system for bimmerz tools — one interface, two backends:
4
+
5
+ | Backend | Class | Source |
6
+ |---|---|---|
7
+ | **Local** | `FsaDirectory` | File System Access API / OPFS (`FileSystemDirectoryHandle`) |
8
+ | **Remote** | `HttpDirectory` | HTTP server + `index.json` directory listings |
9
+
10
+ Both implement `VirtualDirectory`. All lookups are **case-insensitive**.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm i @emdzej/bimmerz-vfs
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```ts
21
+ import { FsaDirectory, HttpDirectory, drillPath, listFiles } from '@emdzej/bimmerz-vfs';
22
+
23
+ // ---- Local (File System Access API / OPFS) ----
24
+ const handle = await showDirectoryPicker();
25
+ const local = new FsaDirectory(handle);
26
+
27
+ // ---- Remote (HTTP + index.json) ----
28
+ const remote = new HttpDirectory('https://files.example.com/inpa-bundle');
29
+
30
+ // ---- Same API for both ----
31
+ const ecu = await drillPath(remote, 'EDIABAS', 'Ecu'); // case-insensitive
32
+ const ipos = await listFiles(ecu!, '.ipo'); // [{ name: 'MS43.IPO', size: 12345 }]
33
+ const file = await ecu!.file('ms43.prg'); // case-insensitive
34
+ const bytes = await file!.arrayBuffer();
35
+ ```
36
+
37
+ ## API
38
+
39
+ ### `VirtualDirectory`
40
+
41
+ ```ts
42
+ interface VirtualDirectory {
43
+ readonly name: string;
44
+
45
+ /** Case-insensitive. Returns null if not found. */
46
+ file(name: string): Promise<VirtualFile | null>;
47
+
48
+ /** Case-insensitive. Returns null if not found. */
49
+ dir(name: string): Promise<VirtualDirectory | null>;
50
+
51
+ /**
52
+ * Flat listing of direct children.
53
+ * Note: FsaDirectory returns size=0 for files — call file(name) for the real size.
54
+ */
55
+ entries(): Promise<VirtualEntry[]>;
56
+ }
57
+
58
+ type VirtualEntry =
59
+ | { kind: 'file'; name: string; size: number }
60
+ | { kind: 'dir'; name: string };
61
+ ```
62
+
63
+ ### `VirtualFile`
64
+
65
+ ```ts
66
+ interface VirtualFile {
67
+ readonly name: string; // original-cased full basename: "MS43.IPO"
68
+ readonly size: number;
69
+ arrayBuffer(): Promise<ArrayBuffer>;
70
+ }
71
+ ```
72
+
73
+ ### `FsaDirectory(handle)`
74
+
75
+ Wraps a `FileSystemDirectoryHandle` (File System Access API or OPFS). Both sources return the same handle type, so this class works for both.
76
+
77
+ ```ts
78
+ // File System Access API (user picks a folder)
79
+ const root = new FsaDirectory(await showDirectoryPicker());
80
+
81
+ // OPFS (pre-extracted bundle)
82
+ const opfsRoot = await navigator.storage.getDirectory();
83
+ const root = new FsaDirectory(opfsRoot);
84
+ ```
85
+
86
+ `entries()` does not call `getFile()` per entry (no extra I/O for listings). Call `file(name)` when you need the actual size.
87
+
88
+ ### `HttpDirectory(baseUrl, options?)`
89
+
90
+ Navigates a remote tree using `index.json` files generated by `bimmerz data index`.
91
+
92
+ ```ts
93
+ const root = new HttpDirectory('https://cdn.example.com/inpa', {
94
+ indexFile: 'index.json', // default
95
+ fetch: customFetch, // inject auth headers, mock in tests, etc.
96
+ });
97
+ ```
98
+
99
+ **How it works:**
100
+ 1. On first access `entries()` / `file()` / `dir()` fetches `{baseUrl}/index.json` and caches it.
101
+ 2. `file(name)` finds the matching entry (case-insensitive on `fullName`) and returns an `HttpFile` that fetches `{baseUrl}/{originalFullName}` on `arrayBuffer()`.
102
+ 3. `dir(name)` returns a new `HttpDirectory` rooted at `{baseUrl}/{originalFullName}/`, which lazily fetches its own `index.json`.
103
+
104
+ The `index.json` format is the one written by [`bimmerz data index`](../../../apps/cli) — both `fullName` (lowercase) and `originalFullName` (original casing) are present in every entry. The lookup uses `fullName` for matching and `originalFullName` for the fetch URL, so the original casing of the server's files is preserved in HTTP requests.
105
+
106
+ **`link` entries** (symlinks recorded by `bimmerz data index`) are treated as files.
107
+
108
+ ### `drillPath(root, ...segments)`
109
+
110
+ Walk down a path segment by segment, case-insensitively. Returns `null` at the first missing segment.
111
+
112
+ ```ts
113
+ const cfgdat = await drillPath(root, 'EC-APPS', 'INPA', 'CFGDAT');
114
+ // equivalent to:
115
+ // root.dir('EC-APPS') → .dir('INPA') → .dir('CFGDAT')
116
+ ```
117
+
118
+ ### `listFiles(dir, ext?)`
119
+
120
+ Return all file entries in `dir`, optionally filtered by extension (case-insensitive, dot required).
121
+
122
+ ```ts
123
+ const ipos = await listFiles(cfgdat, '.ipo');
124
+ // [{ kind: 'file', name: 'MS43.IPO', size: 512 }, ...]
125
+ ```
126
+
127
+ Returns `Array<{ kind: 'file'; name: string; size: number }>` — lightweight entry objects. Call `dir.file(name)` to open one.
128
+
129
+ ## Serving an install remotely
130
+
131
+ Use `bimmerz data index` to write `index.json` files into the extracted install tree, then serve the whole directory over HTTP (nginx, GitHub Pages, any static host):
132
+
133
+ ```bash
134
+ bimmerz data index ~/inpa-extracted
135
+ # → writes index.json in every subdirectory
136
+
137
+ # Serve with any static file server
138
+ npx serve ~/inpa-extracted
139
+ ```
140
+
141
+ Then point `HttpDirectory` at the server root:
142
+
143
+ ```ts
144
+ const root = new HttpDirectory('http://localhost:3000');
145
+ const cfgdat = await drillPath(root, 'EC-APPS', 'INPA', 'CFGDAT');
146
+ const ipo = await cfgdat!.file('MS43.IPO');
147
+ const bytes = await ipo!.arrayBuffer();
148
+ ```
149
+
150
+ ## Notes
151
+
152
+ - **Read-only** — no write operations. External write-back (fault-store reports, etc.) is application-layer concern.
153
+ - **No runtime dependencies** — FSA is a browser built-in; HTTP uses `fetch`. Works in any environment with `fetch` (browsers, Node ≥ 18, Deno, Bun).
154
+ - **Index caching** — each `HttpDirectory` instance fetches its `index.json` at most once. Create a new instance to force a refresh.
package/dist/fsa.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { VirtualFile, VirtualDirectory, VirtualEntry } from './types.js';
2
+ export declare class FsaFile implements VirtualFile {
3
+ #private;
4
+ readonly name: string;
5
+ readonly size: number;
6
+ constructor(handle: FileSystemFileHandle, file: File);
7
+ arrayBuffer(): Promise<ArrayBuffer>;
8
+ }
9
+ export declare class FsaDirectory implements VirtualDirectory {
10
+ #private;
11
+ readonly name: string;
12
+ constructor(handle: FileSystemDirectoryHandle);
13
+ file(name: string): Promise<VirtualFile | null>;
14
+ dir(name: string): Promise<VirtualDirectory | null>;
15
+ entries(): Promise<VirtualEntry[]>;
16
+ }
17
+ //# sourceMappingURL=fsa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fsa.d.ts","sourceRoot":"","sources":["../src/fsa.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9E,qBAAa,OAAQ,YAAW,WAAW;;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAKV,MAAM,EAAE,oBAAoB,EAAE,IAAI,EAAE,IAAI;IAMpD,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;CAGpC;AAED,qBAAa,YAAa,YAAW,gBAAgB;;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGV,MAAM,EAAE,yBAAyB;IAKvC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAY/C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAUnD,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;CAazC"}
package/dist/fsa.js ADDED
@@ -0,0 +1,58 @@
1
+ export class FsaFile {
2
+ name;
3
+ size;
4
+ // Cache the File object obtained during construction so arrayBuffer()
5
+ // doesn't need a second getFile() round-trip.
6
+ #file;
7
+ constructor(handle, file) {
8
+ this.name = handle.name;
9
+ this.size = file.size;
10
+ this.#file = file;
11
+ }
12
+ arrayBuffer() {
13
+ return this.#file.arrayBuffer();
14
+ }
15
+ }
16
+ export class FsaDirectory {
17
+ name;
18
+ #handle;
19
+ constructor(handle) {
20
+ this.name = handle.name;
21
+ this.#handle = handle;
22
+ }
23
+ async file(name) {
24
+ const target = name.toLowerCase();
25
+ for await (const [entryName, handle] of this.#handle.entries()) {
26
+ if (handle.kind === 'file' && entryName.toLowerCase() === target) {
27
+ const fileHandle = handle;
28
+ const file = await fileHandle.getFile();
29
+ return new FsaFile(fileHandle, file);
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+ async dir(name) {
35
+ const target = name.toLowerCase();
36
+ for await (const [entryName, handle] of this.#handle.entries()) {
37
+ if (handle.kind === 'directory' && entryName.toLowerCase() === target) {
38
+ return new FsaDirectory(handle);
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+ async entries() {
44
+ const result = [];
45
+ for await (const [name, handle] of this.#handle.entries()) {
46
+ if (handle.kind === 'file') {
47
+ // Avoid calling getFile() for every entry — size is 0 here.
48
+ // Call dir.file(name) when you need the actual file and its size.
49
+ result.push({ kind: 'file', name, size: 0 });
50
+ }
51
+ else if (handle.kind === 'directory') {
52
+ result.push({ kind: 'dir', name });
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ }
58
+ //# sourceMappingURL=fsa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fsa.js","sourceRoot":"","sources":["../src/fsa.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,OAAO;IACT,IAAI,CAAS;IACb,IAAI,CAAS;IACtB,sEAAsE;IACtE,8CAA8C;IACrC,KAAK,CAAO;IAErB,YAAY,MAA4B,EAAE,IAAU;QAClD,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,YAA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OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAC1D,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC3B,4DAA4D;gBAC5D,kEAAkE;gBAClE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC;iBAAM,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBACvC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fsa.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fsa.test.d.ts","sourceRoot":"","sources":["../src/fsa.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,118 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { FsaDirectory, FsaFile } from './fsa.js';
3
+ // ---------------------------------------------------------------------------
4
+ // Mock helpers — minimal FSA-shaped objects without a real browser
5
+ // ---------------------------------------------------------------------------
6
+ function mockFile(name, content) {
7
+ return {
8
+ kind: 'file',
9
+ name,
10
+ getFile: async () => ({ arrayBuffer: async () => content.buffer.slice(0), size: content.length }),
11
+ };
12
+ }
13
+ function mockDir(name, children) {
14
+ return {
15
+ kind: 'directory',
16
+ name,
17
+ entries: async function* () {
18
+ for (const child of children) {
19
+ yield [child.name, child];
20
+ }
21
+ },
22
+ };
23
+ }
24
+ // ---------------------------------------------------------------------------
25
+ // FsaFile
26
+ // ---------------------------------------------------------------------------
27
+ describe('FsaFile', () => {
28
+ const content = new Uint8Array([0x49, 0x50, 0x4f]);
29
+ const handle = mockFile('MS43.IPO', content);
30
+ it('exposes name and size from constructor args', async () => {
31
+ const file = await handle.getFile();
32
+ const fsaFile = new FsaFile(handle, file);
33
+ expect(fsaFile.name).toBe('MS43.IPO');
34
+ expect(fsaFile.size).toBe(3);
35
+ });
36
+ it('arrayBuffer() returns the file contents', async () => {
37
+ const file = await handle.getFile();
38
+ const fsaFile = new FsaFile(handle, file);
39
+ const buf = await fsaFile.arrayBuffer();
40
+ expect(new Uint8Array(buf)).toEqual(content);
41
+ });
42
+ });
43
+ // ---------------------------------------------------------------------------
44
+ // FsaDirectory
45
+ // ---------------------------------------------------------------------------
46
+ const IPO = new Uint8Array([0x01, 0x02, 0x03]);
47
+ const INI = new Uint8Array([0x5b, 0x49, 0x4e, 0x50, 0x41, 0x5d]); // [INPA]
48
+ const ecuHandle = mockDir('Ecu', [
49
+ mockFile('MS43.prg', new Uint8Array([0x50, 0x52, 0x47])),
50
+ ]);
51
+ const rootHandle = mockDir('root', [
52
+ mockFile('MS43.IPO', IPO),
53
+ mockFile('INPA.INI', INI),
54
+ ecuHandle,
55
+ ]);
56
+ const root = new FsaDirectory(rootHandle);
57
+ describe('FsaDirectory.file()', () => {
58
+ it('returns null when the file does not exist', async () => {
59
+ expect(await root.file('missing.ipo')).toBeNull();
60
+ });
61
+ it('finds a file by exact name', async () => {
62
+ const f = await root.file('MS43.IPO');
63
+ expect(f).not.toBeNull();
64
+ expect(f.name).toBe('MS43.IPO');
65
+ });
66
+ it('finds a file case-insensitively', async () => {
67
+ const f = await root.file('ms43.ipo');
68
+ expect(f).not.toBeNull();
69
+ expect(f.name).toBe('MS43.IPO');
70
+ });
71
+ it('does not return a directory when looking for a file', async () => {
72
+ expect(await root.file('Ecu')).toBeNull();
73
+ });
74
+ it('returns file with correct size and contents', async () => {
75
+ const f = await root.file('MS43.IPO');
76
+ expect(f.size).toBe(IPO.length);
77
+ const buf = await f.arrayBuffer();
78
+ expect(new Uint8Array(buf)).toEqual(IPO);
79
+ });
80
+ });
81
+ describe('FsaDirectory.dir()', () => {
82
+ it('returns null when the directory does not exist', async () => {
83
+ expect(await root.dir('missing')).toBeNull();
84
+ });
85
+ it('finds a directory by exact name', async () => {
86
+ const d = await root.dir('Ecu');
87
+ expect(d).not.toBeNull();
88
+ expect(d.name).toBe('Ecu');
89
+ });
90
+ it('finds a directory case-insensitively', async () => {
91
+ const d = await root.dir('ecu');
92
+ expect(d).not.toBeNull();
93
+ expect(d.name).toBe('Ecu');
94
+ });
95
+ it('does not return a file when looking for a directory', async () => {
96
+ expect(await root.dir('MS43.IPO')).toBeNull();
97
+ });
98
+ });
99
+ describe('FsaDirectory.entries()', () => {
100
+ it('lists files with kind "file" and size 0', async () => {
101
+ const entries = await root.entries();
102
+ const files = entries.filter((e) => e.kind === 'file');
103
+ expect(files.length).toBe(2);
104
+ expect(files.every((f) => f.kind === 'file' && f.size === 0)).toBe(true);
105
+ });
106
+ it('lists directories with kind "dir"', async () => {
107
+ const entries = await root.entries();
108
+ const dirs = entries.filter((e) => e.kind === 'dir');
109
+ expect(dirs.length).toBe(1);
110
+ expect(dirs[0].name).toBe('Ecu');
111
+ });
112
+ it('preserves original casing in entry names', async () => {
113
+ const entries = await root.entries();
114
+ const names = entries.map((e) => e.name).sort();
115
+ expect(names).toEqual(['Ecu', 'INPA.INI', 'MS43.IPO'].sort());
116
+ });
117
+ });
118
+ //# sourceMappingURL=fsa.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fsa.test.js","sourceRoot":"","sources":["../src/fsa.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD,8EAA8E;AAC9E,mEAAmE;AACnE,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,IAAY,EAAE,OAAmB;IACjD,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,IAAI;QACJ,OAAO,EAAE,KAAK,IAAI,EAAE,CAClB,CAAC,EAAE,WAAW,EAAE,KAAK,IAAI,EAAE,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,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QAChD,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { VirtualFile, VirtualDirectory, VirtualEntry } from './types.js';
2
+ export interface HttpDirectoryOptions {
3
+ /** Name of the index file to fetch from each directory. Default: `"index.json"`. */
4
+ indexFile?: string;
5
+ /**
6
+ * Custom fetch implementation. Defaults to `globalThis.fetch`.
7
+ * Useful for injecting auth headers, mocking in tests, etc.
8
+ */
9
+ fetch?: typeof globalThis.fetch;
10
+ }
11
+ export declare class HttpFile implements VirtualFile {
12
+ #private;
13
+ readonly name: string;
14
+ readonly size: number;
15
+ constructor(name: string, size: number, url: string, fetchFn: typeof globalThis.fetch);
16
+ arrayBuffer(): Promise<ArrayBuffer>;
17
+ }
18
+ export declare class HttpDirectory implements VirtualDirectory {
19
+ #private;
20
+ readonly name: string;
21
+ constructor(baseUrl: string, options?: HttpDirectoryOptions);
22
+ file(name: string): Promise<VirtualFile | null>;
23
+ dir(name: string): Promise<VirtualDirectory | null>;
24
+ entries(): Promise<VirtualEntry[]>;
25
+ }
26
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAiB9E,MAAM,WAAW,oBAAoB;IACnC,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,qBAAa,QAAS,YAAW,WAAW;;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAKpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,UAAU,CAAC,KAAK;IAQ5B,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;CAK1C;AAED,qBAAa,aAAc,YAAW,gBAAgB;;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAOV,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB;IAkBzD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAY/C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAWnD,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;CAYzC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=http.e2e.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.e2e.test.d.ts","sourceRoot":"","sources":["../src/http.e2e.test.ts"],"names":[],"mappings":""}