@ricsam/quickjs-fs 0.2.10 → 0.2.11
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/dist/cjs/package.json +1 -1
- package/dist/mjs/package.json +1 -1
- package/dist/types/quickjs.d.ts +314 -0
- package/package.json +5 -2
package/dist/cjs/package.json
CHANGED
package/dist/mjs/package.json
CHANGED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-fs
|
|
3
|
+
*
|
|
4
|
+
* These types define the globals injected by setupFs() into a QuickJS context.
|
|
5
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Typecheck QuickJS code with file system access
|
|
9
|
+
* const root = await fs.getDirectory("/data");
|
|
10
|
+
* const fileHandle = await root.getFileHandle("config.json");
|
|
11
|
+
* const file = await fileHandle.getFile();
|
|
12
|
+
* const content = await file.text();
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export {};
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
// ============================================
|
|
19
|
+
// fs namespace - QuickJS-specific entry point
|
|
20
|
+
// ============================================
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* File System namespace providing access to the file system.
|
|
24
|
+
* This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).
|
|
25
|
+
*/
|
|
26
|
+
namespace fs {
|
|
27
|
+
/**
|
|
28
|
+
* Get a directory handle for the given path.
|
|
29
|
+
*
|
|
30
|
+
* The host controls which paths are accessible. Invalid or unauthorized
|
|
31
|
+
* paths will throw an error.
|
|
32
|
+
*
|
|
33
|
+
* @param path - The path to request from the host
|
|
34
|
+
* @returns A promise resolving to a directory handle
|
|
35
|
+
* @throws If the path is not allowed or doesn't exist
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const root = await fs.getDirectory("/");
|
|
39
|
+
* const dataDir = await fs.getDirectory("/data");
|
|
40
|
+
*/
|
|
41
|
+
function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ============================================
|
|
45
|
+
// File System Access API
|
|
46
|
+
// ============================================
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Base interface for file system handles.
|
|
50
|
+
*/
|
|
51
|
+
interface FileSystemHandle {
|
|
52
|
+
/**
|
|
53
|
+
* The kind of handle: "file" or "directory".
|
|
54
|
+
*/
|
|
55
|
+
readonly kind: "file" | "directory";
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The name of the file or directory.
|
|
59
|
+
*/
|
|
60
|
+
readonly name: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Compare two handles to check if they reference the same entry.
|
|
64
|
+
*
|
|
65
|
+
* @param other - Another FileSystemHandle to compare against
|
|
66
|
+
* @returns true if both handles reference the same entry
|
|
67
|
+
*/
|
|
68
|
+
isSameEntry(other: FileSystemHandle): Promise<boolean>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Handle for a file in the file system.
|
|
73
|
+
*/
|
|
74
|
+
interface FileSystemFileHandle extends FileSystemHandle {
|
|
75
|
+
/**
|
|
76
|
+
* Always "file" for file handles.
|
|
77
|
+
*/
|
|
78
|
+
readonly kind: "file";
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get the file contents as a File object.
|
|
82
|
+
*
|
|
83
|
+
* @returns A promise resolving to a File object
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const file = await fileHandle.getFile();
|
|
87
|
+
* const text = await file.text();
|
|
88
|
+
*/
|
|
89
|
+
getFile(): Promise<File>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create a writable stream for writing to the file.
|
|
93
|
+
*
|
|
94
|
+
* @param options - Options for the writable stream
|
|
95
|
+
* @returns A promise resolving to a writable stream
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const writable = await fileHandle.createWritable();
|
|
99
|
+
* await writable.write("Hello, World!");
|
|
100
|
+
* await writable.close();
|
|
101
|
+
*/
|
|
102
|
+
createWritable(options?: {
|
|
103
|
+
/**
|
|
104
|
+
* If true, keeps existing file data. Otherwise, truncates the file.
|
|
105
|
+
*/
|
|
106
|
+
keepExistingData?: boolean;
|
|
107
|
+
}): Promise<FileSystemWritableFileStream>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Handle for a directory in the file system.
|
|
112
|
+
*/
|
|
113
|
+
interface FileSystemDirectoryHandle extends FileSystemHandle {
|
|
114
|
+
/**
|
|
115
|
+
* Always "directory" for directory handles.
|
|
116
|
+
*/
|
|
117
|
+
readonly kind: "directory";
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get a file handle within this directory.
|
|
121
|
+
*
|
|
122
|
+
* @param name - The name of the file
|
|
123
|
+
* @param options - Options for getting the file handle
|
|
124
|
+
* @returns A promise resolving to a file handle
|
|
125
|
+
* @throws If the file doesn't exist and create is not true
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const file = await dir.getFileHandle("data.json");
|
|
129
|
+
* const newFile = await dir.getFileHandle("output.txt", { create: true });
|
|
130
|
+
*/
|
|
131
|
+
getFileHandle(
|
|
132
|
+
name: string,
|
|
133
|
+
options?: {
|
|
134
|
+
/**
|
|
135
|
+
* If true, creates the file if it doesn't exist.
|
|
136
|
+
*/
|
|
137
|
+
create?: boolean;
|
|
138
|
+
}
|
|
139
|
+
): Promise<FileSystemFileHandle>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get a subdirectory handle within this directory.
|
|
143
|
+
*
|
|
144
|
+
* @param name - The name of the subdirectory
|
|
145
|
+
* @param options - Options for getting the directory handle
|
|
146
|
+
* @returns A promise resolving to a directory handle
|
|
147
|
+
* @throws If the directory doesn't exist and create is not true
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const subdir = await dir.getDirectoryHandle("logs");
|
|
151
|
+
* const newDir = await dir.getDirectoryHandle("cache", { create: true });
|
|
152
|
+
*/
|
|
153
|
+
getDirectoryHandle(
|
|
154
|
+
name: string,
|
|
155
|
+
options?: {
|
|
156
|
+
/**
|
|
157
|
+
* If true, creates the directory if it doesn't exist.
|
|
158
|
+
*/
|
|
159
|
+
create?: boolean;
|
|
160
|
+
}
|
|
161
|
+
): Promise<FileSystemDirectoryHandle>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Remove a file or directory within this directory.
|
|
165
|
+
*
|
|
166
|
+
* @param name - The name of the entry to remove
|
|
167
|
+
* @param options - Options for removal
|
|
168
|
+
* @throws If the entry doesn't exist or cannot be removed
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* await dir.removeEntry("old-file.txt");
|
|
172
|
+
* await dir.removeEntry("old-dir", { recursive: true });
|
|
173
|
+
*/
|
|
174
|
+
removeEntry(
|
|
175
|
+
name: string,
|
|
176
|
+
options?: {
|
|
177
|
+
/**
|
|
178
|
+
* If true, removes directories recursively.
|
|
179
|
+
*/
|
|
180
|
+
recursive?: boolean;
|
|
181
|
+
}
|
|
182
|
+
): Promise<void>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Resolve the path from this directory to a descendant handle.
|
|
186
|
+
*
|
|
187
|
+
* @param possibleDescendant - A handle that may be a descendant
|
|
188
|
+
* @returns An array of path segments, or null if not a descendant
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* const path = await root.resolve(nestedFile);
|
|
192
|
+
* // ["subdir", "file.txt"]
|
|
193
|
+
*/
|
|
194
|
+
resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Iterate over entries in this directory.
|
|
198
|
+
*
|
|
199
|
+
* @returns An async iterator of [name, handle] pairs
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* for await (const [name, handle] of dir.entries()) {
|
|
203
|
+
* console.log(name, handle.kind);
|
|
204
|
+
* }
|
|
205
|
+
*/
|
|
206
|
+
entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Iterate over entry names in this directory.
|
|
210
|
+
*
|
|
211
|
+
* @returns An async iterator of names
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* for await (const name of dir.keys()) {
|
|
215
|
+
* console.log(name);
|
|
216
|
+
* }
|
|
217
|
+
*/
|
|
218
|
+
keys(): AsyncIterableIterator<string>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Iterate over handles in this directory.
|
|
222
|
+
*
|
|
223
|
+
* @returns An async iterator of handles
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* for await (const handle of dir.values()) {
|
|
227
|
+
* console.log(handle.name, handle.kind);
|
|
228
|
+
* }
|
|
229
|
+
*/
|
|
230
|
+
values(): AsyncIterableIterator<FileSystemHandle>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Async iterator support for directory entries.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* for await (const [name, handle] of dir) {
|
|
237
|
+
* console.log(name, handle.kind);
|
|
238
|
+
* }
|
|
239
|
+
*/
|
|
240
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Parameters for write operations on FileSystemWritableFileStream.
|
|
245
|
+
*/
|
|
246
|
+
interface WriteParams {
|
|
247
|
+
/**
|
|
248
|
+
* The type of write operation.
|
|
249
|
+
* - "write": Write data at the current position or specified position
|
|
250
|
+
* - "seek": Move the file position
|
|
251
|
+
* - "truncate": Truncate the file to a specific size
|
|
252
|
+
*/
|
|
253
|
+
type: "write" | "seek" | "truncate";
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The data to write (for "write" type).
|
|
257
|
+
*/
|
|
258
|
+
data?: string | ArrayBuffer | Uint8Array | Blob;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The position to write at or seek to.
|
|
262
|
+
*/
|
|
263
|
+
position?: number;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The size to truncate to (for "truncate" type).
|
|
267
|
+
*/
|
|
268
|
+
size?: number;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Writable stream for writing to a file.
|
|
273
|
+
* Extends WritableStream with file-specific operations.
|
|
274
|
+
*/
|
|
275
|
+
interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {
|
|
276
|
+
/**
|
|
277
|
+
* Write data to the file.
|
|
278
|
+
*
|
|
279
|
+
* @param data - The data to write
|
|
280
|
+
* @returns A promise that resolves when the write completes
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* await writable.write("Hello, World!");
|
|
284
|
+
* await writable.write(new Uint8Array([1, 2, 3]));
|
|
285
|
+
* await writable.write({ type: "write", data: "text", position: 0 });
|
|
286
|
+
*/
|
|
287
|
+
write(
|
|
288
|
+
data: string | ArrayBuffer | Uint8Array | Blob | WriteParams
|
|
289
|
+
): Promise<void>;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Seek to a position in the file.
|
|
293
|
+
*
|
|
294
|
+
* @param position - The byte position to seek to
|
|
295
|
+
* @returns A promise that resolves when the seek completes
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* await writable.seek(0); // Seek to beginning
|
|
299
|
+
* await writable.write("Overwrite");
|
|
300
|
+
*/
|
|
301
|
+
seek(position: number): Promise<void>;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Truncate the file to a specific size.
|
|
305
|
+
*
|
|
306
|
+
* @param size - The size to truncate to
|
|
307
|
+
* @returns A promise that resolves when the truncation completes
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* await writable.truncate(100); // Keep only first 100 bytes
|
|
311
|
+
*/
|
|
312
|
+
truncate(size: number): Promise<void>;
|
|
313
|
+
}
|
|
314
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/quickjs-fs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"main": "./dist/cjs/index.cjs",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"types": "./dist/types/index.d.ts",
|
|
9
9
|
"require": "./dist/cjs/index.cjs",
|
|
10
10
|
"import": "./dist/mjs/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./quickjs": {
|
|
13
|
+
"types": "./dist/types/quickjs.d.ts"
|
|
11
14
|
}
|
|
12
15
|
},
|
|
13
16
|
"scripts": {
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
"typecheck": "tsc --noEmit"
|
|
17
20
|
},
|
|
18
21
|
"dependencies": {
|
|
19
|
-
"@ricsam/quickjs-core": "^0.2.
|
|
22
|
+
"@ricsam/quickjs-core": "^0.2.11",
|
|
20
23
|
"quickjs-emscripten": "^0.31.0"
|
|
21
24
|
},
|
|
22
25
|
"peerDependencies": {
|