@ricsam/quickjs-test-utils 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -43
- package/dist/cjs/context.cjs +86 -0
- package/dist/cjs/context.cjs.map +10 -0
- package/dist/cjs/eval.cjs +69 -0
- package/dist/cjs/eval.cjs.map +10 -0
- package/dist/cjs/fetch-context.cjs +89 -0
- package/dist/cjs/fetch-context.cjs.map +10 -0
- package/dist/cjs/fs-context.cjs +54 -0
- package/dist/cjs/fs-context.cjs.map +10 -0
- package/dist/cjs/index.cjs +58 -0
- package/dist/cjs/index.cjs.map +10 -0
- package/dist/cjs/integration-server.cjs +137 -0
- package/dist/cjs/integration-server.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/quickjs-types.cjs +700 -0
- package/dist/cjs/quickjs-types.cjs.map +10 -0
- package/dist/cjs/runtime-context.cjs +55 -0
- package/dist/cjs/runtime-context.cjs.map +10 -0
- package/dist/cjs/typecheck.cjs +108 -0
- package/dist/cjs/typecheck.cjs.map +10 -0
- package/dist/mjs/context.mjs +61 -0
- package/dist/mjs/context.mjs.map +10 -0
- package/dist/mjs/eval.mjs +38 -0
- package/dist/mjs/eval.mjs.map +10 -0
- package/dist/mjs/fetch-context.mjs +61 -0
- package/dist/mjs/fetch-context.mjs.map +10 -0
- package/dist/mjs/fs-context.mjs +29 -0
- package/dist/mjs/fs-context.mjs.map +10 -0
- package/dist/mjs/index.mjs +45 -0
- package/dist/mjs/index.mjs.map +10 -0
- package/dist/mjs/integration-server.mjs +106 -0
- package/dist/mjs/integration-server.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/mjs/quickjs-types.mjs +669 -0
- package/dist/mjs/quickjs-types.mjs.map +10 -0
- package/dist/mjs/runtime-context.mjs +26 -0
- package/dist/mjs/runtime-context.mjs.map +10 -0
- package/dist/mjs/typecheck.mjs +77 -0
- package/dist/mjs/typecheck.mjs.map +10 -0
- package/dist/types/context.d.ts +35 -0
- package/dist/types/eval.d.ts +31 -0
- package/dist/types/fetch-context.d.ts +41 -0
- package/dist/types/fs-context.d.ts +12 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integration-server.d.ts +39 -0
- package/dist/types/quickjs-types.d.ts +42 -0
- package/dist/types/runtime-context.d.ts +9 -0
- package/dist/types/typecheck.d.ts +115 -0
- package/package.json +62 -6
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-checking utility for QuickJS user code using ts-morph.
|
|
3
|
+
*
|
|
4
|
+
* This utility allows you to validate TypeScript code strings against
|
|
5
|
+
* the QuickJS global type definitions before running them in the sandbox.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { typecheckQuickJSCode } from "@ricsam/quickjs-test-utils";
|
|
9
|
+
*
|
|
10
|
+
* const result = typecheckQuickJSCode(`
|
|
11
|
+
* serve({
|
|
12
|
+
* fetch(request, server) {
|
|
13
|
+
* return new Response("Hello!");
|
|
14
|
+
* }
|
|
15
|
+
* });
|
|
16
|
+
* `, { include: ["fetch"] });
|
|
17
|
+
*
|
|
18
|
+
* if (!result.success) {
|
|
19
|
+
* console.error("Type errors:", result.errors);
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
import { ts } from "ts-morph";
|
|
23
|
+
/**
|
|
24
|
+
* Result of type-checking QuickJS code.
|
|
25
|
+
*/
|
|
26
|
+
export interface TypecheckResult {
|
|
27
|
+
/**
|
|
28
|
+
* Whether the code passed type checking.
|
|
29
|
+
*/
|
|
30
|
+
success: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Array of type errors found in the code.
|
|
33
|
+
*/
|
|
34
|
+
errors: TypecheckError[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A single type-checking error.
|
|
38
|
+
*/
|
|
39
|
+
export interface TypecheckError {
|
|
40
|
+
/**
|
|
41
|
+
* The error message from TypeScript.
|
|
42
|
+
*/
|
|
43
|
+
message: string;
|
|
44
|
+
/**
|
|
45
|
+
* The line number where the error occurred (1-indexed).
|
|
46
|
+
*/
|
|
47
|
+
line?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The column number where the error occurred (1-indexed).
|
|
50
|
+
*/
|
|
51
|
+
column?: number;
|
|
52
|
+
/**
|
|
53
|
+
* The TypeScript error code.
|
|
54
|
+
*/
|
|
55
|
+
code?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Options for type-checking QuickJS code.
|
|
59
|
+
*/
|
|
60
|
+
export interface TypecheckOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Which package types to include.
|
|
63
|
+
* @default ["core", "fetch", "fs"]
|
|
64
|
+
*/
|
|
65
|
+
include?: Array<"core" | "fetch" | "fs">;
|
|
66
|
+
/**
|
|
67
|
+
* Additional compiler options to pass to TypeScript.
|
|
68
|
+
*/
|
|
69
|
+
compilerOptions?: Partial<ts.CompilerOptions>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Type-check QuickJS user code against the package type definitions.
|
|
73
|
+
*
|
|
74
|
+
* @param code - The TypeScript/JavaScript code to check
|
|
75
|
+
* @param options - Configuration options
|
|
76
|
+
* @returns The result of type checking
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Check code that uses the fetch API
|
|
80
|
+
* const result = typecheckQuickJSCode(`
|
|
81
|
+
* const response = await fetch("https://api.example.com/data");
|
|
82
|
+
* const data = await response.json();
|
|
83
|
+
* `, { include: ["core", "fetch"] });
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Check code that uses serve()
|
|
87
|
+
* const result = typecheckQuickJSCode(`
|
|
88
|
+
* serve({
|
|
89
|
+
* fetch(request, server) {
|
|
90
|
+
* return new Response("Hello!");
|
|
91
|
+
* }
|
|
92
|
+
* });
|
|
93
|
+
* `, { include: ["fetch"] });
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // Check code that uses the file system API
|
|
97
|
+
* const result = typecheckQuickJSCode(`
|
|
98
|
+
* const root = await fs.getDirectory("/data");
|
|
99
|
+
* const file = await root.getFileHandle("config.json");
|
|
100
|
+
* `, { include: ["core", "fs"] });
|
|
101
|
+
*/
|
|
102
|
+
export declare function typecheckQuickJSCode(code: string, options?: TypecheckOptions): TypecheckResult;
|
|
103
|
+
/**
|
|
104
|
+
* Format type-check errors for display.
|
|
105
|
+
*
|
|
106
|
+
* @param result - The type-check result
|
|
107
|
+
* @returns A formatted string of errors
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* const result = typecheckQuickJSCode(code);
|
|
111
|
+
* if (!result.success) {
|
|
112
|
+
* console.error(formatTypecheckErrors(result));
|
|
113
|
+
* }
|
|
114
|
+
*/
|
|
115
|
+
export declare function formatTypecheckErrors(result: TypecheckResult): string;
|
package/package.json
CHANGED
|
@@ -1,10 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/quickjs-test-utils",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "./dist/cjs/index.cjs",
|
|
5
|
+
"types": "./dist/types/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"require": "./dist/cjs/index.cjs",
|
|
10
|
+
"import": "./dist/mjs/index.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target bun",
|
|
15
|
+
"test": "bun test",
|
|
16
|
+
"typecheck": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"ts-morph": "^24.0.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"quickjs-emscripten": "^0.31.0",
|
|
23
|
+
"@ricsam/quickjs-core": "^0.2.1",
|
|
24
|
+
"@ricsam/quickjs-fetch": "^0.2.1",
|
|
25
|
+
"@ricsam/quickjs-fs": "^0.2.1",
|
|
26
|
+
"@ricsam/quickjs-runtime": "^0.2.1"
|
|
27
|
+
},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"@ricsam/quickjs-fs": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"@ricsam/quickjs-runtime": {
|
|
33
|
+
"optional": true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"author": "Richard Samuelsson",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/ricsam/richie-qjs.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/ricsam/richie-qjs/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/ricsam/richie-qjs#readme",
|
|
5
46
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
47
|
+
"quickjs",
|
|
48
|
+
"sandbox",
|
|
49
|
+
"javascript",
|
|
50
|
+
"runtime",
|
|
51
|
+
"fetch",
|
|
52
|
+
"filesystem",
|
|
53
|
+
"streams",
|
|
54
|
+
"wasm",
|
|
55
|
+
"emscripten"
|
|
56
|
+
],
|
|
57
|
+
"description": "Testing utilities for QuickJS runtime",
|
|
58
|
+
"module": "./dist/mjs/index.mjs",
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"dist",
|
|
64
|
+
"README.md"
|
|
9
65
|
]
|
|
10
|
-
}
|
|
66
|
+
}
|