buritifs 0.0.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 +209 -0
- package/dist/chunk-QOM3Q3WE.js +803 -0
- package/dist/chunk-QOM3Q3WE.js.map +1 -0
- package/dist/index.cjs +831 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +303 -0
- package/dist/index.d.ts +303 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +943 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +34 -0
- package/dist/react/index.d.ts +34 -0
- package/dist/react/index.js +120 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Samuel Henrique
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# BuritiFS
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/buritifs)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
**A real filesystem API for the browser — paths, copy/move/rename, and crash recovery, all in one library.**
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## What is BuritiFS?
|
|
12
|
+
|
|
13
|
+
BuritiFS is a TypeScript library that gives you a real filesystem abstraction inside the browser. It combines two browser storage primitives — **OPFS** (Origin Private File System) for binary file content and **IndexedDB** for the node tree, metadata, and structure — and exposes a single, unified API driven by familiar path strings.
|
|
14
|
+
|
|
15
|
+
Without BuritiFS, building a browser-based file manager means manually juggling IndexedDB transactions, OPFS handles, recursive copy/move logic, and cross-storage consistency. If the user closes the tab mid-write, data becomes inconsistent with no recovery path.
|
|
16
|
+
|
|
17
|
+
BuritiFS solves all of this:
|
|
18
|
+
|
|
19
|
+
- **Path-based API** — work with `/projects/app/index.ts` just like in Node.js.
|
|
20
|
+
- **Recursive operations** — `copy`, `move`, and `delete` handle entire folder trees atomically.
|
|
21
|
+
- **Dual-storage consistency** — a Write-Ahead Log (WAL) keeps OPFS content and IndexedDB metadata in sync.
|
|
22
|
+
- **Automatic crash recovery** — on every initialization, three recovery phases clean up any state left by interrupted operations.
|
|
23
|
+
- **Reactive subscriptions** — `subscribe(path, fn)` fires whenever anything under that path changes, bubbling up to the root automatically.
|
|
24
|
+
|
|
25
|
+
> The name *Buriti* comes from a Brazilian palm tree. FS stands for File System.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Why BuritiFS?
|
|
30
|
+
|
|
31
|
+
| Feature | Raw OPFS + IDB | BuritiFS |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| Path-based addressing | No | Yes (`/folder/file.txt`) |
|
|
34
|
+
| Recursive copy/move | Manual | Built-in |
|
|
35
|
+
| Cross-storage consistency | Manual transactions | WAL + auto-recovery |
|
|
36
|
+
| Crash recovery | None | 3-phase recovery on init |
|
|
37
|
+
| React integration | None | `useExplorer`, `useFolder`, `useAction` |
|
|
38
|
+
| Vue/Svelte/Vanilla reactivity | Manual | `subscribe(path, fn)` |
|
|
39
|
+
| TypeScript-first | Partial | Full, with discriminated union results |
|
|
40
|
+
|
|
41
|
+
### API that never throws
|
|
42
|
+
|
|
43
|
+
Every public method returns `{ ok: true, error: null, ...data }` on success or `{ ok: false, error: string }` on failure. No try/catch required. TypeScript narrows the type automatically based on `result.ok`.
|
|
44
|
+
|
|
45
|
+
### Reactive by default
|
|
46
|
+
|
|
47
|
+
`subscribe(path, fn)` propagates changes upward through the directory tree. Subscribing to `/` means you get notified of every change in the filesystem. Subscribing to `/projects` means you get notified of changes anywhere inside `projects/`. The React hooks use this internally — `useFolder` re-renders automatically when the folder contents change.
|
|
48
|
+
|
|
49
|
+
### Designed for offline-first
|
|
50
|
+
|
|
51
|
+
Because BuritiFS uses OPFS and IndexedDB — both persistent browser storages — the data survives page refreshes, tab closures, and offline sessions without any server.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Is it for you?
|
|
56
|
+
|
|
57
|
+
BuritiFS is a good fit for:
|
|
58
|
+
|
|
59
|
+
- **Browser-based code editors** — store source files in OPFS, navigate them with path APIs, and react to changes in real time.
|
|
60
|
+
- **Web IDEs** — maintain a project tree with folders, files, and metadata entirely in the browser.
|
|
61
|
+
- **Offline-first apps** — ship a fully functional file system that works without a network connection.
|
|
62
|
+
- **Design tools** — store assets, project files, and drafts with version-like copy semantics.
|
|
63
|
+
- **Games with save systems** — treat save slots as files in a folder, move/copy between them with one call.
|
|
64
|
+
- **Document editors** — handle attachments, exports, and auto-saves with a consistent API.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Quick Demo
|
|
69
|
+
|
|
70
|
+
### Vanilla TypeScript (no framework)
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { ExplorerTree } from 'buritifs';
|
|
74
|
+
|
|
75
|
+
const result = await ExplorerTree.create({ name: 'my-app' });
|
|
76
|
+
|
|
77
|
+
if (!result.ok) {
|
|
78
|
+
console.error('Failed to open filesystem:', result.error);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// result is an ExplorerFolder pointing to "/"
|
|
83
|
+
const root = result;
|
|
84
|
+
|
|
85
|
+
const docs = await root.newFolder({ name: 'docs' });
|
|
86
|
+
if (!docs.ok) throw new Error(docs.error);
|
|
87
|
+
|
|
88
|
+
const file = await docs.newFile({ name: 'readme.txt' });
|
|
89
|
+
if (!file.ok) throw new Error(file.error);
|
|
90
|
+
|
|
91
|
+
await file.write({ content: 'Hello, BuritiFS!' });
|
|
92
|
+
|
|
93
|
+
const read = await file.read();
|
|
94
|
+
if (read.ok) {
|
|
95
|
+
console.log(read.text); // "Hello, BuritiFS!"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const unsubscribe = root.tree.subscribe('/', () => {
|
|
99
|
+
console.log('Something changed in the filesystem');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
unsubscribe();
|
|
103
|
+
root.tree.close();
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### React
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { useExplorer, useFolder, useAction } from 'buritifs/react';
|
|
110
|
+
|
|
111
|
+
function App() {
|
|
112
|
+
const explorer = useExplorer('my-app');
|
|
113
|
+
|
|
114
|
+
if (explorer.status === 'loading') return <p>Opening filesystem...</p>;
|
|
115
|
+
if (explorer.status === 'error') return <p>Error: {explorer.error}</p>;
|
|
116
|
+
|
|
117
|
+
return <FileTree root={explorer.root} />;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function FileTree({ root }) {
|
|
121
|
+
const { items, loading } = useFolder(root);
|
|
122
|
+
|
|
123
|
+
const createFile = useAction(() =>
|
|
124
|
+
root.newFile({ name: `file-${Date.now()}.txt` })
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (loading) return <p>Loading...</p>;
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<div>
|
|
131
|
+
<button onClick={createFile.run} disabled={createFile.loading}>
|
|
132
|
+
New File
|
|
133
|
+
</button>
|
|
134
|
+
{createFile.error && <p style={{ color: 'red' }}>{createFile.error}</p>}
|
|
135
|
+
<ul>
|
|
136
|
+
{items.map(item => (
|
|
137
|
+
<li key={item.path}>{item.path} ({item.type})</li>
|
|
138
|
+
))}
|
|
139
|
+
</ul>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Browser Support
|
|
148
|
+
|
|
149
|
+
| Browser | IndexedDB | OPFS | Status |
|
|
150
|
+
|---|---|---|---|
|
|
151
|
+
| Chrome 86+ | Yes | Yes | Fully supported |
|
|
152
|
+
| Edge 86+ | Yes | Yes | Fully supported |
|
|
153
|
+
| Safari 15.2+ | Yes | Yes | Fully supported |
|
|
154
|
+
| Firefox | Yes | Limited* | Partial support |
|
|
155
|
+
|
|
156
|
+
> **Firefox note:** Firefox supports OPFS but lacks the synchronous access handle (`createSyncAccessHandle`) and has limited support for the asynchronous API in certain contexts. Core metadata operations via IndexedDB work fine, but file content read/write may not function in all Firefox versions.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Installation
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm install buritifs
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pnpm add buritifs
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
yarn add buritifs
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
React hooks are in a separate subpath to keep the core tree-shakeable:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// Core (vanilla, Vue, Svelte, Angular...)
|
|
178
|
+
import { ExplorerTree, ExplorerFolder, ExplorerFile } from 'buritifs';
|
|
179
|
+
|
|
180
|
+
// React hooks
|
|
181
|
+
import { useExplorer, useFolder, useAction } from 'buritifs/react';
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Roadmap
|
|
187
|
+
|
|
188
|
+
- [x] ExplorerTree with path-based API
|
|
189
|
+
- [x] Recursive copy, move, delete
|
|
190
|
+
- [x] WAL-based consistency between OPFS and IndexedDB
|
|
191
|
+
- [x] 3-phase crash recovery on initialization
|
|
192
|
+
- [x] Reactive subscribe system (bubbles to root)
|
|
193
|
+
- [x] React hooks: useExplorer, useFolder, useAction
|
|
194
|
+
- [ ] `useFile` — reactive hook for file content, auto-updating when the file is written
|
|
195
|
+
- [ ] Synchronous OPFS access via Web Worker for high-performance I/O
|
|
196
|
+
- [ ] GitHub sync — push/pull filesystem snapshots to a GitHub repository
|
|
197
|
+
- [ ] Vue 3 composables (`useExplorer`, `useFolder`)
|
|
198
|
+
- [ ] Svelte 5 runes integration
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Getting Started
|
|
203
|
+
|
|
204
|
+
See **[docs/getting-started.md](docs/getting-started.md)** for a step-by-step guide.
|
|
205
|
+
|
|
206
|
+
- [Core API overview](docs/core/overview.md)
|
|
207
|
+
- [React hooks guide](docs/react/overview.md)
|
|
208
|
+
- [Using without React](docs/guides/without-react.md)
|
|
209
|
+
- [Browser support details](docs/guides/browser-support.md)
|