@ricsam/quickjs-test-utils 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/quickjs-types.cjs +285 -2
- package/dist/cjs/quickjs-types.cjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/quickjs-types.mjs +285 -2
- package/dist/mjs/quickjs-types.mjs.map +3 -3
- package/dist/types/quickjs-types.d.ts +7 -0
- package/package.json +5 -5
package/dist/cjs/package.json
CHANGED
|
@@ -31,6 +31,7 @@ var __export = (target, all) => {
|
|
|
31
31
|
var exports_quickjs_types = {};
|
|
32
32
|
__export(exports_quickjs_types, {
|
|
33
33
|
TYPE_DEFINITIONS: () => TYPE_DEFINITIONS,
|
|
34
|
+
TEST_ENV_TYPES: () => TEST_ENV_TYPES,
|
|
34
35
|
FS_TYPES: () => FS_TYPES,
|
|
35
36
|
FETCH_TYPES: () => FETCH_TYPES,
|
|
36
37
|
CORE_TYPES: () => CORE_TYPES
|
|
@@ -690,11 +691,293 @@ declare global {
|
|
|
690
691
|
}
|
|
691
692
|
}
|
|
692
693
|
`;
|
|
694
|
+
var TEST_ENV_TYPES = `/**
|
|
695
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-test-environment
|
|
696
|
+
*
|
|
697
|
+
* These types define the globals injected by setupTestEnvironment() into a QuickJS context.
|
|
698
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* describe("Math operations", () => {
|
|
702
|
+
* it("should add numbers", () => {
|
|
703
|
+
* expect(1 + 1).toBe(2);
|
|
704
|
+
* });
|
|
705
|
+
* });
|
|
706
|
+
*/
|
|
707
|
+
|
|
708
|
+
export {};
|
|
709
|
+
|
|
710
|
+
declare global {
|
|
711
|
+
// ============================================
|
|
712
|
+
// Test Structure
|
|
713
|
+
// ============================================
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Define a test suite.
|
|
717
|
+
*
|
|
718
|
+
* @param name - The name of the test suite
|
|
719
|
+
* @param fn - Function containing tests and nested suites
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* describe("Calculator", () => {
|
|
723
|
+
* it("adds numbers", () => {
|
|
724
|
+
* expect(1 + 1).toBe(2);
|
|
725
|
+
* });
|
|
726
|
+
* });
|
|
727
|
+
*/
|
|
728
|
+
function describe(name: string, fn: () => void): void;
|
|
729
|
+
|
|
730
|
+
namespace describe {
|
|
731
|
+
/**
|
|
732
|
+
* Skip this suite and all its tests.
|
|
733
|
+
*/
|
|
734
|
+
function skip(name: string, fn: () => void): void;
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Only run this suite (and other .only suites).
|
|
738
|
+
*/
|
|
739
|
+
function only(name: string, fn: () => void): void;
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Mark suite as todo (skipped with different status).
|
|
743
|
+
*/
|
|
744
|
+
function todo(name: string, fn?: () => void): void;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Define a test case.
|
|
749
|
+
*
|
|
750
|
+
* @param name - The name of the test
|
|
751
|
+
* @param fn - The test function (can be async)
|
|
752
|
+
*
|
|
753
|
+
* @example
|
|
754
|
+
* it("should work", () => {
|
|
755
|
+
* expect(true).toBe(true);
|
|
756
|
+
* });
|
|
757
|
+
*
|
|
758
|
+
* it("should work async", async () => {
|
|
759
|
+
* const result = await Promise.resolve(42);
|
|
760
|
+
* expect(result).toBe(42);
|
|
761
|
+
* });
|
|
762
|
+
*/
|
|
763
|
+
function it(name: string, fn: () => void | Promise<void>): void;
|
|
764
|
+
|
|
765
|
+
namespace it {
|
|
766
|
+
/**
|
|
767
|
+
* Skip this test.
|
|
768
|
+
*/
|
|
769
|
+
function skip(name: string, fn?: () => void | Promise<void>): void;
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Only run this test (and other .only tests).
|
|
773
|
+
*/
|
|
774
|
+
function only(name: string, fn: () => void | Promise<void>): void;
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Mark test as todo.
|
|
778
|
+
*/
|
|
779
|
+
function todo(name: string, fn?: () => void | Promise<void>): void;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Alias for it().
|
|
784
|
+
*/
|
|
785
|
+
function test(name: string, fn: () => void | Promise<void>): void;
|
|
786
|
+
|
|
787
|
+
namespace test {
|
|
788
|
+
/**
|
|
789
|
+
* Skip this test.
|
|
790
|
+
*/
|
|
791
|
+
function skip(name: string, fn?: () => void | Promise<void>): void;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Only run this test (and other .only tests).
|
|
795
|
+
*/
|
|
796
|
+
function only(name: string, fn: () => void | Promise<void>): void;
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Mark test as todo.
|
|
800
|
+
*/
|
|
801
|
+
function todo(name: string, fn?: () => void | Promise<void>): void;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// ============================================
|
|
805
|
+
// Lifecycle Hooks
|
|
806
|
+
// ============================================
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Run once before all tests in the current suite.
|
|
810
|
+
*
|
|
811
|
+
* @param fn - Setup function (can be async)
|
|
812
|
+
*/
|
|
813
|
+
function beforeAll(fn: () => void | Promise<void>): void;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Run once after all tests in the current suite.
|
|
817
|
+
*
|
|
818
|
+
* @param fn - Teardown function (can be async)
|
|
819
|
+
*/
|
|
820
|
+
function afterAll(fn: () => void | Promise<void>): void;
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Run before each test in the current suite (and nested suites).
|
|
824
|
+
*
|
|
825
|
+
* @param fn - Setup function (can be async)
|
|
826
|
+
*/
|
|
827
|
+
function beforeEach(fn: () => void | Promise<void>): void;
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Run after each test in the current suite (and nested suites).
|
|
831
|
+
*
|
|
832
|
+
* @param fn - Teardown function (can be async)
|
|
833
|
+
*/
|
|
834
|
+
function afterEach(fn: () => void | Promise<void>): void;
|
|
835
|
+
|
|
836
|
+
// ============================================
|
|
837
|
+
// Assertions
|
|
838
|
+
// ============================================
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Matchers for assertions.
|
|
842
|
+
*/
|
|
843
|
+
interface Matchers<T> {
|
|
844
|
+
/**
|
|
845
|
+
* Strict equality (===).
|
|
846
|
+
*/
|
|
847
|
+
toBe(expected: T): void;
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Deep equality.
|
|
851
|
+
*/
|
|
852
|
+
toEqual(expected: unknown): void;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Deep equality with type checking.
|
|
856
|
+
*/
|
|
857
|
+
toStrictEqual(expected: unknown): void;
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Check if value is truthy.
|
|
861
|
+
*/
|
|
862
|
+
toBeTruthy(): void;
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Check if value is falsy.
|
|
866
|
+
*/
|
|
867
|
+
toBeFalsy(): void;
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Check if value is null.
|
|
871
|
+
*/
|
|
872
|
+
toBeNull(): void;
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Check if value is undefined.
|
|
876
|
+
*/
|
|
877
|
+
toBeUndefined(): void;
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Check if value is defined (not undefined).
|
|
881
|
+
*/
|
|
882
|
+
toBeDefined(): void;
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Check if value is NaN.
|
|
886
|
+
*/
|
|
887
|
+
toBeNaN(): void;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Check if number is greater than expected.
|
|
891
|
+
*/
|
|
892
|
+
toBeGreaterThan(n: number): void;
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Check if number is greater than or equal to expected.
|
|
896
|
+
*/
|
|
897
|
+
toBeGreaterThanOrEqual(n: number): void;
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Check if number is less than expected.
|
|
901
|
+
*/
|
|
902
|
+
toBeLessThan(n: number): void;
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* Check if number is less than or equal to expected.
|
|
906
|
+
*/
|
|
907
|
+
toBeLessThanOrEqual(n: number): void;
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Check if array/string contains item/substring.
|
|
911
|
+
*/
|
|
912
|
+
toContain(item: unknown): void;
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Check length of array/string.
|
|
916
|
+
*/
|
|
917
|
+
toHaveLength(length: number): void;
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Check if object has property (optionally with value).
|
|
921
|
+
*/
|
|
922
|
+
toHaveProperty(key: string, value?: unknown): void;
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Check if function throws.
|
|
926
|
+
*/
|
|
927
|
+
toThrow(expected?: string | RegExp | Error): void;
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Check if string matches pattern.
|
|
931
|
+
*/
|
|
932
|
+
toMatch(pattern: string | RegExp): void;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Check if object matches subset of properties.
|
|
936
|
+
*/
|
|
937
|
+
toMatchObject(object: object): void;
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Check if value is instance of class.
|
|
941
|
+
*/
|
|
942
|
+
toBeInstanceOf(constructor: Function): void;
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Negate the matcher.
|
|
946
|
+
*/
|
|
947
|
+
not: Matchers<T>;
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Await promise and check resolved value.
|
|
951
|
+
*/
|
|
952
|
+
resolves: Matchers<Awaited<T>>;
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* Await promise and check rejection.
|
|
956
|
+
*/
|
|
957
|
+
rejects: Matchers<unknown>;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Create an expectation for a value.
|
|
962
|
+
*
|
|
963
|
+
* @param actual - The value to test
|
|
964
|
+
* @returns Matchers for the value
|
|
965
|
+
*
|
|
966
|
+
* @example
|
|
967
|
+
* expect(1 + 1).toBe(2);
|
|
968
|
+
* expect({ a: 1 }).toEqual({ a: 1 });
|
|
969
|
+
* expect(() => { throw new Error(); }).toThrow();
|
|
970
|
+
* expect(promise).resolves.toBe(42);
|
|
971
|
+
*/
|
|
972
|
+
function expect<T>(actual: T): Matchers<T>;
|
|
973
|
+
}
|
|
974
|
+
`;
|
|
693
975
|
var TYPE_DEFINITIONS = {
|
|
694
976
|
core: CORE_TYPES,
|
|
695
977
|
fetch: FETCH_TYPES,
|
|
696
|
-
fs: FS_TYPES
|
|
978
|
+
fs: FS_TYPES,
|
|
979
|
+
testEnvironment: TEST_ENV_TYPES
|
|
697
980
|
};
|
|
698
981
|
})
|
|
699
982
|
|
|
700
|
-
//# debugId=
|
|
983
|
+
//# debugId=AAD20C0C66AEFD8664756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/quickjs-types.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * server.upgrade(request, { data: { id: 123 } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n */\n interface Server {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: unknown }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
5
|
+
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * server.upgrade(request, { data: { id: 123 } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n */\n interface Server {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: unknown }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-test-environment globals.\n *\n * Includes: describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach\n */\nexport const TEST_ENV_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n testEnvironment: TEST_ENV_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuGnB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;A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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6RvB,IAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,iBAAiB;AACnB;",
|
|
8
|
+
"debugId": "AAD20C0C66AEFD8664756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/mjs/package.json
CHANGED
|
@@ -654,16 +654,299 @@ declare global {
|
|
|
654
654
|
}
|
|
655
655
|
}
|
|
656
656
|
`;
|
|
657
|
+
var TEST_ENV_TYPES = `/**
|
|
658
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-test-environment
|
|
659
|
+
*
|
|
660
|
+
* These types define the globals injected by setupTestEnvironment() into a QuickJS context.
|
|
661
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* describe("Math operations", () => {
|
|
665
|
+
* it("should add numbers", () => {
|
|
666
|
+
* expect(1 + 1).toBe(2);
|
|
667
|
+
* });
|
|
668
|
+
* });
|
|
669
|
+
*/
|
|
670
|
+
|
|
671
|
+
export {};
|
|
672
|
+
|
|
673
|
+
declare global {
|
|
674
|
+
// ============================================
|
|
675
|
+
// Test Structure
|
|
676
|
+
// ============================================
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Define a test suite.
|
|
680
|
+
*
|
|
681
|
+
* @param name - The name of the test suite
|
|
682
|
+
* @param fn - Function containing tests and nested suites
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* describe("Calculator", () => {
|
|
686
|
+
* it("adds numbers", () => {
|
|
687
|
+
* expect(1 + 1).toBe(2);
|
|
688
|
+
* });
|
|
689
|
+
* });
|
|
690
|
+
*/
|
|
691
|
+
function describe(name: string, fn: () => void): void;
|
|
692
|
+
|
|
693
|
+
namespace describe {
|
|
694
|
+
/**
|
|
695
|
+
* Skip this suite and all its tests.
|
|
696
|
+
*/
|
|
697
|
+
function skip(name: string, fn: () => void): void;
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Only run this suite (and other .only suites).
|
|
701
|
+
*/
|
|
702
|
+
function only(name: string, fn: () => void): void;
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Mark suite as todo (skipped with different status).
|
|
706
|
+
*/
|
|
707
|
+
function todo(name: string, fn?: () => void): void;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Define a test case.
|
|
712
|
+
*
|
|
713
|
+
* @param name - The name of the test
|
|
714
|
+
* @param fn - The test function (can be async)
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* it("should work", () => {
|
|
718
|
+
* expect(true).toBe(true);
|
|
719
|
+
* });
|
|
720
|
+
*
|
|
721
|
+
* it("should work async", async () => {
|
|
722
|
+
* const result = await Promise.resolve(42);
|
|
723
|
+
* expect(result).toBe(42);
|
|
724
|
+
* });
|
|
725
|
+
*/
|
|
726
|
+
function it(name: string, fn: () => void | Promise<void>): void;
|
|
727
|
+
|
|
728
|
+
namespace it {
|
|
729
|
+
/**
|
|
730
|
+
* Skip this test.
|
|
731
|
+
*/
|
|
732
|
+
function skip(name: string, fn?: () => void | Promise<void>): void;
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Only run this test (and other .only tests).
|
|
736
|
+
*/
|
|
737
|
+
function only(name: string, fn: () => void | Promise<void>): void;
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Mark test as todo.
|
|
741
|
+
*/
|
|
742
|
+
function todo(name: string, fn?: () => void | Promise<void>): void;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Alias for it().
|
|
747
|
+
*/
|
|
748
|
+
function test(name: string, fn: () => void | Promise<void>): void;
|
|
749
|
+
|
|
750
|
+
namespace test {
|
|
751
|
+
/**
|
|
752
|
+
* Skip this test.
|
|
753
|
+
*/
|
|
754
|
+
function skip(name: string, fn?: () => void | Promise<void>): void;
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Only run this test (and other .only tests).
|
|
758
|
+
*/
|
|
759
|
+
function only(name: string, fn: () => void | Promise<void>): void;
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Mark test as todo.
|
|
763
|
+
*/
|
|
764
|
+
function todo(name: string, fn?: () => void | Promise<void>): void;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// ============================================
|
|
768
|
+
// Lifecycle Hooks
|
|
769
|
+
// ============================================
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Run once before all tests in the current suite.
|
|
773
|
+
*
|
|
774
|
+
* @param fn - Setup function (can be async)
|
|
775
|
+
*/
|
|
776
|
+
function beforeAll(fn: () => void | Promise<void>): void;
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Run once after all tests in the current suite.
|
|
780
|
+
*
|
|
781
|
+
* @param fn - Teardown function (can be async)
|
|
782
|
+
*/
|
|
783
|
+
function afterAll(fn: () => void | Promise<void>): void;
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Run before each test in the current suite (and nested suites).
|
|
787
|
+
*
|
|
788
|
+
* @param fn - Setup function (can be async)
|
|
789
|
+
*/
|
|
790
|
+
function beforeEach(fn: () => void | Promise<void>): void;
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Run after each test in the current suite (and nested suites).
|
|
794
|
+
*
|
|
795
|
+
* @param fn - Teardown function (can be async)
|
|
796
|
+
*/
|
|
797
|
+
function afterEach(fn: () => void | Promise<void>): void;
|
|
798
|
+
|
|
799
|
+
// ============================================
|
|
800
|
+
// Assertions
|
|
801
|
+
// ============================================
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Matchers for assertions.
|
|
805
|
+
*/
|
|
806
|
+
interface Matchers<T> {
|
|
807
|
+
/**
|
|
808
|
+
* Strict equality (===).
|
|
809
|
+
*/
|
|
810
|
+
toBe(expected: T): void;
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Deep equality.
|
|
814
|
+
*/
|
|
815
|
+
toEqual(expected: unknown): void;
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Deep equality with type checking.
|
|
819
|
+
*/
|
|
820
|
+
toStrictEqual(expected: unknown): void;
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Check if value is truthy.
|
|
824
|
+
*/
|
|
825
|
+
toBeTruthy(): void;
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Check if value is falsy.
|
|
829
|
+
*/
|
|
830
|
+
toBeFalsy(): void;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Check if value is null.
|
|
834
|
+
*/
|
|
835
|
+
toBeNull(): void;
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Check if value is undefined.
|
|
839
|
+
*/
|
|
840
|
+
toBeUndefined(): void;
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Check if value is defined (not undefined).
|
|
844
|
+
*/
|
|
845
|
+
toBeDefined(): void;
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Check if value is NaN.
|
|
849
|
+
*/
|
|
850
|
+
toBeNaN(): void;
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Check if number is greater than expected.
|
|
854
|
+
*/
|
|
855
|
+
toBeGreaterThan(n: number): void;
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Check if number is greater than or equal to expected.
|
|
859
|
+
*/
|
|
860
|
+
toBeGreaterThanOrEqual(n: number): void;
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Check if number is less than expected.
|
|
864
|
+
*/
|
|
865
|
+
toBeLessThan(n: number): void;
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Check if number is less than or equal to expected.
|
|
869
|
+
*/
|
|
870
|
+
toBeLessThanOrEqual(n: number): void;
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Check if array/string contains item/substring.
|
|
874
|
+
*/
|
|
875
|
+
toContain(item: unknown): void;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Check length of array/string.
|
|
879
|
+
*/
|
|
880
|
+
toHaveLength(length: number): void;
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Check if object has property (optionally with value).
|
|
884
|
+
*/
|
|
885
|
+
toHaveProperty(key: string, value?: unknown): void;
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Check if function throws.
|
|
889
|
+
*/
|
|
890
|
+
toThrow(expected?: string | RegExp | Error): void;
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Check if string matches pattern.
|
|
894
|
+
*/
|
|
895
|
+
toMatch(pattern: string | RegExp): void;
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* Check if object matches subset of properties.
|
|
899
|
+
*/
|
|
900
|
+
toMatchObject(object: object): void;
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Check if value is instance of class.
|
|
904
|
+
*/
|
|
905
|
+
toBeInstanceOf(constructor: Function): void;
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Negate the matcher.
|
|
909
|
+
*/
|
|
910
|
+
not: Matchers<T>;
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Await promise and check resolved value.
|
|
914
|
+
*/
|
|
915
|
+
resolves: Matchers<Awaited<T>>;
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Await promise and check rejection.
|
|
919
|
+
*/
|
|
920
|
+
rejects: Matchers<unknown>;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Create an expectation for a value.
|
|
925
|
+
*
|
|
926
|
+
* @param actual - The value to test
|
|
927
|
+
* @returns Matchers for the value
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* expect(1 + 1).toBe(2);
|
|
931
|
+
* expect({ a: 1 }).toEqual({ a: 1 });
|
|
932
|
+
* expect(() => { throw new Error(); }).toThrow();
|
|
933
|
+
* expect(promise).resolves.toBe(42);
|
|
934
|
+
*/
|
|
935
|
+
function expect<T>(actual: T): Matchers<T>;
|
|
936
|
+
}
|
|
937
|
+
`;
|
|
657
938
|
var TYPE_DEFINITIONS = {
|
|
658
939
|
core: CORE_TYPES,
|
|
659
940
|
fetch: FETCH_TYPES,
|
|
660
|
-
fs: FS_TYPES
|
|
941
|
+
fs: FS_TYPES,
|
|
942
|
+
testEnvironment: TEST_ENV_TYPES
|
|
661
943
|
};
|
|
662
944
|
export {
|
|
663
945
|
TYPE_DEFINITIONS,
|
|
946
|
+
TEST_ENV_TYPES,
|
|
664
947
|
FS_TYPES,
|
|
665
948
|
FETCH_TYPES,
|
|
666
949
|
CORE_TYPES
|
|
667
950
|
};
|
|
668
951
|
|
|
669
|
-
//# debugId=
|
|
952
|
+
//# debugId=C18D1D397F119E8864756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/quickjs-types.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * server.upgrade(request, { data: { id: 123 } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n */\n interface Server {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: unknown }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
5
|
+
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * server.upgrade(request, { data: { id: 123 } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n */\n interface Server {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: unknown }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-test-environment globals.\n *\n * Includes: describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach\n */\nexport const TEST_ENV_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n testEnvironment: TEST_ENV_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;AAkBO,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuGnB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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A;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6RvB,IAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,iBAAiB;AACnB;",
|
|
8
|
+
"debugId": "C18D1D397F119E8864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -28,6 +28,12 @@ export declare const FETCH_TYPES = "/**\n * QuickJS Global Type Definitions for
|
|
|
28
28
|
* Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream
|
|
29
29
|
*/
|
|
30
30
|
export declare const FS_TYPES = "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n";
|
|
31
|
+
/**
|
|
32
|
+
* Type definitions for @ricsam/quickjs-test-environment globals.
|
|
33
|
+
*
|
|
34
|
+
* Includes: describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach
|
|
35
|
+
*/
|
|
36
|
+
export declare const TEST_ENV_TYPES = "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n";
|
|
31
37
|
/**
|
|
32
38
|
* Map of package names to their type definitions.
|
|
33
39
|
*/
|
|
@@ -35,6 +41,7 @@ export declare const TYPE_DEFINITIONS: {
|
|
|
35
41
|
readonly core: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n";
|
|
36
42
|
readonly fetch: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * server.upgrade(request, { data: { id: 123 } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n */\n interface Server {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: unknown }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via `server.upgrade(request, { data: ... })`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n";
|
|
37
43
|
readonly fs: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n";
|
|
44
|
+
readonly testEnvironment: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n";
|
|
38
45
|
};
|
|
39
46
|
/**
|
|
40
47
|
* Type for the keys of TYPE_DEFINITIONS.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/quickjs-test-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "./dist/cjs/index.cjs",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"quickjs-emscripten": "^0.31.0",
|
|
23
|
-
"@ricsam/quickjs-core": "^0.2.
|
|
24
|
-
"@ricsam/quickjs-fetch": "^0.2.
|
|
25
|
-
"@ricsam/quickjs-fs": "^0.2.
|
|
26
|
-
"@ricsam/quickjs-runtime": "^0.2.
|
|
23
|
+
"@ricsam/quickjs-core": "^0.2.4",
|
|
24
|
+
"@ricsam/quickjs-fetch": "^0.2.4",
|
|
25
|
+
"@ricsam/quickjs-fs": "^0.2.4",
|
|
26
|
+
"@ricsam/quickjs-runtime": "^0.2.4"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@ricsam/quickjs-fs": {
|