opfs-worker 1.3.1 → 2.0.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/README.md +89 -106
- package/dist/{facade.d.ts → OPFSFacade.d.ts} +26 -9
- package/dist/OPFSFacade.d.ts.map +1 -0
- package/dist/{worker.d.ts → OPFSWorker.d.ts} +11 -11
- package/dist/OPFSWorker.d.ts.map +1 -0
- package/dist/assets/worker.entry-DUlEoroc.js.map +1 -0
- package/dist/createOPFSWorker.d.ts +17 -0
- package/dist/createOPFSWorker.d.ts.map +1 -0
- package/dist/helpers-DNj8ZoMu.cjs +4 -0
- package/dist/helpers-DNj8ZoMu.cjs.map +1 -0
- package/dist/{helpers-CKOebsbw.js → helpers-WY2jfbOT.js} +257 -253
- package/dist/helpers-WY2jfbOT.js.map +1 -0
- package/dist/index.cjs +349 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +428 -382
- package/dist/index.js.map +1 -1
- package/dist/index.pure.cjs +2 -0
- package/dist/index.pure.cjs.map +1 -0
- package/dist/index.pure.d.ts +6 -0
- package/dist/index.pure.d.ts.map +1 -0
- package/dist/{raw.js → index.pure.js} +248 -188
- package/dist/index.pure.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +14 -6
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +15 -3
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.entry.d.ts +2 -0
- package/dist/worker.entry.d.ts.map +1 -0
- package/docs/api-reference.md +815 -0
- package/docs/file-descriptors.md +696 -0
- package/docs/types.md +232 -0
- package/package.json +15 -9
- package/src/OPFSFacade.ts +460 -0
- package/src/OPFSWorker.ts +1544 -0
- package/src/createOPFSWorker.ts +57 -0
- package/src/index.pure.ts +7 -0
- package/src/index.ts +15 -0
- package/src/types.ts +99 -0
- package/src/utils/encoder.ts +205 -0
- package/src/utils/errors.ts +297 -0
- package/src/utils/helpers.ts +465 -0
- package/src/worker.entry.ts +6 -0
- package/dist/assets/worker-1Wh1cr7P.js.map +0 -1
- package/dist/assets/worker-BeJaVyBV.js.map +0 -1
- package/dist/facade.d.ts.map +0 -1
- package/dist/helpers-BuGfPAg0.js +0 -1439
- package/dist/helpers-BuGfPAg0.js.map +0 -1
- package/dist/helpers-CF7A2WQG.cjs +0 -4
- package/dist/helpers-CF7A2WQG.cjs.map +0 -1
- package/dist/helpers-CIiblZ8d.cjs +0 -4
- package/dist/helpers-CIiblZ8d.cjs.map +0 -1
- package/dist/helpers-CKOebsbw.js.map +0 -1
- package/dist/raw.cjs +0 -2
- package/dist/raw.cjs.map +0 -1
- package/dist/raw.d.ts +0 -13
- package/dist/raw.d.ts.map +0 -1
- package/dist/raw.js.map +0 -1
- package/dist/worker.d.ts.map +0 -1
package/docs/types.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Types
|
|
2
|
+
|
|
3
|
+
This document contains all TypeScript types and interfaces provided by OPFS Worker.
|
|
4
|
+
|
|
5
|
+
## Core Types
|
|
6
|
+
|
|
7
|
+
### `FileStat`
|
|
8
|
+
|
|
9
|
+
File or directory statistics.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
interface FileStat {
|
|
13
|
+
kind: 'file' | 'directory';
|
|
14
|
+
size: number;
|
|
15
|
+
mtime: string; // ISO string
|
|
16
|
+
ctime: string; // ISO string
|
|
17
|
+
isFile: boolean;
|
|
18
|
+
isDirectory: boolean;
|
|
19
|
+
hash?: string; // Hash of file content (only for files)
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Properties:**
|
|
24
|
+
|
|
25
|
+
- `kind`: Type of the file system entry
|
|
26
|
+
- `size`: Size in bytes (0 for directories)
|
|
27
|
+
- `mtime`: Last modification time as ISO string
|
|
28
|
+
- `ctime`: Creation time as ISO string
|
|
29
|
+
- `isFile`: True if this is a file
|
|
30
|
+
- `isDirectory`: True if this is a directory
|
|
31
|
+
- `hash`: Optional hash of file content (only present for files when hashing is enabled)
|
|
32
|
+
|
|
33
|
+
### `DirentData`
|
|
34
|
+
|
|
35
|
+
Directory entry information.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
interface DirentData {
|
|
39
|
+
name: string;
|
|
40
|
+
kind: 'file' | 'directory';
|
|
41
|
+
isFile: boolean;
|
|
42
|
+
isDirectory: boolean;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Properties:**
|
|
47
|
+
|
|
48
|
+
- `name`: Name of the file or directory
|
|
49
|
+
- `kind`: Type of the entry
|
|
50
|
+
- `isFile`: True if this is a file
|
|
51
|
+
- `isDirectory`: True if this is a directory
|
|
52
|
+
|
|
53
|
+
### `WatchOptions`
|
|
54
|
+
|
|
55
|
+
Options for file watching operations.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
interface WatchOptions {
|
|
59
|
+
recursive?: boolean; // Whether to watch recursively (default: true)
|
|
60
|
+
include?: string | string[]; // Glob patterns to include in watching (minimatch syntax, default: ['**'])
|
|
61
|
+
exclude?: string | string[]; // Glob patterns to exclude from watching (minimatch syntax, default: [])
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Properties:**
|
|
66
|
+
|
|
67
|
+
- `recursive`: Whether to watch the entire directory tree (default: true)
|
|
68
|
+
- `include`: Glob patterns to include in watching (default: all files)
|
|
69
|
+
- `exclude`: Glob patterns to exclude from watching (default: none)
|
|
70
|
+
|
|
71
|
+
### `RemoteOPFSWorker`
|
|
72
|
+
|
|
73
|
+
Remote file system interface type for Comlink communication.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
type RemoteOPFSWorker = Remote<OPFSWorker>;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This type represents the remote interface when using the worker with Comlink.
|
|
80
|
+
|
|
81
|
+
## Configuration Types
|
|
82
|
+
|
|
83
|
+
### `OPFSOptions`
|
|
84
|
+
|
|
85
|
+
Configuration options for creating an OPFS Worker instance.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
interface OPFSOptions {
|
|
89
|
+
/** Root path for the file system (default: '/') */
|
|
90
|
+
root?: string;
|
|
91
|
+
/** Namespace for the events (default: 'opfs-worker:${root}') */
|
|
92
|
+
namespace?: string;
|
|
93
|
+
/** Hash algorithm for file hashing, or false/null to disable (default: 'etag') */
|
|
94
|
+
hashAlgorithm?: null | false | 'etag' | 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
95
|
+
/** Maximum file size in bytes for SHA-* hashing (default: 50MB); ignored by 'etag' */
|
|
96
|
+
maxFileSize?: number;
|
|
97
|
+
/** Custom name for the broadcast channel (default: 'opfs-worker') */
|
|
98
|
+
broadcastChannel?: string | BroadcastChannel | null;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Properties:**
|
|
103
|
+
|
|
104
|
+
- `root`: Root path for the file system
|
|
105
|
+
- `namespace`: Namespace for events and isolation
|
|
106
|
+
- `hashAlgorithm`: `'etag'` (default, mtime+size), `'SHA-*'`, or `null`/`false` to disable
|
|
107
|
+
- `maxFileSize`: Max bytes for SHA-* content hashing (etag ignores this)
|
|
108
|
+
- `broadcastChannel`: Custom broadcast channel name or instance
|
|
109
|
+
|
|
110
|
+
## Event Types
|
|
111
|
+
|
|
112
|
+
### `WatchEventType`
|
|
113
|
+
|
|
114
|
+
Enumeration of file system change event types.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
enum WatchEventType {
|
|
118
|
+
Added = 'added',
|
|
119
|
+
Changed = 'changed',
|
|
120
|
+
Removed = 'removed'
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Values:**
|
|
125
|
+
|
|
126
|
+
- `Added`: File or directory was created
|
|
127
|
+
- `Changed`: File or directory was modified
|
|
128
|
+
- `Removed`: File or directory was deleted
|
|
129
|
+
|
|
130
|
+
### `WatchEvent`
|
|
131
|
+
|
|
132
|
+
File system change event sent via BroadcastChannel.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
interface WatchEvent {
|
|
136
|
+
namespace: string;
|
|
137
|
+
path: string;
|
|
138
|
+
type: WatchEventType;
|
|
139
|
+
isDirectory: boolean;
|
|
140
|
+
timestamp: string;
|
|
141
|
+
hash?: string;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Properties:**
|
|
146
|
+
|
|
147
|
+
- `namespace`: Event namespace for isolation
|
|
148
|
+
- `path`: Path of the changed file/directory
|
|
149
|
+
- `type`: Type of change (added, changed, removed)
|
|
150
|
+
- `isDirectory`: Whether the changed item is a directory
|
|
151
|
+
- `timestamp`: ISO timestamp of the change
|
|
152
|
+
- `hash`: Optional hash of the file content (if hashing is enabled)
|
|
153
|
+
|
|
154
|
+
## Utility Types
|
|
155
|
+
|
|
156
|
+
### `Kind`
|
|
157
|
+
|
|
158
|
+
File system entry type.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
type Kind = 'file' | 'directory';
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### `Encoding`
|
|
165
|
+
|
|
166
|
+
Supported text encodings.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
type Encoding = 'utf-8' | 'utf-16le' | 'ascii' | 'latin1' | 'base64' | 'hex' | 'binary';
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Error Types
|
|
173
|
+
|
|
174
|
+
The library provides comprehensive error handling with specific error types that are Node.js SystemError compatible:
|
|
175
|
+
|
|
176
|
+
### Base Error Class
|
|
177
|
+
|
|
178
|
+
- `OPFSError` - Base error class for all OPFS-related errors (Node.js SystemError compatible)
|
|
179
|
+
|
|
180
|
+
**Properties:**
|
|
181
|
+
|
|
182
|
+
- `errno: number` - Numeric error code (e.g., -2 for ENOENT)
|
|
183
|
+
- `syscall?: string` - System call name (e.g., 'open', 'read', 'write')
|
|
184
|
+
- `path?: string` - File path when applicable
|
|
185
|
+
- `name: string` - Error class name ('OPFSError')
|
|
186
|
+
- `message: string` - Human-readable error message
|
|
187
|
+
- `cause?: any` - Underlying error (Node.js 16+ feature)
|
|
188
|
+
|
|
189
|
+
### Specialized Error Classes
|
|
190
|
+
|
|
191
|
+
- `OPFSNotSupportedError` - Thrown when OPFS is not supported in the browser
|
|
192
|
+
- `PathError` - Thrown for invalid paths or path traversal attempts
|
|
193
|
+
- `ExistenceError` - Thrown when files or directories don't exist
|
|
194
|
+
- Usage: `new ExistenceError('File not found: /path/to/file', 'ENOENT', '/path/to/file')`
|
|
195
|
+
- `PermissionError` - Thrown when permission is denied for an operation
|
|
196
|
+
- `StorageError` - Thrown when an operation fails due to insufficient storage
|
|
197
|
+
- `TimeoutError` - Thrown when an operation times out
|
|
198
|
+
- `FileBusyError` - Thrown when a file is busy (locked by another operation)
|
|
199
|
+
- `FileTypeError` - Thrown when file/directory type expectations don't match
|
|
200
|
+
- Usage: `new FileTypeError('directory', '/path/to/dir')`
|
|
201
|
+
- `ValidationError` - Thrown for validation failures (invalid arguments, formats, etc.)
|
|
202
|
+
- Usage: `new ValidationError('Invalid size', 'EINVAL', '/path/to/file')`
|
|
203
|
+
- `OperationAbortedError` - Thrown when an operation is aborted
|
|
204
|
+
- `IOError` - Thrown for I/O operation failures
|
|
205
|
+
- `OperationNotSupportedError` - Thrown when an operation is not supported
|
|
206
|
+
- `DirectoryOperationError` - Thrown when directory operations fail
|
|
207
|
+
- Usage: `new DirectoryOperationError('RM_FAILED', '/path/to/dir')`
|
|
208
|
+
- `InitializationFailedError` - Thrown when OPFS initialization fails
|
|
209
|
+
- `FileSystemOperationError` - Thrown when file system operations fail
|
|
210
|
+
- `PathResolutionFailedError` - Thrown when path resolution fails
|
|
211
|
+
- `AlreadyExistsError` - Thrown when a file or directory already exists
|
|
212
|
+
|
|
213
|
+
### Error Code Mapping
|
|
214
|
+
|
|
215
|
+
The library uses standard POSIX error codes with numeric errno mapping:
|
|
216
|
+
|
|
217
|
+
- `ENOENT` (-2) - No such file or directory
|
|
218
|
+
- `EISDIR` (-21) - Is a directory
|
|
219
|
+
- `ENOTDIR` (-20) - Not a directory
|
|
220
|
+
- `EACCES` (-13) - Permission denied
|
|
221
|
+
- `EEXIST` (-17) - File exists
|
|
222
|
+
- `ENOTEMPTY` (-39) - Directory not empty
|
|
223
|
+
- `EINVAL` (-22) - Invalid argument
|
|
224
|
+
- `EIO` (-5) - I/O error
|
|
225
|
+
- `ENOSPC` (-28) - No space left on device
|
|
226
|
+
- `EBUSY` (-16) - Device or resource busy
|
|
227
|
+
- `EINTR` (-4) - Interrupted system call
|
|
228
|
+
- `ENOTSUP` (-95) - Operation not supported
|
|
229
|
+
- `ERANGE` (-34) - Result too large
|
|
230
|
+
- `EBADF` (-9) - Bad file descriptor
|
|
231
|
+
|
|
232
|
+
Each error type extends the base `OPFSError` class and provides specific error codes and context information for better debugging.
|
package/package.json
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opfs-worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A robust TypeScript library for working with Origin Private File System (OPFS) through Web Workers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"source": "src/index.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
12
|
+
"source": "./src/index.ts",
|
|
11
13
|
"import": "./dist/index.js",
|
|
12
14
|
"require": "./dist/index.cjs"
|
|
13
15
|
},
|
|
14
|
-
"./
|
|
15
|
-
"types": "./dist/
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"./pure": {
|
|
17
|
+
"types": "./dist/index.pure.d.ts",
|
|
18
|
+
"source": "./src/index.pure.ts",
|
|
19
|
+
"import": "./dist/index.pure.js",
|
|
20
|
+
"require": "./dist/index.pure.cjs"
|
|
18
21
|
}
|
|
19
22
|
},
|
|
23
|
+
"sideEffects": false,
|
|
20
24
|
"files": [
|
|
21
25
|
"dist/**/*",
|
|
26
|
+
"src/**/*",
|
|
27
|
+
"docs/**/*",
|
|
22
28
|
"README.md",
|
|
23
29
|
"LICENSE"
|
|
24
30
|
],
|
|
@@ -28,12 +34,12 @@
|
|
|
28
34
|
"dev": "concurrently \"vite build --watch --mode development\" \"tsc -p tsconfig.build.json --watch\"",
|
|
29
35
|
"preview": "vite preview demo",
|
|
30
36
|
"type-check": "tsc --noEmit",
|
|
31
|
-
"lint": "eslint src --ext .ts,.tsx",
|
|
32
|
-
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
37
|
+
"lint": "eslint src --ext .ts,.tsx --fix --max-warnings=9999 --quiet",
|
|
33
38
|
"test": "vitest --run",
|
|
34
39
|
"test:coverage": "vitest --coverage",
|
|
35
|
-
"prepublishOnly": "
|
|
36
|
-
"
|
|
40
|
+
"prepublishOnly": "bun run lint && bun run type-check && bun run build",
|
|
41
|
+
"changelog": "changeset",
|
|
42
|
+
"version-packages": "changeset version",
|
|
37
43
|
"release": "changeset publish"
|
|
38
44
|
},
|
|
39
45
|
"keywords": [
|