@ricsam/quickjs-test-utils 1.0.0 → 1.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/dist/cjs/context.cjs +86 -0
- package/dist/cjs/context.cjs.map +10 -0
- package/dist/cjs/eval.cjs +69 -0
- package/dist/cjs/eval.cjs.map +10 -0
- package/dist/cjs/fetch-context.cjs +89 -0
- package/dist/cjs/fetch-context.cjs.map +10 -0
- package/dist/cjs/fs-context.cjs +54 -0
- package/dist/cjs/fs-context.cjs.map +10 -0
- package/dist/cjs/integration-server.cjs +137 -0
- package/dist/cjs/integration-server.cjs.map +10 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/quickjs-types.cjs +700 -0
- package/dist/cjs/quickjs-types.cjs.map +10 -0
- package/dist/cjs/runtime-context.cjs +55 -0
- package/dist/cjs/runtime-context.cjs.map +10 -0
- package/dist/cjs/typecheck.cjs +108 -0
- package/dist/cjs/typecheck.cjs.map +10 -0
- package/dist/mjs/context.mjs +61 -0
- package/dist/mjs/context.mjs.map +10 -0
- package/dist/mjs/eval.mjs +38 -0
- package/dist/mjs/eval.mjs.map +10 -0
- package/dist/mjs/fetch-context.mjs +61 -0
- package/dist/mjs/fetch-context.mjs.map +10 -0
- package/dist/mjs/fs-context.mjs +29 -0
- package/dist/mjs/fs-context.mjs.map +10 -0
- package/dist/mjs/integration-server.mjs +106 -0
- package/dist/mjs/integration-server.mjs.map +10 -0
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/quickjs-types.mjs +669 -0
- package/dist/mjs/quickjs-types.mjs.map +10 -0
- package/dist/mjs/runtime-context.mjs +26 -0
- package/dist/mjs/runtime-context.mjs.map +10 -0
- package/dist/mjs/typecheck.mjs +77 -0
- package/dist/mjs/typecheck.mjs.map +10 -0
- package/package.json +5 -5
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// packages/test-utils/src/quickjs-types.ts
|
|
31
|
+
var exports_quickjs_types = {};
|
|
32
|
+
__export(exports_quickjs_types, {
|
|
33
|
+
TYPE_DEFINITIONS: () => TYPE_DEFINITIONS,
|
|
34
|
+
FS_TYPES: () => FS_TYPES,
|
|
35
|
+
FETCH_TYPES: () => FETCH_TYPES,
|
|
36
|
+
CORE_TYPES: () => CORE_TYPES
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(exports_quickjs_types);
|
|
39
|
+
var CORE_TYPES = `/**
|
|
40
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-core
|
|
41
|
+
*
|
|
42
|
+
* These types define the globals injected by setupCore() into a QuickJS context.
|
|
43
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // In your tsconfig.quickjs.json
|
|
47
|
+
* {
|
|
48
|
+
* "compilerOptions": {
|
|
49
|
+
* "lib": ["ESNext", "DOM"]
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* // Then reference this file or use ts-morph for code strings
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export {};
|
|
57
|
+
|
|
58
|
+
declare global {
|
|
59
|
+
// ============================================
|
|
60
|
+
// Web Streams API
|
|
61
|
+
// ============================================
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A readable stream of data.
|
|
65
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
66
|
+
*/
|
|
67
|
+
const ReadableStream: typeof globalThis.ReadableStream;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A writable stream of data.
|
|
71
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream
|
|
72
|
+
*/
|
|
73
|
+
const WritableStream: typeof globalThis.WritableStream;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A transform stream that can be used to pipe data through a transformer.
|
|
77
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream
|
|
78
|
+
*/
|
|
79
|
+
const TransformStream: typeof globalThis.TransformStream;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Default reader for ReadableStream
|
|
83
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader
|
|
84
|
+
*/
|
|
85
|
+
const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Default writer for WritableStream
|
|
89
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter
|
|
90
|
+
*/
|
|
91
|
+
const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;
|
|
92
|
+
|
|
93
|
+
// ============================================
|
|
94
|
+
// Blob and File APIs
|
|
95
|
+
// ============================================
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A file-like object of immutable, raw data.
|
|
99
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Blob
|
|
100
|
+
*/
|
|
101
|
+
const Blob: typeof globalThis.Blob;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A file object representing a file.
|
|
105
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
106
|
+
*/
|
|
107
|
+
const File: typeof globalThis.File;
|
|
108
|
+
|
|
109
|
+
// ============================================
|
|
110
|
+
// URL APIs
|
|
111
|
+
// ============================================
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Interface for URL manipulation.
|
|
115
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
116
|
+
*/
|
|
117
|
+
const URL: typeof globalThis.URL;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Utility for working with URL query strings.
|
|
121
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
|
|
122
|
+
*/
|
|
123
|
+
const URLSearchParams: typeof globalThis.URLSearchParams;
|
|
124
|
+
|
|
125
|
+
// ============================================
|
|
126
|
+
// Error Handling
|
|
127
|
+
// ============================================
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Exception type for DOM operations.
|
|
131
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException
|
|
132
|
+
*/
|
|
133
|
+
const DOMException: typeof globalThis.DOMException;
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
var FETCH_TYPES = `/**
|
|
137
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-fetch
|
|
138
|
+
*
|
|
139
|
+
* These types define the globals injected by setupFetch() into a QuickJS context.
|
|
140
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* // Typecheck QuickJS code with serve()
|
|
144
|
+
* serve({
|
|
145
|
+
* fetch(request, server) {
|
|
146
|
+
* if (request.url.includes("/ws")) {
|
|
147
|
+
* server.upgrade(request, { data: { id: 123 } });
|
|
148
|
+
* return new Response(null, { status: 101 });
|
|
149
|
+
* }
|
|
150
|
+
* return new Response("Hello!");
|
|
151
|
+
* },
|
|
152
|
+
* websocket: {
|
|
153
|
+
* message(ws, message) {
|
|
154
|
+
* ws.send("Echo: " + message);
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* });
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
export {};
|
|
161
|
+
|
|
162
|
+
declare global {
|
|
163
|
+
// ============================================
|
|
164
|
+
// Standard Fetch API (from lib.dom)
|
|
165
|
+
// ============================================
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Headers class for HTTP headers manipulation.
|
|
169
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
|
|
170
|
+
*/
|
|
171
|
+
const Headers: typeof globalThis.Headers;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Request class for HTTP requests.
|
|
175
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
176
|
+
*/
|
|
177
|
+
const Request: typeof globalThis.Request;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Response class for HTTP responses.
|
|
181
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response
|
|
182
|
+
*/
|
|
183
|
+
const Response: typeof globalThis.Response;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* AbortController for cancelling fetch requests.
|
|
187
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController
|
|
188
|
+
*/
|
|
189
|
+
const AbortController: typeof globalThis.AbortController;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* AbortSignal for listening to abort events.
|
|
193
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
194
|
+
*/
|
|
195
|
+
const AbortSignal: typeof globalThis.AbortSignal;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* FormData for constructing form data.
|
|
199
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FormData
|
|
200
|
+
*/
|
|
201
|
+
const FormData: typeof globalThis.FormData;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Fetch function for making HTTP requests.
|
|
205
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
|
206
|
+
*/
|
|
207
|
+
function fetch(
|
|
208
|
+
input: RequestInfo | URL,
|
|
209
|
+
init?: RequestInit
|
|
210
|
+
): Promise<Response>;
|
|
211
|
+
|
|
212
|
+
// ============================================
|
|
213
|
+
// QuickJS-specific: serve() API
|
|
214
|
+
// ============================================
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Server interface for handling WebSocket upgrades within serve() handlers.
|
|
218
|
+
*/
|
|
219
|
+
interface Server {
|
|
220
|
+
/**
|
|
221
|
+
* Upgrade an HTTP request to a WebSocket connection.
|
|
222
|
+
*
|
|
223
|
+
* @param request - The incoming HTTP request to upgrade
|
|
224
|
+
* @param options - Optional data to associate with the WebSocket connection
|
|
225
|
+
* @returns true if upgrade will proceed, false otherwise
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* serve({
|
|
229
|
+
* fetch(request, server) {
|
|
230
|
+
* if (server.upgrade(request, { data: { userId: 123 } })) {
|
|
231
|
+
* return new Response(null, { status: 101 });
|
|
232
|
+
* }
|
|
233
|
+
* return new Response("Upgrade failed", { status: 400 });
|
|
234
|
+
* }
|
|
235
|
+
* });
|
|
236
|
+
*/
|
|
237
|
+
upgrade(request: Request, options?: { data?: unknown }): boolean;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* ServerWebSocket interface for WebSocket connections within serve() handlers.
|
|
242
|
+
*
|
|
243
|
+
* @typeParam T - The type of data associated with this WebSocket connection
|
|
244
|
+
*/
|
|
245
|
+
interface ServerWebSocket<T = unknown> {
|
|
246
|
+
/**
|
|
247
|
+
* User data associated with this connection.
|
|
248
|
+
* Set via \`server.upgrade(request, { data: ... })\`.
|
|
249
|
+
*/
|
|
250
|
+
readonly data: T;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Send a message to the client.
|
|
254
|
+
*
|
|
255
|
+
* @param message - The message to send (string, ArrayBuffer, or Uint8Array)
|
|
256
|
+
*/
|
|
257
|
+
send(message: string | ArrayBuffer | Uint8Array): void;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Close the WebSocket connection.
|
|
261
|
+
*
|
|
262
|
+
* @param code - Optional close code (default: 1000)
|
|
263
|
+
* @param reason - Optional close reason
|
|
264
|
+
*/
|
|
265
|
+
close(code?: number, reason?: string): void;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* WebSocket ready state.
|
|
269
|
+
* - 0: CONNECTING
|
|
270
|
+
* - 1: OPEN
|
|
271
|
+
* - 2: CLOSING
|
|
272
|
+
* - 3: CLOSED
|
|
273
|
+
*/
|
|
274
|
+
readonly readyState: number;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Options for the serve() function.
|
|
279
|
+
*
|
|
280
|
+
* @typeParam T - The type of data associated with WebSocket connections
|
|
281
|
+
*/
|
|
282
|
+
interface ServeOptions<T = unknown> {
|
|
283
|
+
/**
|
|
284
|
+
* Handler for HTTP requests.
|
|
285
|
+
*
|
|
286
|
+
* @param request - The incoming HTTP request
|
|
287
|
+
* @param server - Server interface for WebSocket upgrades
|
|
288
|
+
* @returns Response or Promise resolving to Response
|
|
289
|
+
*/
|
|
290
|
+
fetch(request: Request, server: Server): Response | Promise<Response>;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* WebSocket event handlers.
|
|
294
|
+
*/
|
|
295
|
+
websocket?: {
|
|
296
|
+
/**
|
|
297
|
+
* Called when a WebSocket connection is opened.
|
|
298
|
+
*
|
|
299
|
+
* @param ws - The WebSocket connection
|
|
300
|
+
*/
|
|
301
|
+
open?(ws: ServerWebSocket<T>): void | Promise<void>;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Called when a message is received.
|
|
305
|
+
*
|
|
306
|
+
* @param ws - The WebSocket connection
|
|
307
|
+
* @param message - The received message (string or ArrayBuffer)
|
|
308
|
+
*/
|
|
309
|
+
message?(
|
|
310
|
+
ws: ServerWebSocket<T>,
|
|
311
|
+
message: string | ArrayBuffer
|
|
312
|
+
): void | Promise<void>;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Called when the connection is closed.
|
|
316
|
+
*
|
|
317
|
+
* @param ws - The WebSocket connection
|
|
318
|
+
* @param code - The close code
|
|
319
|
+
* @param reason - The close reason
|
|
320
|
+
*/
|
|
321
|
+
close?(
|
|
322
|
+
ws: ServerWebSocket<T>,
|
|
323
|
+
code: number,
|
|
324
|
+
reason: string
|
|
325
|
+
): void | Promise<void>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Called when an error occurs.
|
|
329
|
+
*
|
|
330
|
+
* @param ws - The WebSocket connection
|
|
331
|
+
* @param error - The error that occurred
|
|
332
|
+
*/
|
|
333
|
+
error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Register an HTTP server handler in QuickJS.
|
|
339
|
+
*
|
|
340
|
+
* Only one serve() handler can be active at a time.
|
|
341
|
+
* Calling serve() again replaces the previous handler.
|
|
342
|
+
*
|
|
343
|
+
* @param options - Server configuration including fetch handler and optional WebSocket handlers
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* serve({
|
|
347
|
+
* fetch(request, server) {
|
|
348
|
+
* const url = new URL(request.url);
|
|
349
|
+
*
|
|
350
|
+
* if (url.pathname === "/ws") {
|
|
351
|
+
* if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {
|
|
352
|
+
* return new Response(null, { status: 101 });
|
|
353
|
+
* }
|
|
354
|
+
* }
|
|
355
|
+
*
|
|
356
|
+
* if (url.pathname === "/api/hello") {
|
|
357
|
+
* return Response.json({ message: "Hello!" });
|
|
358
|
+
* }
|
|
359
|
+
*
|
|
360
|
+
* return new Response("Not Found", { status: 404 });
|
|
361
|
+
* },
|
|
362
|
+
* websocket: {
|
|
363
|
+
* open(ws) {
|
|
364
|
+
* console.log("Connected at:", ws.data.connectedAt);
|
|
365
|
+
* },
|
|
366
|
+
* message(ws, message) {
|
|
367
|
+
* ws.send("Echo: " + message);
|
|
368
|
+
* },
|
|
369
|
+
* close(ws, code, reason) {
|
|
370
|
+
* console.log("Closed:", code, reason);
|
|
371
|
+
* }
|
|
372
|
+
* }
|
|
373
|
+
* });
|
|
374
|
+
*/
|
|
375
|
+
function serve<T = unknown>(options: ServeOptions<T>): void;
|
|
376
|
+
}
|
|
377
|
+
`;
|
|
378
|
+
var FS_TYPES = `/**
|
|
379
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-fs
|
|
380
|
+
*
|
|
381
|
+
* These types define the globals injected by setupFs() into a QuickJS context.
|
|
382
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* // Typecheck QuickJS code with file system access
|
|
386
|
+
* const root = await fs.getDirectory("/data");
|
|
387
|
+
* const fileHandle = await root.getFileHandle("config.json");
|
|
388
|
+
* const file = await fileHandle.getFile();
|
|
389
|
+
* const content = await file.text();
|
|
390
|
+
*/
|
|
391
|
+
|
|
392
|
+
export {};
|
|
393
|
+
|
|
394
|
+
declare global {
|
|
395
|
+
// ============================================
|
|
396
|
+
// fs namespace - QuickJS-specific entry point
|
|
397
|
+
// ============================================
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* File System namespace providing access to the file system.
|
|
401
|
+
* This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).
|
|
402
|
+
*/
|
|
403
|
+
namespace fs {
|
|
404
|
+
/**
|
|
405
|
+
* Get a directory handle for the given path.
|
|
406
|
+
*
|
|
407
|
+
* The host controls which paths are accessible. Invalid or unauthorized
|
|
408
|
+
* paths will throw an error.
|
|
409
|
+
*
|
|
410
|
+
* @param path - The path to request from the host
|
|
411
|
+
* @returns A promise resolving to a directory handle
|
|
412
|
+
* @throws If the path is not allowed or doesn't exist
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* const root = await fs.getDirectory("/");
|
|
416
|
+
* const dataDir = await fs.getDirectory("/data");
|
|
417
|
+
*/
|
|
418
|
+
function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// ============================================
|
|
422
|
+
// File System Access API
|
|
423
|
+
// ============================================
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Base interface for file system handles.
|
|
427
|
+
*/
|
|
428
|
+
interface FileSystemHandle {
|
|
429
|
+
/**
|
|
430
|
+
* The kind of handle: "file" or "directory".
|
|
431
|
+
*/
|
|
432
|
+
readonly kind: "file" | "directory";
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The name of the file or directory.
|
|
436
|
+
*/
|
|
437
|
+
readonly name: string;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Compare two handles to check if they reference the same entry.
|
|
441
|
+
*
|
|
442
|
+
* @param other - Another FileSystemHandle to compare against
|
|
443
|
+
* @returns true if both handles reference the same entry
|
|
444
|
+
*/
|
|
445
|
+
isSameEntry(other: FileSystemHandle): Promise<boolean>;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Handle for a file in the file system.
|
|
450
|
+
*/
|
|
451
|
+
interface FileSystemFileHandle extends FileSystemHandle {
|
|
452
|
+
/**
|
|
453
|
+
* Always "file" for file handles.
|
|
454
|
+
*/
|
|
455
|
+
readonly kind: "file";
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Get the file contents as a File object.
|
|
459
|
+
*
|
|
460
|
+
* @returns A promise resolving to a File object
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* const file = await fileHandle.getFile();
|
|
464
|
+
* const text = await file.text();
|
|
465
|
+
*/
|
|
466
|
+
getFile(): Promise<File>;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Create a writable stream for writing to the file.
|
|
470
|
+
*
|
|
471
|
+
* @param options - Options for the writable stream
|
|
472
|
+
* @returns A promise resolving to a writable stream
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* const writable = await fileHandle.createWritable();
|
|
476
|
+
* await writable.write("Hello, World!");
|
|
477
|
+
* await writable.close();
|
|
478
|
+
*/
|
|
479
|
+
createWritable(options?: {
|
|
480
|
+
/**
|
|
481
|
+
* If true, keeps existing file data. Otherwise, truncates the file.
|
|
482
|
+
*/
|
|
483
|
+
keepExistingData?: boolean;
|
|
484
|
+
}): Promise<FileSystemWritableFileStream>;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Handle for a directory in the file system.
|
|
489
|
+
*/
|
|
490
|
+
interface FileSystemDirectoryHandle extends FileSystemHandle {
|
|
491
|
+
/**
|
|
492
|
+
* Always "directory" for directory handles.
|
|
493
|
+
*/
|
|
494
|
+
readonly kind: "directory";
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Get a file handle within this directory.
|
|
498
|
+
*
|
|
499
|
+
* @param name - The name of the file
|
|
500
|
+
* @param options - Options for getting the file handle
|
|
501
|
+
* @returns A promise resolving to a file handle
|
|
502
|
+
* @throws If the file doesn't exist and create is not true
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* const file = await dir.getFileHandle("data.json");
|
|
506
|
+
* const newFile = await dir.getFileHandle("output.txt", { create: true });
|
|
507
|
+
*/
|
|
508
|
+
getFileHandle(
|
|
509
|
+
name: string,
|
|
510
|
+
options?: {
|
|
511
|
+
/**
|
|
512
|
+
* If true, creates the file if it doesn't exist.
|
|
513
|
+
*/
|
|
514
|
+
create?: boolean;
|
|
515
|
+
}
|
|
516
|
+
): Promise<FileSystemFileHandle>;
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Get a subdirectory handle within this directory.
|
|
520
|
+
*
|
|
521
|
+
* @param name - The name of the subdirectory
|
|
522
|
+
* @param options - Options for getting the directory handle
|
|
523
|
+
* @returns A promise resolving to a directory handle
|
|
524
|
+
* @throws If the directory doesn't exist and create is not true
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* const subdir = await dir.getDirectoryHandle("logs");
|
|
528
|
+
* const newDir = await dir.getDirectoryHandle("cache", { create: true });
|
|
529
|
+
*/
|
|
530
|
+
getDirectoryHandle(
|
|
531
|
+
name: string,
|
|
532
|
+
options?: {
|
|
533
|
+
/**
|
|
534
|
+
* If true, creates the directory if it doesn't exist.
|
|
535
|
+
*/
|
|
536
|
+
create?: boolean;
|
|
537
|
+
}
|
|
538
|
+
): Promise<FileSystemDirectoryHandle>;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Remove a file or directory within this directory.
|
|
542
|
+
*
|
|
543
|
+
* @param name - The name of the entry to remove
|
|
544
|
+
* @param options - Options for removal
|
|
545
|
+
* @throws If the entry doesn't exist or cannot be removed
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* await dir.removeEntry("old-file.txt");
|
|
549
|
+
* await dir.removeEntry("old-dir", { recursive: true });
|
|
550
|
+
*/
|
|
551
|
+
removeEntry(
|
|
552
|
+
name: string,
|
|
553
|
+
options?: {
|
|
554
|
+
/**
|
|
555
|
+
* If true, removes directories recursively.
|
|
556
|
+
*/
|
|
557
|
+
recursive?: boolean;
|
|
558
|
+
}
|
|
559
|
+
): Promise<void>;
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Resolve the path from this directory to a descendant handle.
|
|
563
|
+
*
|
|
564
|
+
* @param possibleDescendant - A handle that may be a descendant
|
|
565
|
+
* @returns An array of path segments, or null if not a descendant
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* const path = await root.resolve(nestedFile);
|
|
569
|
+
* // ["subdir", "file.txt"]
|
|
570
|
+
*/
|
|
571
|
+
resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Iterate over entries in this directory.
|
|
575
|
+
*
|
|
576
|
+
* @returns An async iterator of [name, handle] pairs
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* for await (const [name, handle] of dir.entries()) {
|
|
580
|
+
* console.log(name, handle.kind);
|
|
581
|
+
* }
|
|
582
|
+
*/
|
|
583
|
+
entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Iterate over entry names in this directory.
|
|
587
|
+
*
|
|
588
|
+
* @returns An async iterator of names
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* for await (const name of dir.keys()) {
|
|
592
|
+
* console.log(name);
|
|
593
|
+
* }
|
|
594
|
+
*/
|
|
595
|
+
keys(): AsyncIterableIterator<string>;
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Iterate over handles in this directory.
|
|
599
|
+
*
|
|
600
|
+
* @returns An async iterator of handles
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* for await (const handle of dir.values()) {
|
|
604
|
+
* console.log(handle.name, handle.kind);
|
|
605
|
+
* }
|
|
606
|
+
*/
|
|
607
|
+
values(): AsyncIterableIterator<FileSystemHandle>;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Async iterator support for directory entries.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* for await (const [name, handle] of dir) {
|
|
614
|
+
* console.log(name, handle.kind);
|
|
615
|
+
* }
|
|
616
|
+
*/
|
|
617
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Parameters for write operations on FileSystemWritableFileStream.
|
|
622
|
+
*/
|
|
623
|
+
interface WriteParams {
|
|
624
|
+
/**
|
|
625
|
+
* The type of write operation.
|
|
626
|
+
* - "write": Write data at the current position or specified position
|
|
627
|
+
* - "seek": Move the file position
|
|
628
|
+
* - "truncate": Truncate the file to a specific size
|
|
629
|
+
*/
|
|
630
|
+
type: "write" | "seek" | "truncate";
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* The data to write (for "write" type).
|
|
634
|
+
*/
|
|
635
|
+
data?: string | ArrayBuffer | Uint8Array | Blob;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* The position to write at or seek to.
|
|
639
|
+
*/
|
|
640
|
+
position?: number;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* The size to truncate to (for "truncate" type).
|
|
644
|
+
*/
|
|
645
|
+
size?: number;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Writable stream for writing to a file.
|
|
650
|
+
* Extends WritableStream with file-specific operations.
|
|
651
|
+
*/
|
|
652
|
+
interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {
|
|
653
|
+
/**
|
|
654
|
+
* Write data to the file.
|
|
655
|
+
*
|
|
656
|
+
* @param data - The data to write
|
|
657
|
+
* @returns A promise that resolves when the write completes
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* await writable.write("Hello, World!");
|
|
661
|
+
* await writable.write(new Uint8Array([1, 2, 3]));
|
|
662
|
+
* await writable.write({ type: "write", data: "text", position: 0 });
|
|
663
|
+
*/
|
|
664
|
+
write(
|
|
665
|
+
data: string | ArrayBuffer | Uint8Array | Blob | WriteParams
|
|
666
|
+
): Promise<void>;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Seek to a position in the file.
|
|
670
|
+
*
|
|
671
|
+
* @param position - The byte position to seek to
|
|
672
|
+
* @returns A promise that resolves when the seek completes
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* await writable.seek(0); // Seek to beginning
|
|
676
|
+
* await writable.write("Overwrite");
|
|
677
|
+
*/
|
|
678
|
+
seek(position: number): Promise<void>;
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Truncate the file to a specific size.
|
|
682
|
+
*
|
|
683
|
+
* @param size - The size to truncate to
|
|
684
|
+
* @returns A promise that resolves when the truncation completes
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* await writable.truncate(100); // Keep only first 100 bytes
|
|
688
|
+
*/
|
|
689
|
+
truncate(size: number): Promise<void>;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
`;
|
|
693
|
+
var TYPE_DEFINITIONS = {
|
|
694
|
+
core: CORE_TYPES,
|
|
695
|
+
fetch: FETCH_TYPES,
|
|
696
|
+
fs: FS_TYPES
|
|
697
|
+
};
|
|
698
|
+
})
|
|
699
|
+
|
|
700
|
+
//# debugId=AAA1920C2BB7D8E964756E2164756E21
|