@ricsam/isolate-types 0.0.1 → 0.1.3

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