@ricsam/isolate-types 0.0.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -43
- package/dist/cjs/index.cjs +51 -0
- package/dist/cjs/index.cjs.map +10 -0
- package/dist/cjs/isolate-types.cjs +1748 -0
- package/dist/cjs/isolate-types.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/typecheck.cjs +123 -0
- package/dist/cjs/typecheck.cjs.map +10 -0
- package/dist/mjs/index.mjs +34 -0
- package/dist/mjs/index.mjs.map +10 -0
- package/dist/mjs/isolate-types.mjs +1717 -0
- package/dist/mjs/isolate-types.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/mjs/typecheck.mjs +92 -0
- package/dist/mjs/typecheck.mjs.map +10 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/isolate-types.d.ts +86 -0
- package/dist/types/typecheck.d.ts +148 -0
- package/package.json +47 -6
package/README.md
CHANGED
|
@@ -1,45 +1,88 @@
|
|
|
1
1
|
# @ricsam/isolate-types
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
Type definitions and type-checking utilities for isolate user code.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm add @ricsam/isolate-types
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
#### Type Checking Isolate Code
|
|
10
|
+
|
|
11
|
+
Validate TypeScript/JavaScript code that will run inside the isolate before execution using `ts-morph`:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { typecheckIsolateCode } from "@ricsam/isolate-types";
|
|
15
|
+
|
|
16
|
+
const result = typecheckIsolateCode(`
|
|
17
|
+
serve({
|
|
18
|
+
fetch(request, server) {
|
|
19
|
+
const url = new URL(request.url);
|
|
20
|
+
|
|
21
|
+
if (url.pathname === "/ws") {
|
|
22
|
+
server.upgrade(request, { data: { userId: 123 } });
|
|
23
|
+
return new Response(null, { status: 101 });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return Response.json({ message: "Hello!" });
|
|
27
|
+
},
|
|
28
|
+
websocket: {
|
|
29
|
+
message(ws, message) {
|
|
30
|
+
ws.send("Echo: " + message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
`, { include: ["core", "fetch"] });
|
|
35
|
+
|
|
36
|
+
if (!result.success) {
|
|
37
|
+
console.error("Type errors found:");
|
|
38
|
+
for (const error of result.errors) {
|
|
39
|
+
console.error(` Line ${error.line}: ${error.message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Options:**
|
|
45
|
+
|
|
46
|
+
| Option | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `include` | Which package types to include: `"core"`, `"fetch"`, `"fs"`, `"console"`, `"encoding"`, `"timers"`, `"testEnvironment"` (default: `["core", "fetch", "fs"]`) |
|
|
49
|
+
| `compilerOptions` | Additional TypeScript compiler options |
|
|
50
|
+
| `libraryTypes` | External library type definitions for import resolution (for validating user imports) |
|
|
51
|
+
|
|
52
|
+
**Using with tests:**
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { describe, expect, test } from "node:test";
|
|
56
|
+
import { typecheckIsolateCode } from "@ricsam/isolate-types";
|
|
57
|
+
|
|
58
|
+
describe("Isolate code validation", () => {
|
|
59
|
+
test("server code is type-safe", () => {
|
|
60
|
+
const result = typecheckIsolateCode(userProvidedCode, {
|
|
61
|
+
include: ["fetch"]
|
|
62
|
+
});
|
|
63
|
+
expect(result.success).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Type Definition Strings
|
|
69
|
+
|
|
70
|
+
The type definitions are exported as strings for custom use cases:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import {
|
|
74
|
+
CORE_TYPES, // ReadableStream, Blob, File, URL, etc.
|
|
75
|
+
CONSOLE_TYPES, // console.log, console.time, etc.
|
|
76
|
+
CRYPTO_TYPES, // crypto.subtle, CryptoKey, etc.
|
|
77
|
+
ENCODING_TYPES, // atob, btoa
|
|
78
|
+
FETCH_TYPES, // fetch, Request, Response, serve, etc.
|
|
79
|
+
FS_TYPES, // getDirectory, FileSystemHandle, etc.
|
|
80
|
+
PATH_TYPES, // path.join, path.resolve, etc.
|
|
81
|
+
TEST_ENV_TYPES, // describe, it, expect, etc.
|
|
82
|
+
TIMERS_TYPES, // setTimeout, setInterval, etc.
|
|
83
|
+
TYPE_DEFINITIONS // All types as { core, fetch, fs, ... }
|
|
84
|
+
} from "@ricsam/isolate-types";
|
|
85
|
+
|
|
86
|
+
// Use with your own ts-morph project
|
|
87
|
+
project.createSourceFile("isolate-globals.d.ts", FETCH_TYPES);
|
|
88
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// packages/isolate-types/src/index.ts
|
|
31
|
+
var exports_src = {};
|
|
32
|
+
__export(exports_src, {
|
|
33
|
+
typecheckIsolateCode: () => import_typecheck.typecheckIsolateCode,
|
|
34
|
+
formatTypecheckErrors: () => import_typecheck.formatTypecheckErrors,
|
|
35
|
+
TYPE_DEFINITIONS: () => import_isolate_types.TYPE_DEFINITIONS,
|
|
36
|
+
TIMERS_TYPES: () => import_isolate_types.TIMERS_TYPES,
|
|
37
|
+
TEST_ENV_TYPES: () => import_isolate_types.TEST_ENV_TYPES,
|
|
38
|
+
PATH_TYPES: () => import_isolate_types.PATH_TYPES,
|
|
39
|
+
FS_TYPES: () => import_isolate_types.FS_TYPES,
|
|
40
|
+
FETCH_TYPES: () => import_isolate_types.FETCH_TYPES,
|
|
41
|
+
ENCODING_TYPES: () => import_isolate_types.ENCODING_TYPES,
|
|
42
|
+
CRYPTO_TYPES: () => import_isolate_types.CRYPTO_TYPES,
|
|
43
|
+
CORE_TYPES: () => import_isolate_types.CORE_TYPES,
|
|
44
|
+
CONSOLE_TYPES: () => import_isolate_types.CONSOLE_TYPES
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(exports_src);
|
|
47
|
+
var import_isolate_types = require("./isolate-types.cjs");
|
|
48
|
+
var import_typecheck = require("./typecheck.cjs");
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
//# debugId=1488BE7FB67324F264756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @ricsam/isolate-types\n *\n * Type definitions and type-checking utilities for isolated-vm V8 sandbox code.\n */\n\n// Re-export type definitions\nexport {\n CORE_TYPES,\n CONSOLE_TYPES,\n CRYPTO_TYPES,\n ENCODING_TYPES,\n FETCH_TYPES,\n FS_TYPES,\n PATH_TYPES,\n TEST_ENV_TYPES,\n TIMERS_TYPES,\n TYPE_DEFINITIONS,\n type TypeDefinitionKey,\n} from \"./isolate-types.cjs\";\n\n// Re-export typecheck utilities\nexport {\n typecheckIsolateCode,\n formatTypecheckErrors,\n type TypecheckResult,\n type TypecheckError,\n type TypecheckOptions,\n type LibraryTypes,\n type LibraryTypeFile,\n} from \"./typecheck.cjs\";\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,IAZP;AAuBO,IARP;",
|
|
8
|
+
"debugId": "1488BE7FB67324F264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|