@ricsam/isolate-types 0.0.1 → 0.1.2

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.
@@ -0,0 +1,1748 @@
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/isolate-types/src/isolate-types.ts
31
+ var exports_isolate_types = {};
32
+ __export(exports_isolate_types, {
33
+ TYPE_DEFINITIONS: () => TYPE_DEFINITIONS,
34
+ TIMERS_TYPES: () => TIMERS_TYPES,
35
+ TEST_ENV_TYPES: () => TEST_ENV_TYPES,
36
+ PATH_TYPES: () => PATH_TYPES,
37
+ FS_TYPES: () => FS_TYPES,
38
+ FETCH_TYPES: () => FETCH_TYPES,
39
+ ENCODING_TYPES: () => ENCODING_TYPES,
40
+ CRYPTO_TYPES: () => CRYPTO_TYPES,
41
+ CORE_TYPES: () => CORE_TYPES,
42
+ CONSOLE_TYPES: () => CONSOLE_TYPES
43
+ });
44
+ module.exports = __toCommonJS(exports_isolate_types);
45
+ var CORE_TYPES = `/**
46
+ * Global Type Definitions for @ricsam/isolate-core
47
+ *
48
+ * These types define the globals injected by setupCore() into an isolated-vm context.
49
+ * Use these types to typecheck user code that will run inside the V8 isolate.
50
+ *
51
+ * @example
52
+ * // In your tsconfig.isolate.json
53
+ * {
54
+ * "compilerOptions": {
55
+ * "lib": ["ESNext", "DOM"]
56
+ * }
57
+ * }
58
+ *
59
+ * // Then reference this file or use ts-morph for code strings
60
+ */
61
+
62
+ export {};
63
+
64
+ declare global {
65
+ // ============================================
66
+ // Web Streams API
67
+ // ============================================
68
+
69
+ /**
70
+ * A readable stream of data.
71
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
72
+ */
73
+ const ReadableStream: typeof globalThis.ReadableStream;
74
+
75
+ /**
76
+ * A writable stream of data.
77
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream
78
+ */
79
+ const WritableStream: typeof globalThis.WritableStream;
80
+
81
+ /**
82
+ * A transform stream that can be used to pipe data through a transformer.
83
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream
84
+ */
85
+ const TransformStream: typeof globalThis.TransformStream;
86
+
87
+ /**
88
+ * Default reader for ReadableStream
89
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader
90
+ */
91
+ const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;
92
+
93
+ /**
94
+ * Default writer for WritableStream
95
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter
96
+ */
97
+ const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;
98
+
99
+ // ============================================
100
+ // Blob and File APIs
101
+ // ============================================
102
+
103
+ /**
104
+ * A file-like object of immutable, raw data.
105
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob
106
+ */
107
+ const Blob: typeof globalThis.Blob;
108
+
109
+ /**
110
+ * A file object representing a file.
111
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/File
112
+ */
113
+ const File: typeof globalThis.File;
114
+
115
+ // ============================================
116
+ // URL APIs
117
+ // ============================================
118
+
119
+ /**
120
+ * Interface for URL manipulation.
121
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/URL
122
+ */
123
+ const URL: typeof globalThis.URL;
124
+
125
+ /**
126
+ * Utility for working with URL query strings.
127
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
128
+ */
129
+ const URLSearchParams: typeof globalThis.URLSearchParams;
130
+
131
+ // ============================================
132
+ // Error Handling
133
+ // ============================================
134
+
135
+ /**
136
+ * Exception type for DOM operations.
137
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException
138
+ */
139
+ const DOMException: typeof globalThis.DOMException;
140
+ }
141
+ `;
142
+ var FETCH_TYPES = `/**
143
+ * Global Type Definitions for @ricsam/isolate-fetch
144
+ *
145
+ * These types define the globals injected by setupFetch() into an isolated-vm context.
146
+ * Use these types to typecheck user code that will run inside the V8 isolate.
147
+ *
148
+ * @example
149
+ * // Typecheck isolate code with serve()
150
+ * type WebSocketData = { id: number; connectedAt: number };
151
+ *
152
+ * serve({
153
+ * fetch(request, server) {
154
+ * if (request.url.includes("/ws")) {
155
+ * // server.upgrade knows data should be WebSocketData
156
+ * server.upgrade(request, { data: { id: 123, connectedAt: Date.now() } });
157
+ * return new Response(null, { status: 101 });
158
+ * }
159
+ * return new Response("Hello!");
160
+ * },
161
+ * websocket: {
162
+ * // Type hint - specifies the type of ws.data
163
+ * data: {} as WebSocketData,
164
+ * message(ws, message) {
165
+ * // ws.data is typed as WebSocketData
166
+ * console.log("User", ws.data.id, "says:", message);
167
+ * ws.send("Echo: " + message);
168
+ * }
169
+ * }
170
+ * });
171
+ */
172
+
173
+ export {};
174
+
175
+ declare global {
176
+ // ============================================
177
+ // Standard Fetch API (from lib.dom)
178
+ // ============================================
179
+
180
+ /**
181
+ * Headers class for HTTP headers manipulation.
182
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
183
+ */
184
+ const Headers: typeof globalThis.Headers;
185
+
186
+ /**
187
+ * Request class for HTTP requests.
188
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Request
189
+ */
190
+ const Request: typeof globalThis.Request;
191
+
192
+ /**
193
+ * Response class for HTTP responses.
194
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Response
195
+ */
196
+ const Response: typeof globalThis.Response;
197
+
198
+ /**
199
+ * AbortController for cancelling fetch requests.
200
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController
201
+ */
202
+ const AbortController: typeof globalThis.AbortController;
203
+
204
+ /**
205
+ * AbortSignal for listening to abort events.
206
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
207
+ */
208
+ const AbortSignal: typeof globalThis.AbortSignal;
209
+
210
+ /**
211
+ * FormData for constructing form data.
212
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData
213
+ */
214
+ const FormData: typeof globalThis.FormData;
215
+
216
+ /**
217
+ * Fetch function for making HTTP requests.
218
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch
219
+ */
220
+ function fetch(
221
+ input: RequestInfo | URL,
222
+ init?: RequestInit
223
+ ): Promise<Response>;
224
+
225
+ // ============================================
226
+ // Isolate-specific: serve() API
227
+ // ============================================
228
+
229
+ /**
230
+ * Server interface for handling WebSocket upgrades within serve() handlers.
231
+ *
232
+ * @typeParam T - The type of data associated with WebSocket connections
233
+ */
234
+ interface Server<T = unknown> {
235
+ /**
236
+ * Upgrade an HTTP request to a WebSocket connection.
237
+ *
238
+ * @param request - The incoming HTTP request to upgrade
239
+ * @param options - Optional data to associate with the WebSocket connection
240
+ * @returns true if upgrade will proceed, false otherwise
241
+ *
242
+ * @example
243
+ * serve({
244
+ * fetch(request, server) {
245
+ * if (server.upgrade(request, { data: { userId: 123 } })) {
246
+ * return new Response(null, { status: 101 });
247
+ * }
248
+ * return new Response("Upgrade failed", { status: 400 });
249
+ * }
250
+ * });
251
+ */
252
+ upgrade(request: Request, options?: { data?: T }): boolean;
253
+ }
254
+
255
+ /**
256
+ * ServerWebSocket interface for WebSocket connections within serve() handlers.
257
+ *
258
+ * @typeParam T - The type of data associated with this WebSocket connection
259
+ */
260
+ interface ServerWebSocket<T = unknown> {
261
+ /**
262
+ * User data associated with this connection.
263
+ * Set via \`server.upgrade(request, { data: ... })\`.
264
+ */
265
+ readonly data: T;
266
+
267
+ /**
268
+ * Send a message to the client.
269
+ *
270
+ * @param message - The message to send (string, ArrayBuffer, or Uint8Array)
271
+ */
272
+ send(message: string | ArrayBuffer | Uint8Array): void;
273
+
274
+ /**
275
+ * Close the WebSocket connection.
276
+ *
277
+ * @param code - Optional close code (default: 1000)
278
+ * @param reason - Optional close reason
279
+ */
280
+ close(code?: number, reason?: string): void;
281
+
282
+ /**
283
+ * WebSocket ready state.
284
+ * - 0: CONNECTING
285
+ * - 1: OPEN
286
+ * - 2: CLOSING
287
+ * - 3: CLOSED
288
+ */
289
+ readonly readyState: number;
290
+ }
291
+
292
+ /**
293
+ * Options for the serve() function.
294
+ *
295
+ * @typeParam T - The type of data associated with WebSocket connections
296
+ */
297
+ interface ServeOptions<T = unknown> {
298
+ /**
299
+ * Handler for HTTP requests.
300
+ *
301
+ * @param request - The incoming HTTP request
302
+ * @param server - Server interface for WebSocket upgrades
303
+ * @returns Response or Promise resolving to Response
304
+ */
305
+ fetch(request: Request, server: Server<T>): Response | Promise<Response>;
306
+
307
+ /**
308
+ * WebSocket event handlers.
309
+ */
310
+ websocket?: {
311
+ /**
312
+ * Type hint for WebSocket data. The value is not used at runtime.
313
+ * Specifies the type of \`ws.data\` for all handlers and \`server.upgrade()\`.
314
+ *
315
+ * @example
316
+ * websocket: {
317
+ * data: {} as { userId: string },
318
+ * message(ws, message) {
319
+ * // ws.data.userId is typed as string
320
+ * }
321
+ * }
322
+ */
323
+ data?: T;
324
+
325
+ /**
326
+ * Called when a WebSocket connection is opened.
327
+ *
328
+ * @param ws - The WebSocket connection
329
+ */
330
+ open?(ws: ServerWebSocket<T>): void | Promise<void>;
331
+
332
+ /**
333
+ * Called when a message is received.
334
+ *
335
+ * @param ws - The WebSocket connection
336
+ * @param message - The received message (string or ArrayBuffer)
337
+ */
338
+ message?(
339
+ ws: ServerWebSocket<T>,
340
+ message: string | ArrayBuffer
341
+ ): void | Promise<void>;
342
+
343
+ /**
344
+ * Called when the connection is closed.
345
+ *
346
+ * @param ws - The WebSocket connection
347
+ * @param code - The close code
348
+ * @param reason - The close reason
349
+ */
350
+ close?(
351
+ ws: ServerWebSocket<T>,
352
+ code: number,
353
+ reason: string
354
+ ): void | Promise<void>;
355
+
356
+ /**
357
+ * Called when an error occurs.
358
+ *
359
+ * @param ws - The WebSocket connection
360
+ * @param error - The error that occurred
361
+ */
362
+ error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;
363
+ };
364
+ }
365
+
366
+ /**
367
+ * Register an HTTP server handler in the isolate.
368
+ *
369
+ * Only one serve() handler can be active at a time.
370
+ * Calling serve() again replaces the previous handler.
371
+ *
372
+ * @param options - Server configuration including fetch handler and optional WebSocket handlers
373
+ *
374
+ * @example
375
+ * type WsData = { connectedAt: number };
376
+ *
377
+ * serve({
378
+ * fetch(request, server) {
379
+ * const url = new URL(request.url);
380
+ *
381
+ * if (url.pathname === "/ws") {
382
+ * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {
383
+ * return new Response(null, { status: 101 });
384
+ * }
385
+ * }
386
+ *
387
+ * if (url.pathname === "/api/hello") {
388
+ * return Response.json({ message: "Hello!" });
389
+ * }
390
+ *
391
+ * return new Response("Not Found", { status: 404 });
392
+ * },
393
+ * websocket: {
394
+ * data: {} as WsData,
395
+ * open(ws) {
396
+ * console.log("Connected at:", ws.data.connectedAt);
397
+ * },
398
+ * message(ws, message) {
399
+ * ws.send("Echo: " + message);
400
+ * },
401
+ * close(ws, code, reason) {
402
+ * console.log("Closed:", code, reason);
403
+ * }
404
+ * }
405
+ * });
406
+ */
407
+ function serve<T = unknown>(options: ServeOptions<T>): void;
408
+ }
409
+ `;
410
+ var FS_TYPES = `/**
411
+ * Global Type Definitions for @ricsam/isolate-fs
412
+ *
413
+ * These types define the globals injected by setupFs() into an isolated-vm context.
414
+ * Use these types to typecheck user code that will run inside the V8 isolate.
415
+ *
416
+ * @example
417
+ * // Typecheck isolate code with file system access
418
+ * const root = await getDirectory("/data");
419
+ * const fileHandle = await root.getFileHandle("config.json");
420
+ * const file = await fileHandle.getFile();
421
+ * const content = await file.text();
422
+ */
423
+
424
+ export {};
425
+
426
+ declare global {
427
+ // ============================================
428
+ // getDirectory - Isolate-specific entry point
429
+ // ============================================
430
+
431
+ /**
432
+ * Get a directory handle for the given path.
433
+ *
434
+ * The host controls which paths are accessible. Invalid or unauthorized
435
+ * paths will throw an error.
436
+ *
437
+ * @param path - The path to request from the host
438
+ * @returns A promise resolving to a directory handle
439
+ * @throws If the path is not allowed or doesn't exist
440
+ *
441
+ * @example
442
+ * const root = await getDirectory("/");
443
+ * const dataDir = await getDirectory("/data");
444
+ */
445
+ function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;
446
+
447
+ // ============================================
448
+ // File System Access API
449
+ // ============================================
450
+
451
+ /**
452
+ * Base interface for file system handles.
453
+ */
454
+ interface FileSystemHandle {
455
+ /**
456
+ * The kind of handle: "file" or "directory".
457
+ */
458
+ readonly kind: "file" | "directory";
459
+
460
+ /**
461
+ * The name of the file or directory.
462
+ */
463
+ readonly name: string;
464
+
465
+ /**
466
+ * Compare two handles to check if they reference the same entry.
467
+ *
468
+ * @param other - Another FileSystemHandle to compare against
469
+ * @returns true if both handles reference the same entry
470
+ */
471
+ isSameEntry(other: FileSystemHandle): Promise<boolean>;
472
+ }
473
+
474
+ /**
475
+ * Handle for a file in the file system.
476
+ */
477
+ interface FileSystemFileHandle extends FileSystemHandle {
478
+ /**
479
+ * Always "file" for file handles.
480
+ */
481
+ readonly kind: "file";
482
+
483
+ /**
484
+ * Get the file contents as a File object.
485
+ *
486
+ * @returns A promise resolving to a File object
487
+ *
488
+ * @example
489
+ * const file = await fileHandle.getFile();
490
+ * const text = await file.text();
491
+ */
492
+ getFile(): Promise<File>;
493
+
494
+ /**
495
+ * Create a writable stream for writing to the file.
496
+ *
497
+ * @param options - Options for the writable stream
498
+ * @returns A promise resolving to a writable stream
499
+ *
500
+ * @example
501
+ * const writable = await fileHandle.createWritable();
502
+ * await writable.write("Hello, World!");
503
+ * await writable.close();
504
+ */
505
+ createWritable(options?: {
506
+ /**
507
+ * If true, keeps existing file data. Otherwise, truncates the file.
508
+ */
509
+ keepExistingData?: boolean;
510
+ }): Promise<FileSystemWritableFileStream>;
511
+ }
512
+
513
+ /**
514
+ * Handle for a directory in the file system.
515
+ */
516
+ interface FileSystemDirectoryHandle extends FileSystemHandle {
517
+ /**
518
+ * Always "directory" for directory handles.
519
+ */
520
+ readonly kind: "directory";
521
+
522
+ /**
523
+ * Get a file handle within this directory.
524
+ *
525
+ * @param name - The name of the file
526
+ * @param options - Options for getting the file handle
527
+ * @returns A promise resolving to a file handle
528
+ * @throws If the file doesn't exist and create is not true
529
+ *
530
+ * @example
531
+ * const file = await dir.getFileHandle("data.json");
532
+ * const newFile = await dir.getFileHandle("output.txt", { create: true });
533
+ */
534
+ getFileHandle(
535
+ name: string,
536
+ options?: {
537
+ /**
538
+ * If true, creates the file if it doesn't exist.
539
+ */
540
+ create?: boolean;
541
+ }
542
+ ): Promise<FileSystemFileHandle>;
543
+
544
+ /**
545
+ * Get a subdirectory handle within this directory.
546
+ *
547
+ * @param name - The name of the subdirectory
548
+ * @param options - Options for getting the directory handle
549
+ * @returns A promise resolving to a directory handle
550
+ * @throws If the directory doesn't exist and create is not true
551
+ *
552
+ * @example
553
+ * const subdir = await dir.getDirectoryHandle("logs");
554
+ * const newDir = await dir.getDirectoryHandle("cache", { create: true });
555
+ */
556
+ getDirectoryHandle(
557
+ name: string,
558
+ options?: {
559
+ /**
560
+ * If true, creates the directory if it doesn't exist.
561
+ */
562
+ create?: boolean;
563
+ }
564
+ ): Promise<FileSystemDirectoryHandle>;
565
+
566
+ /**
567
+ * Remove a file or directory within this directory.
568
+ *
569
+ * @param name - The name of the entry to remove
570
+ * @param options - Options for removal
571
+ * @throws If the entry doesn't exist or cannot be removed
572
+ *
573
+ * @example
574
+ * await dir.removeEntry("old-file.txt");
575
+ * await dir.removeEntry("old-dir", { recursive: true });
576
+ */
577
+ removeEntry(
578
+ name: string,
579
+ options?: {
580
+ /**
581
+ * If true, removes directories recursively.
582
+ */
583
+ recursive?: boolean;
584
+ }
585
+ ): Promise<void>;
586
+
587
+ /**
588
+ * Resolve the path from this directory to a descendant handle.
589
+ *
590
+ * @param possibleDescendant - A handle that may be a descendant
591
+ * @returns An array of path segments, or null if not a descendant
592
+ *
593
+ * @example
594
+ * const path = await root.resolve(nestedFile);
595
+ * // ["subdir", "file.txt"]
596
+ */
597
+ resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;
598
+
599
+ /**
600
+ * Iterate over entries in this directory.
601
+ *
602
+ * @returns An async iterator of [name, handle] pairs
603
+ *
604
+ * @example
605
+ * for await (const [name, handle] of dir.entries()) {
606
+ * console.log(name, handle.kind);
607
+ * }
608
+ */
609
+ entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
610
+
611
+ /**
612
+ * Iterate over entry names in this directory.
613
+ *
614
+ * @returns An async iterator of names
615
+ *
616
+ * @example
617
+ * for await (const name of dir.keys()) {
618
+ * console.log(name);
619
+ * }
620
+ */
621
+ keys(): AsyncIterableIterator<string>;
622
+
623
+ /**
624
+ * Iterate over handles in this directory.
625
+ *
626
+ * @returns An async iterator of handles
627
+ *
628
+ * @example
629
+ * for await (const handle of dir.values()) {
630
+ * console.log(handle.name, handle.kind);
631
+ * }
632
+ */
633
+ values(): AsyncIterableIterator<FileSystemHandle>;
634
+
635
+ /**
636
+ * Async iterator support for directory entries.
637
+ *
638
+ * @example
639
+ * for await (const [name, handle] of dir) {
640
+ * console.log(name, handle.kind);
641
+ * }
642
+ */
643
+ [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;
644
+ }
645
+
646
+ /**
647
+ * Parameters for write operations on FileSystemWritableFileStream.
648
+ */
649
+ interface WriteParams {
650
+ /**
651
+ * The type of write operation.
652
+ * - "write": Write data at the current position or specified position
653
+ * - "seek": Move the file position
654
+ * - "truncate": Truncate the file to a specific size
655
+ */
656
+ type: "write" | "seek" | "truncate";
657
+
658
+ /**
659
+ * The data to write (for "write" type).
660
+ */
661
+ data?: string | ArrayBuffer | Uint8Array | Blob;
662
+
663
+ /**
664
+ * The position to write at or seek to.
665
+ */
666
+ position?: number;
667
+
668
+ /**
669
+ * The size to truncate to (for "truncate" type).
670
+ */
671
+ size?: number;
672
+ }
673
+
674
+ /**
675
+ * Writable stream for writing to a file.
676
+ * Extends WritableStream with file-specific operations.
677
+ */
678
+ interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {
679
+ /**
680
+ * Write data to the file.
681
+ *
682
+ * @param data - The data to write
683
+ * @returns A promise that resolves when the write completes
684
+ *
685
+ * @example
686
+ * await writable.write("Hello, World!");
687
+ * await writable.write(new Uint8Array([1, 2, 3]));
688
+ * await writable.write({ type: "write", data: "text", position: 0 });
689
+ */
690
+ write(
691
+ data: string | ArrayBuffer | Uint8Array | Blob | WriteParams
692
+ ): Promise<void>;
693
+
694
+ /**
695
+ * Seek to a position in the file.
696
+ *
697
+ * @param position - The byte position to seek to
698
+ * @returns A promise that resolves when the seek completes
699
+ *
700
+ * @example
701
+ * await writable.seek(0); // Seek to beginning
702
+ * await writable.write("Overwrite");
703
+ */
704
+ seek(position: number): Promise<void>;
705
+
706
+ /**
707
+ * Truncate the file to a specific size.
708
+ *
709
+ * @param size - The size to truncate to
710
+ * @returns A promise that resolves when the truncation completes
711
+ *
712
+ * @example
713
+ * await writable.truncate(100); // Keep only first 100 bytes
714
+ */
715
+ truncate(size: number): Promise<void>;
716
+ }
717
+ }
718
+ `;
719
+ var TEST_ENV_TYPES = `/**
720
+ * Global Type Definitions for @ricsam/isolate-test-environment
721
+ *
722
+ * These types define the globals injected by setupTestEnvironment() into an isolated-vm context.
723
+ * Use these types to typecheck user code that will run inside the V8 isolate.
724
+ *
725
+ * @example
726
+ * describe("Math operations", () => {
727
+ * it("should add numbers", () => {
728
+ * expect(1 + 1).toBe(2);
729
+ * });
730
+ * });
731
+ */
732
+
733
+ export {};
734
+
735
+ declare global {
736
+ // ============================================
737
+ // Test Structure
738
+ // ============================================
739
+
740
+ /**
741
+ * Define a test suite.
742
+ *
743
+ * @param name - The name of the test suite
744
+ * @param fn - Function containing tests and nested suites
745
+ *
746
+ * @example
747
+ * describe("Calculator", () => {
748
+ * it("adds numbers", () => {
749
+ * expect(1 + 1).toBe(2);
750
+ * });
751
+ * });
752
+ */
753
+ function describe(name: string, fn: () => void): void;
754
+
755
+ namespace describe {
756
+ /**
757
+ * Skip this suite and all its tests.
758
+ */
759
+ function skip(name: string, fn: () => void): void;
760
+
761
+ /**
762
+ * Only run this suite (and other .only suites).
763
+ */
764
+ function only(name: string, fn: () => void): void;
765
+
766
+ /**
767
+ * Mark suite as todo (skipped with different status).
768
+ */
769
+ function todo(name: string, fn?: () => void): void;
770
+ }
771
+
772
+ /**
773
+ * Define a test case.
774
+ *
775
+ * @param name - The name of the test
776
+ * @param fn - The test function (can be async)
777
+ *
778
+ * @example
779
+ * it("should work", () => {
780
+ * expect(true).toBe(true);
781
+ * });
782
+ *
783
+ * it("should work async", async () => {
784
+ * const result = await Promise.resolve(42);
785
+ * expect(result).toBe(42);
786
+ * });
787
+ */
788
+ function it(name: string, fn: () => void | Promise<void>): void;
789
+
790
+ namespace it {
791
+ /**
792
+ * Skip this test.
793
+ */
794
+ function skip(name: string, fn?: () => void | Promise<void>): void;
795
+
796
+ /**
797
+ * Only run this test (and other .only tests).
798
+ */
799
+ function only(name: string, fn: () => void | Promise<void>): void;
800
+
801
+ /**
802
+ * Mark test as todo.
803
+ */
804
+ function todo(name: string, fn?: () => void | Promise<void>): void;
805
+ }
806
+
807
+ /**
808
+ * Alias for it().
809
+ */
810
+ function test(name: string, fn: () => void | Promise<void>): void;
811
+
812
+ namespace test {
813
+ /**
814
+ * Skip this test.
815
+ */
816
+ function skip(name: string, fn?: () => void | Promise<void>): void;
817
+
818
+ /**
819
+ * Only run this test (and other .only tests).
820
+ */
821
+ function only(name: string, fn: () => void | Promise<void>): void;
822
+
823
+ /**
824
+ * Mark test as todo.
825
+ */
826
+ function todo(name: string, fn?: () => void | Promise<void>): void;
827
+ }
828
+
829
+ // ============================================
830
+ // Lifecycle Hooks
831
+ // ============================================
832
+
833
+ /**
834
+ * Run once before all tests in the current suite.
835
+ *
836
+ * @param fn - Setup function (can be async)
837
+ */
838
+ function beforeAll(fn: () => void | Promise<void>): void;
839
+
840
+ /**
841
+ * Run once after all tests in the current suite.
842
+ *
843
+ * @param fn - Teardown function (can be async)
844
+ */
845
+ function afterAll(fn: () => void | Promise<void>): void;
846
+
847
+ /**
848
+ * Run before each test in the current suite (and nested suites).
849
+ *
850
+ * @param fn - Setup function (can be async)
851
+ */
852
+ function beforeEach(fn: () => void | Promise<void>): void;
853
+
854
+ /**
855
+ * Run after each test in the current suite (and nested suites).
856
+ *
857
+ * @param fn - Teardown function (can be async)
858
+ */
859
+ function afterEach(fn: () => void | Promise<void>): void;
860
+
861
+ // ============================================
862
+ // Assertions
863
+ // ============================================
864
+
865
+ /**
866
+ * Matchers for assertions.
867
+ */
868
+ interface Matchers<T> {
869
+ /**
870
+ * Strict equality (===).
871
+ */
872
+ toBe(expected: T): void;
873
+
874
+ /**
875
+ * Deep equality.
876
+ */
877
+ toEqual(expected: unknown): void;
878
+
879
+ /**
880
+ * Deep equality with type checking.
881
+ */
882
+ toStrictEqual(expected: unknown): void;
883
+
884
+ /**
885
+ * Check if value is truthy.
886
+ */
887
+ toBeTruthy(): void;
888
+
889
+ /**
890
+ * Check if value is falsy.
891
+ */
892
+ toBeFalsy(): void;
893
+
894
+ /**
895
+ * Check if value is null.
896
+ */
897
+ toBeNull(): void;
898
+
899
+ /**
900
+ * Check if value is undefined.
901
+ */
902
+ toBeUndefined(): void;
903
+
904
+ /**
905
+ * Check if value is defined (not undefined).
906
+ */
907
+ toBeDefined(): void;
908
+
909
+ /**
910
+ * Check if value is NaN.
911
+ */
912
+ toBeNaN(): void;
913
+
914
+ /**
915
+ * Check if number is greater than expected.
916
+ */
917
+ toBeGreaterThan(n: number): void;
918
+
919
+ /**
920
+ * Check if number is greater than or equal to expected.
921
+ */
922
+ toBeGreaterThanOrEqual(n: number): void;
923
+
924
+ /**
925
+ * Check if number is less than expected.
926
+ */
927
+ toBeLessThan(n: number): void;
928
+
929
+ /**
930
+ * Check if number is less than or equal to expected.
931
+ */
932
+ toBeLessThanOrEqual(n: number): void;
933
+
934
+ /**
935
+ * Check if array/string contains item/substring.
936
+ */
937
+ toContain(item: unknown): void;
938
+
939
+ /**
940
+ * Check length of array/string.
941
+ */
942
+ toHaveLength(length: number): void;
943
+
944
+ /**
945
+ * Check if object has property (optionally with value).
946
+ */
947
+ toHaveProperty(key: string, value?: unknown): void;
948
+
949
+ /**
950
+ * Check if function throws.
951
+ */
952
+ toThrow(expected?: string | RegExp | Error): void;
953
+
954
+ /**
955
+ * Check if string matches pattern.
956
+ */
957
+ toMatch(pattern: string | RegExp): void;
958
+
959
+ /**
960
+ * Check if object matches subset of properties.
961
+ */
962
+ toMatchObject(object: object): void;
963
+
964
+ /**
965
+ * Check if value is instance of class.
966
+ */
967
+ toBeInstanceOf(constructor: Function): void;
968
+
969
+ /**
970
+ * Negate the matcher.
971
+ */
972
+ not: Matchers<T>;
973
+
974
+ /**
975
+ * Await promise and check resolved value.
976
+ */
977
+ resolves: Matchers<Awaited<T>>;
978
+
979
+ /**
980
+ * Await promise and check rejection.
981
+ */
982
+ rejects: Matchers<unknown>;
983
+ }
984
+
985
+ /**
986
+ * Create an expectation for a value.
987
+ *
988
+ * @param actual - The value to test
989
+ * @returns Matchers for the value
990
+ *
991
+ * @example
992
+ * expect(1 + 1).toBe(2);
993
+ * expect({ a: 1 }).toEqual({ a: 1 });
994
+ * expect(() => { throw new Error(); }).toThrow();
995
+ * expect(promise).resolves.toBe(42);
996
+ */
997
+ function expect<T>(actual: T): Matchers<T>;
998
+ }
999
+ `;
1000
+ var CONSOLE_TYPES = `/**
1001
+ * Global Type Definitions for @ricsam/isolate-console
1002
+ *
1003
+ * These types define the globals injected by setupConsole() into an isolated-vm context.
1004
+ * Use these types to typecheck user code that will run inside the V8 isolate.
1005
+ */
1006
+
1007
+ export {};
1008
+
1009
+ declare global {
1010
+ /**
1011
+ * Console interface for logging and debugging.
1012
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Console
1013
+ */
1014
+ interface Console {
1015
+ /**
1016
+ * Log a message to the console.
1017
+ * @param data - Values to log
1018
+ */
1019
+ log(...data: unknown[]): void;
1020
+
1021
+ /**
1022
+ * Log a warning message.
1023
+ * @param data - Values to log
1024
+ */
1025
+ warn(...data: unknown[]): void;
1026
+
1027
+ /**
1028
+ * Log an error message.
1029
+ * @param data - Values to log
1030
+ */
1031
+ error(...data: unknown[]): void;
1032
+
1033
+ /**
1034
+ * Log a debug message.
1035
+ * @param data - Values to log
1036
+ */
1037
+ debug(...data: unknown[]): void;
1038
+
1039
+ /**
1040
+ * Log an info message.
1041
+ * @param data - Values to log
1042
+ */
1043
+ info(...data: unknown[]): void;
1044
+
1045
+ /**
1046
+ * Log a stack trace.
1047
+ * @param data - Values to log with the trace
1048
+ */
1049
+ trace(...data: unknown[]): void;
1050
+
1051
+ /**
1052
+ * Display an object in a formatted way.
1053
+ * @param item - Object to display
1054
+ * @param options - Display options
1055
+ */
1056
+ dir(item: unknown, options?: object): void;
1057
+
1058
+ /**
1059
+ * Display tabular data.
1060
+ * @param tabularData - Data to display as a table
1061
+ * @param properties - Optional array of property names to include
1062
+ */
1063
+ table(tabularData: unknown, properties?: string[]): void;
1064
+
1065
+ /**
1066
+ * Start a timer.
1067
+ * @param label - Timer label (default: "default")
1068
+ */
1069
+ time(label?: string): void;
1070
+
1071
+ /**
1072
+ * End a timer and log the elapsed time.
1073
+ * @param label - Timer label (default: "default")
1074
+ */
1075
+ timeEnd(label?: string): void;
1076
+
1077
+ /**
1078
+ * Log the elapsed time of a timer without ending it.
1079
+ * @param label - Timer label (default: "default")
1080
+ * @param data - Additional values to log
1081
+ */
1082
+ timeLog(label?: string, ...data: unknown[]): void;
1083
+
1084
+ /**
1085
+ * Log an error if the assertion is false.
1086
+ * @param condition - Condition to test
1087
+ * @param data - Values to log if assertion fails
1088
+ */
1089
+ assert(condition?: boolean, ...data: unknown[]): void;
1090
+
1091
+ /**
1092
+ * Increment and log a counter.
1093
+ * @param label - Counter label (default: "default")
1094
+ */
1095
+ count(label?: string): void;
1096
+
1097
+ /**
1098
+ * Reset a counter.
1099
+ * @param label - Counter label (default: "default")
1100
+ */
1101
+ countReset(label?: string): void;
1102
+
1103
+ /**
1104
+ * Clear the console.
1105
+ */
1106
+ clear(): void;
1107
+
1108
+ /**
1109
+ * Start an inline group.
1110
+ * @param data - Group label
1111
+ */
1112
+ group(...data: unknown[]): void;
1113
+
1114
+ /**
1115
+ * Start a collapsed inline group.
1116
+ * @param data - Group label
1117
+ */
1118
+ groupCollapsed(...data: unknown[]): void;
1119
+
1120
+ /**
1121
+ * End the current inline group.
1122
+ */
1123
+ groupEnd(): void;
1124
+ }
1125
+
1126
+ /**
1127
+ * Console object for logging and debugging.
1128
+ */
1129
+ const console: Console;
1130
+ }
1131
+ `;
1132
+ var ENCODING_TYPES = `/**
1133
+ * Global Type Definitions for @ricsam/isolate-encoding
1134
+ *
1135
+ * These types define the globals injected by setupEncoding() into an isolated-vm context.
1136
+ * Use these types to typecheck user code that will run inside the V8 isolate.
1137
+ */
1138
+
1139
+ export {};
1140
+
1141
+ declare global {
1142
+ /**
1143
+ * Decodes a Base64-encoded string.
1144
+ *
1145
+ * @param encodedData - The Base64 string to decode
1146
+ * @returns The decoded string
1147
+ * @throws DOMException if the input is not valid Base64
1148
+ *
1149
+ * @example
1150
+ * atob("SGVsbG8="); // "Hello"
1151
+ */
1152
+ function atob(encodedData: string): string;
1153
+
1154
+ /**
1155
+ * Encodes a string to Base64.
1156
+ *
1157
+ * @param stringToEncode - The string to encode (must contain only Latin1 characters)
1158
+ * @returns The Base64 encoded string
1159
+ * @throws DOMException if the string contains characters outside Latin1 range (0-255)
1160
+ *
1161
+ * @example
1162
+ * btoa("Hello"); // "SGVsbG8="
1163
+ */
1164
+ function btoa(stringToEncode: string): string;
1165
+ }
1166
+ `;
1167
+ var CRYPTO_TYPES = `/**
1168
+ * Global Type Definitions for @ricsam/isolate-crypto
1169
+ *
1170
+ * These types define the globals injected by setupCrypto() into an isolated-vm context.
1171
+ * Use these types to typecheck user code that will run inside the V8 isolate.
1172
+ *
1173
+ * @example
1174
+ * // Generate random bytes
1175
+ * const arr = new Uint8Array(16);
1176
+ * crypto.getRandomValues(arr);
1177
+ *
1178
+ * // Generate UUID
1179
+ * const uuid = crypto.randomUUID();
1180
+ *
1181
+ * // Use SubtleCrypto
1182
+ * const key = await crypto.subtle.generateKey(
1183
+ * { name: "AES-GCM", length: 256 },
1184
+ * true,
1185
+ * ["encrypt", "decrypt"]
1186
+ * );
1187
+ */
1188
+
1189
+ export {};
1190
+
1191
+ declare global {
1192
+ /**
1193
+ * CryptoKey represents a cryptographic key.
1194
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey
1195
+ */
1196
+ interface CryptoKey {
1197
+ /**
1198
+ * The type of key: "public", "private", or "secret".
1199
+ */
1200
+ readonly type: "public" | "private" | "secret";
1201
+
1202
+ /**
1203
+ * Whether the key can be exported.
1204
+ */
1205
+ readonly extractable: boolean;
1206
+
1207
+ /**
1208
+ * The algorithm used by this key.
1209
+ */
1210
+ readonly algorithm: KeyAlgorithm;
1211
+
1212
+ /**
1213
+ * The usages allowed for this key.
1214
+ */
1215
+ readonly usages: ReadonlyArray<KeyUsage>;
1216
+ }
1217
+
1218
+ /**
1219
+ * CryptoKey constructor (keys cannot be constructed directly).
1220
+ */
1221
+ const CryptoKey: {
1222
+ prototype: CryptoKey;
1223
+ };
1224
+
1225
+ /**
1226
+ * SubtleCrypto interface for cryptographic operations.
1227
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto
1228
+ */
1229
+ interface SubtleCrypto {
1230
+ /**
1231
+ * Generate a digest (hash) of the given data.
1232
+ *
1233
+ * @param algorithm - Hash algorithm (e.g., "SHA-256", "SHA-384", "SHA-512")
1234
+ * @param data - Data to hash
1235
+ * @returns Promise resolving to the hash as ArrayBuffer
1236
+ */
1237
+ digest(
1238
+ algorithm: AlgorithmIdentifier,
1239
+ data: BufferSource
1240
+ ): Promise<ArrayBuffer>;
1241
+
1242
+ /**
1243
+ * Generate a new cryptographic key or key pair.
1244
+ *
1245
+ * @param algorithm - Key generation algorithm
1246
+ * @param extractable - Whether the key can be exported
1247
+ * @param keyUsages - Allowed key usages
1248
+ * @returns Promise resolving to a CryptoKey or CryptoKeyPair
1249
+ */
1250
+ generateKey(
1251
+ algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,
1252
+ extractable: boolean,
1253
+ keyUsages: KeyUsage[]
1254
+ ): Promise<CryptoKey | CryptoKeyPair>;
1255
+
1256
+ /**
1257
+ * Sign data using a private key.
1258
+ *
1259
+ * @param algorithm - Signing algorithm
1260
+ * @param key - Private key to sign with
1261
+ * @param data - Data to sign
1262
+ * @returns Promise resolving to the signature as ArrayBuffer
1263
+ */
1264
+ sign(
1265
+ algorithm: AlgorithmIdentifier,
1266
+ key: CryptoKey,
1267
+ data: BufferSource
1268
+ ): Promise<ArrayBuffer>;
1269
+
1270
+ /**
1271
+ * Verify a signature.
1272
+ *
1273
+ * @param algorithm - Signing algorithm
1274
+ * @param key - Public key to verify with
1275
+ * @param signature - Signature to verify
1276
+ * @param data - Data that was signed
1277
+ * @returns Promise resolving to true if valid, false otherwise
1278
+ */
1279
+ verify(
1280
+ algorithm: AlgorithmIdentifier,
1281
+ key: CryptoKey,
1282
+ signature: BufferSource,
1283
+ data: BufferSource
1284
+ ): Promise<boolean>;
1285
+
1286
+ /**
1287
+ * Encrypt data.
1288
+ *
1289
+ * @param algorithm - Encryption algorithm
1290
+ * @param key - Encryption key
1291
+ * @param data - Data to encrypt
1292
+ * @returns Promise resolving to encrypted data as ArrayBuffer
1293
+ */
1294
+ encrypt(
1295
+ algorithm: AlgorithmIdentifier,
1296
+ key: CryptoKey,
1297
+ data: BufferSource
1298
+ ): Promise<ArrayBuffer>;
1299
+
1300
+ /**
1301
+ * Decrypt data.
1302
+ *
1303
+ * @param algorithm - Decryption algorithm
1304
+ * @param key - Decryption key
1305
+ * @param data - Data to decrypt
1306
+ * @returns Promise resolving to decrypted data as ArrayBuffer
1307
+ */
1308
+ decrypt(
1309
+ algorithm: AlgorithmIdentifier,
1310
+ key: CryptoKey,
1311
+ data: BufferSource
1312
+ ): Promise<ArrayBuffer>;
1313
+
1314
+ /**
1315
+ * Import a key from external data.
1316
+ *
1317
+ * @param format - Key format ("raw", "pkcs8", "spki", "jwk")
1318
+ * @param keyData - Key data
1319
+ * @param algorithm - Key algorithm
1320
+ * @param extractable - Whether the key can be exported
1321
+ * @param keyUsages - Allowed key usages
1322
+ * @returns Promise resolving to a CryptoKey
1323
+ */
1324
+ importKey(
1325
+ format: "raw" | "pkcs8" | "spki" | "jwk",
1326
+ keyData: BufferSource | JsonWebKey,
1327
+ algorithm: AlgorithmIdentifier,
1328
+ extractable: boolean,
1329
+ keyUsages: KeyUsage[]
1330
+ ): Promise<CryptoKey>;
1331
+
1332
+ /**
1333
+ * Export a key.
1334
+ *
1335
+ * @param format - Export format ("raw", "pkcs8", "spki", "jwk")
1336
+ * @param key - Key to export
1337
+ * @returns Promise resolving to ArrayBuffer or JsonWebKey
1338
+ */
1339
+ exportKey(
1340
+ format: "raw" | "pkcs8" | "spki" | "jwk",
1341
+ key: CryptoKey
1342
+ ): Promise<ArrayBuffer | JsonWebKey>;
1343
+
1344
+ /**
1345
+ * Derive bits from a key.
1346
+ *
1347
+ * @param algorithm - Derivation algorithm
1348
+ * @param baseKey - Base key for derivation
1349
+ * @param length - Number of bits to derive
1350
+ * @returns Promise resolving to derived bits as ArrayBuffer
1351
+ */
1352
+ deriveBits(
1353
+ algorithm: AlgorithmIdentifier,
1354
+ baseKey: CryptoKey,
1355
+ length: number
1356
+ ): Promise<ArrayBuffer>;
1357
+
1358
+ /**
1359
+ * Derive a new key from a base key.
1360
+ *
1361
+ * @param algorithm - Derivation algorithm
1362
+ * @param baseKey - Base key for derivation
1363
+ * @param derivedKeyType - Type of key to derive
1364
+ * @param extractable - Whether the derived key can be exported
1365
+ * @param keyUsages - Allowed usages for derived key
1366
+ * @returns Promise resolving to a CryptoKey
1367
+ */
1368
+ deriveKey(
1369
+ algorithm: AlgorithmIdentifier,
1370
+ baseKey: CryptoKey,
1371
+ derivedKeyType: AlgorithmIdentifier,
1372
+ extractable: boolean,
1373
+ keyUsages: KeyUsage[]
1374
+ ): Promise<CryptoKey>;
1375
+
1376
+ /**
1377
+ * Wrap a key for secure export.
1378
+ *
1379
+ * @param format - Key format
1380
+ * @param key - Key to wrap
1381
+ * @param wrappingKey - Key to wrap with
1382
+ * @param wrapAlgorithm - Wrapping algorithm
1383
+ * @returns Promise resolving to wrapped key as ArrayBuffer
1384
+ */
1385
+ wrapKey(
1386
+ format: "raw" | "pkcs8" | "spki" | "jwk",
1387
+ key: CryptoKey,
1388
+ wrappingKey: CryptoKey,
1389
+ wrapAlgorithm: AlgorithmIdentifier
1390
+ ): Promise<ArrayBuffer>;
1391
+
1392
+ /**
1393
+ * Unwrap a wrapped key.
1394
+ *
1395
+ * @param format - Key format
1396
+ * @param wrappedKey - Wrapped key data
1397
+ * @param unwrappingKey - Key to unwrap with
1398
+ * @param unwrapAlgorithm - Unwrapping algorithm
1399
+ * @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key
1400
+ * @param extractable - Whether the unwrapped key can be exported
1401
+ * @param keyUsages - Allowed usages for unwrapped key
1402
+ * @returns Promise resolving to a CryptoKey
1403
+ */
1404
+ unwrapKey(
1405
+ format: "raw" | "pkcs8" | "spki" | "jwk",
1406
+ wrappedKey: BufferSource,
1407
+ unwrappingKey: CryptoKey,
1408
+ unwrapAlgorithm: AlgorithmIdentifier,
1409
+ unwrappedKeyAlgorithm: AlgorithmIdentifier,
1410
+ extractable: boolean,
1411
+ keyUsages: KeyUsage[]
1412
+ ): Promise<CryptoKey>;
1413
+ }
1414
+
1415
+ /**
1416
+ * Crypto interface providing cryptographic functionality.
1417
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto
1418
+ */
1419
+ interface Crypto {
1420
+ /**
1421
+ * SubtleCrypto interface for cryptographic operations.
1422
+ */
1423
+ readonly subtle: SubtleCrypto;
1424
+
1425
+ /**
1426
+ * Fill a TypedArray with cryptographically random values.
1427
+ *
1428
+ * @param array - TypedArray to fill (max 65536 bytes)
1429
+ * @returns The same array, filled with random values
1430
+ *
1431
+ * @example
1432
+ * const arr = new Uint8Array(16);
1433
+ * crypto.getRandomValues(arr);
1434
+ */
1435
+ getRandomValues<T extends ArrayBufferView | null>(array: T): T;
1436
+
1437
+ /**
1438
+ * Generate a random UUID v4.
1439
+ *
1440
+ * @returns A random UUID string
1441
+ *
1442
+ * @example
1443
+ * const uuid = crypto.randomUUID();
1444
+ * // "550e8400-e29b-41d4-a716-446655440000"
1445
+ */
1446
+ randomUUID(): string;
1447
+ }
1448
+
1449
+ /**
1450
+ * Crypto object providing cryptographic functionality.
1451
+ */
1452
+ const crypto: Crypto;
1453
+ }
1454
+ `;
1455
+ var PATH_TYPES = `/**
1456
+ * Global Type Definitions for @ricsam/isolate-path
1457
+ *
1458
+ * These types define the globals injected by setupPath() into an isolated-vm context.
1459
+ * Use these types to typecheck user code that will run inside the V8 isolate.
1460
+ *
1461
+ * @example
1462
+ * // Typecheck isolate code with path operations
1463
+ * const joined = path.join('/foo', 'bar', 'baz');
1464
+ * const resolved = path.resolve('relative/path');
1465
+ * const cwd = path.cwd();
1466
+ */
1467
+
1468
+ export {};
1469
+
1470
+ declare global {
1471
+ /**
1472
+ * Parsed path object returned by path.parse().
1473
+ */
1474
+ interface ParsedPath {
1475
+ /** The root of the path (e.g., "/" for absolute paths, "" for relative) */
1476
+ root: string;
1477
+ /** The directory portion of the path */
1478
+ dir: string;
1479
+ /** The file name including extension */
1480
+ base: string;
1481
+ /** The file extension (e.g., ".txt") */
1482
+ ext: string;
1483
+ /** The file name without extension */
1484
+ name: string;
1485
+ }
1486
+
1487
+ /**
1488
+ * Input object for path.format().
1489
+ */
1490
+ interface FormatInputPathObject {
1491
+ root?: string;
1492
+ dir?: string;
1493
+ base?: string;
1494
+ ext?: string;
1495
+ name?: string;
1496
+ }
1497
+
1498
+ /**
1499
+ * Path utilities for POSIX paths.
1500
+ * @see https://nodejs.org/api/path.html
1501
+ */
1502
+ namespace path {
1503
+ /**
1504
+ * Join path segments with the platform-specific separator.
1505
+ *
1506
+ * @param paths - Path segments to join
1507
+ * @returns The joined path, normalized
1508
+ *
1509
+ * @example
1510
+ * path.join('/foo', 'bar', 'baz'); // "/foo/bar/baz"
1511
+ * path.join('foo', 'bar', '..', 'baz'); // "foo/baz"
1512
+ */
1513
+ function join(...paths: string[]): string;
1514
+
1515
+ /**
1516
+ * Normalize a path, resolving '..' and '.' segments.
1517
+ *
1518
+ * @param p - The path to normalize
1519
+ * @returns The normalized path
1520
+ *
1521
+ * @example
1522
+ * path.normalize('/foo/bar/../baz'); // "/foo/baz"
1523
+ * path.normalize('/foo//bar'); // "/foo/bar"
1524
+ */
1525
+ function normalize(p: string): string;
1526
+
1527
+ /**
1528
+ * Get the last portion of a path (the file name).
1529
+ *
1530
+ * @param p - The path
1531
+ * @param ext - Optional extension to remove from the result
1532
+ * @returns The base name of the path
1533
+ *
1534
+ * @example
1535
+ * path.basename('/foo/bar/baz.txt'); // "baz.txt"
1536
+ * path.basename('/foo/bar/baz.txt', '.txt'); // "baz"
1537
+ */
1538
+ function basename(p: string, ext?: string): string;
1539
+
1540
+ /**
1541
+ * Get the directory name of a path.
1542
+ *
1543
+ * @param p - The path
1544
+ * @returns The directory portion of the path
1545
+ *
1546
+ * @example
1547
+ * path.dirname('/foo/bar/baz.txt'); // "/foo/bar"
1548
+ * path.dirname('/foo'); // "/"
1549
+ */
1550
+ function dirname(p: string): string;
1551
+
1552
+ /**
1553
+ * Get the extension of a path.
1554
+ *
1555
+ * @param p - The path
1556
+ * @returns The extension including the dot, or empty string
1557
+ *
1558
+ * @example
1559
+ * path.extname('file.txt'); // ".txt"
1560
+ * path.extname('file.tar.gz'); // ".gz"
1561
+ * path.extname('.bashrc'); // ""
1562
+ */
1563
+ function extname(p: string): string;
1564
+
1565
+ /**
1566
+ * Check if a path is absolute.
1567
+ *
1568
+ * @param p - The path to check
1569
+ * @returns True if the path is absolute
1570
+ *
1571
+ * @example
1572
+ * path.isAbsolute('/foo/bar'); // true
1573
+ * path.isAbsolute('foo/bar'); // false
1574
+ */
1575
+ function isAbsolute(p: string): boolean;
1576
+
1577
+ /**
1578
+ * Parse a path into its components.
1579
+ *
1580
+ * @param p - The path to parse
1581
+ * @returns An object with root, dir, base, ext, and name properties
1582
+ *
1583
+ * @example
1584
+ * path.parse('/foo/bar/baz.txt');
1585
+ * // { root: "/", dir: "/foo/bar", base: "baz.txt", ext: ".txt", name: "baz" }
1586
+ */
1587
+ function parse(p: string): ParsedPath;
1588
+
1589
+ /**
1590
+ * Build a path from an object.
1591
+ *
1592
+ * @param pathObject - Object with path components
1593
+ * @returns The formatted path string
1594
+ *
1595
+ * @example
1596
+ * path.format({ dir: '/foo/bar', base: 'baz.txt' }); // "/foo/bar/baz.txt"
1597
+ * path.format({ root: '/', name: 'file', ext: '.txt' }); // "/file.txt"
1598
+ */
1599
+ function format(pathObject: FormatInputPathObject): string;
1600
+
1601
+ /**
1602
+ * Resolve a sequence of paths to an absolute path.
1603
+ * Processes paths from right to left, prepending each until an absolute path is formed.
1604
+ * Uses the configured working directory for relative paths.
1605
+ *
1606
+ * @param paths - Path segments to resolve
1607
+ * @returns The resolved absolute path
1608
+ *
1609
+ * @example
1610
+ * // With cwd set to "/home/user"
1611
+ * path.resolve('foo/bar'); // "/home/user/foo/bar"
1612
+ * path.resolve('/foo', 'bar'); // "/foo/bar"
1613
+ * path.resolve('/foo', '/bar', 'baz'); // "/bar/baz"
1614
+ */
1615
+ function resolve(...paths: string[]): string;
1616
+
1617
+ /**
1618
+ * Compute the relative path from one path to another.
1619
+ *
1620
+ * @param from - The source path
1621
+ * @param to - The destination path
1622
+ * @returns The relative path from 'from' to 'to'
1623
+ *
1624
+ * @example
1625
+ * path.relative('/foo/bar', '/foo/baz'); // "../baz"
1626
+ * path.relative('/foo', '/foo/bar/baz'); // "bar/baz"
1627
+ */
1628
+ function relative(from: string, to: string): string;
1629
+
1630
+ /**
1631
+ * Get the configured working directory.
1632
+ *
1633
+ * @returns The current working directory
1634
+ *
1635
+ * @example
1636
+ * path.cwd(); // "/home/user" (or whatever was configured)
1637
+ */
1638
+ function cwd(): string;
1639
+
1640
+ /**
1641
+ * The platform-specific path segment separator.
1642
+ * Always "/" for POSIX paths.
1643
+ */
1644
+ const sep: string;
1645
+
1646
+ /**
1647
+ * The platform-specific path delimiter.
1648
+ * Always ":" for POSIX paths.
1649
+ */
1650
+ const delimiter: string;
1651
+ }
1652
+ }
1653
+ `;
1654
+ var TIMERS_TYPES = `/**
1655
+ * Global Type Definitions for @ricsam/isolate-timers
1656
+ *
1657
+ * These types define the globals injected by setupTimers() into an isolated-vm context.
1658
+ * Use these types to typecheck user code that will run inside the V8 isolate.
1659
+ *
1660
+ * @example
1661
+ * const timeoutId = setTimeout(() => {
1662
+ * console.log("fired!");
1663
+ * }, 1000);
1664
+ *
1665
+ * clearTimeout(timeoutId);
1666
+ *
1667
+ * const intervalId = setInterval(() => {
1668
+ * console.log("tick");
1669
+ * }, 100);
1670
+ *
1671
+ * clearInterval(intervalId);
1672
+ */
1673
+
1674
+ export {};
1675
+
1676
+ declare global {
1677
+ /**
1678
+ * Schedule a callback to execute after a delay.
1679
+ *
1680
+ * @param callback - The function to call after the delay
1681
+ * @param ms - The delay in milliseconds (default: 0)
1682
+ * @param args - Additional arguments to pass to the callback
1683
+ * @returns A timer ID that can be passed to clearTimeout
1684
+ *
1685
+ * @example
1686
+ * const id = setTimeout(() => console.log("done"), 1000);
1687
+ * setTimeout((a, b) => console.log(a, b), 100, "hello", "world");
1688
+ */
1689
+ function setTimeout(
1690
+ callback: (...args: unknown[]) => void,
1691
+ ms?: number,
1692
+ ...args: unknown[]
1693
+ ): number;
1694
+
1695
+ /**
1696
+ * Schedule a callback to execute repeatedly at a fixed interval.
1697
+ *
1698
+ * @param callback - The function to call at each interval
1699
+ * @param ms - The interval in milliseconds (minimum: 4ms)
1700
+ * @param args - Additional arguments to pass to the callback
1701
+ * @returns A timer ID that can be passed to clearInterval
1702
+ *
1703
+ * @example
1704
+ * const id = setInterval(() => console.log("tick"), 1000);
1705
+ */
1706
+ function setInterval(
1707
+ callback: (...args: unknown[]) => void,
1708
+ ms?: number,
1709
+ ...args: unknown[]
1710
+ ): number;
1711
+
1712
+ /**
1713
+ * Cancel a timeout previously scheduled with setTimeout.
1714
+ *
1715
+ * @param id - The timer ID returned by setTimeout
1716
+ *
1717
+ * @example
1718
+ * const id = setTimeout(() => {}, 1000);
1719
+ * clearTimeout(id);
1720
+ */
1721
+ function clearTimeout(id: number | undefined): void;
1722
+
1723
+ /**
1724
+ * Cancel an interval previously scheduled with setInterval.
1725
+ *
1726
+ * @param id - The timer ID returned by setInterval
1727
+ *
1728
+ * @example
1729
+ * const id = setInterval(() => {}, 1000);
1730
+ * clearInterval(id);
1731
+ */
1732
+ function clearInterval(id: number | undefined): void;
1733
+ }
1734
+ `;
1735
+ var TYPE_DEFINITIONS = {
1736
+ core: CORE_TYPES,
1737
+ console: CONSOLE_TYPES,
1738
+ crypto: CRYPTO_TYPES,
1739
+ encoding: ENCODING_TYPES,
1740
+ fetch: FETCH_TYPES,
1741
+ fs: FS_TYPES,
1742
+ path: PATH_TYPES,
1743
+ testEnvironment: TEST_ENV_TYPES,
1744
+ timers: TIMERS_TYPES
1745
+ };
1746
+ })
1747
+
1748
+ //# debugId=941D1A9D2A63EBAD64756E2164756E21