@ebowwa/sandbox 0.1.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/dist/compilers/index.d.ts +24 -0
- package/dist/compilers/index.d.ts.map +1 -0
- package/dist/compilers/index.js +42 -0
- package/dist/compilers/index.js.map +1 -0
- package/dist/compilers/javascript.d.ts +117 -0
- package/dist/compilers/javascript.d.ts.map +1 -0
- package/dist/compilers/javascript.js +462 -0
- package/dist/compilers/javascript.js.map +1 -0
- package/dist/compilers/python.d.ts +140 -0
- package/dist/compilers/python.d.ts.map +1 -0
- package/dist/compilers/python.js +650 -0
- package/dist/compilers/python.js.map +1 -0
- package/dist/compilers/typescript.d.ts +99 -0
- package/dist/compilers/typescript.d.ts.map +1 -0
- package/dist/compilers/typescript.js +323 -0
- package/dist/compilers/typescript.js.map +1 -0
- package/dist/core/cell.d.ts +160 -0
- package/dist/core/cell.d.ts.map +1 -0
- package/dist/core/cell.js +319 -0
- package/dist/core/cell.js.map +1 -0
- package/dist/core/compiler.d.ts +126 -0
- package/dist/core/compiler.d.ts.map +1 -0
- package/dist/core/compiler.js +123 -0
- package/dist/core/compiler.js.map +1 -0
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/limits.d.ts +173 -0
- package/dist/core/limits.d.ts.map +1 -0
- package/dist/core/limits.js +440 -0
- package/dist/core/limits.js.map +1 -0
- package/dist/core/permissions.d.ts +103 -0
- package/dist/core/permissions.d.ts.map +1 -0
- package/dist/core/permissions.js +341 -0
- package/dist/core/permissions.js.map +1 -0
- package/dist/core/runtime.d.ts +127 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +325 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/types.d.ts +380 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +67 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +145 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +279 -0
- package/dist/index.js.map +1 -0
- package/dist/multi/index.d.ts +9 -0
- package/dist/multi/index.d.ts.map +1 -0
- package/dist/multi/index.js +7 -0
- package/dist/multi/index.js.map +1 -0
- package/dist/multi/polyglot.d.ts +179 -0
- package/dist/multi/polyglot.d.ts.map +1 -0
- package/dist/multi/polyglot.js +319 -0
- package/dist/multi/polyglot.js.map +1 -0
- package/dist/runtimes/docker.d.ts +97 -0
- package/dist/runtimes/docker.d.ts.map +1 -0
- package/dist/runtimes/docker.js +368 -0
- package/dist/runtimes/docker.js.map +1 -0
- package/dist/runtimes/index.d.ts +11 -0
- package/dist/runtimes/index.d.ts.map +1 -0
- package/dist/runtimes/index.js +9 -0
- package/dist/runtimes/index.js.map +1 -0
- package/dist/runtimes/process.d.ts +47 -0
- package/dist/runtimes/process.d.ts.map +1 -0
- package/dist/runtimes/process.js +230 -0
- package/dist/runtimes/process.js.map +1 -0
- package/dist/session/index.d.ts +12 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +9 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/kernel.d.ts +199 -0
- package/dist/session/kernel.d.ts.map +1 -0
- package/dist/session/kernel.js +400 -0
- package/dist/session/kernel.js.map +1 -0
- package/dist/session/notebook.d.ts +168 -0
- package/dist/session/notebook.d.ts.map +1 -0
- package/dist/session/notebook.js +499 -0
- package/dist/session/notebook.js.map +1 -0
- package/dist/session/repl.d.ts +159 -0
- package/dist/session/repl.d.ts.map +1 -0
- package/dist/session/repl.js +409 -0
- package/dist/session/repl.js.map +1 -0
- package/package.json +142 -0
- package/src/compilers/index.ts +80 -0
- package/src/compilers/javascript.ts +571 -0
- package/src/compilers/python.ts +785 -0
- package/src/compilers/typescript.ts +442 -0
- package/src/core/cell.ts +439 -0
- package/src/core/compiler.ts +250 -0
- package/src/core/index.ts +123 -0
- package/src/core/limits.ts +508 -0
- package/src/core/permissions.ts +409 -0
- package/src/core/runtime.ts +499 -0
- package/src/core/types.ts +528 -0
- package/src/global.d.ts +59 -0
- package/src/index.ts +515 -0
- package/src/multi/index.ts +22 -0
- package/src/multi/polyglot.ts +461 -0
- package/src/runtimes/docker.ts +501 -0
- package/src/runtimes/index.ts +21 -0
- package/src/runtimes/process.ts +316 -0
- package/src/session/index.ts +41 -0
- package/src/session/kernel.ts +553 -0
- package/src/session/notebook.ts +635 -0
- package/src/session/repl.ts +521 -0
- package/src/wasm2wasm.d.ts +35 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Compiler for @ebowwa/sandbox
|
|
3
|
+
*
|
|
4
|
+
* Compiles TypeScript to WASM via JavaScript.
|
|
5
|
+
* Uses esbuild for fast TypeScript transpilation, then delegates to JavaScript compiler.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseCompiler, type CompileResult, type CompilerOptions, type LanguageCapabilities } from "../core/compiler.js";
|
|
8
|
+
import type { Permissions, Limits } from "../core/types.js";
|
|
9
|
+
/** TypeScript compiler options */
|
|
10
|
+
export interface TypeScriptCompilerOptions extends CompilerOptions {
|
|
11
|
+
/** TypeScript target */
|
|
12
|
+
target?: "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "esnext";
|
|
13
|
+
/** Module format */
|
|
14
|
+
module?: "esm" | "cjs" | "iife";
|
|
15
|
+
/** Enable strict type checking */
|
|
16
|
+
strict?: boolean;
|
|
17
|
+
/** Emit declaration files */
|
|
18
|
+
declaration?: boolean;
|
|
19
|
+
/** Source map generation */
|
|
20
|
+
sourceMap?: boolean;
|
|
21
|
+
/** JSX transform */
|
|
22
|
+
jsx?: "transform" | "preserve" | "automatic";
|
|
23
|
+
/** JSX factory */
|
|
24
|
+
jsxFactory?: string;
|
|
25
|
+
/** JSX fragment factory */
|
|
26
|
+
jsxFragment?: string;
|
|
27
|
+
/** Use AssemblyScript for compilation */
|
|
28
|
+
useAssemblyScript?: boolean;
|
|
29
|
+
/** Transpiler to use */
|
|
30
|
+
transpiler?: "esbuild" | "swc" | "tsc";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* TypeScript Compiler
|
|
34
|
+
*
|
|
35
|
+
* Transpiles TypeScript to JavaScript, then compiles to WASM.
|
|
36
|
+
* Supports both standard TypeScript and AssemblyScript syntax.
|
|
37
|
+
*/
|
|
38
|
+
export declare class TypeScriptCompiler extends BaseCompiler {
|
|
39
|
+
readonly language: "typescript";
|
|
40
|
+
private jsCompiler;
|
|
41
|
+
private esbuildAvailable;
|
|
42
|
+
private swcAvailable;
|
|
43
|
+
constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Check if TypeScript compiler is available
|
|
46
|
+
*/
|
|
47
|
+
isAvailable(): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Validate TypeScript syntax
|
|
50
|
+
*/
|
|
51
|
+
validate(source: string): Promise<{
|
|
52
|
+
valid: boolean;
|
|
53
|
+
error?: string;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Compile TypeScript to WASM
|
|
57
|
+
*
|
|
58
|
+
* 1. Transpile TypeScript to JavaScript
|
|
59
|
+
* 2. Use JavaScript compiler for WASM compilation
|
|
60
|
+
*/
|
|
61
|
+
compile(source: string, permissions: Permissions, limits: Limits, options?: TypeScriptCompilerOptions): Promise<CompileResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Get language capabilities
|
|
64
|
+
*/
|
|
65
|
+
getCapabilities(): LanguageCapabilities;
|
|
66
|
+
/**
|
|
67
|
+
* Transpile TypeScript to JavaScript
|
|
68
|
+
*/
|
|
69
|
+
private transpile;
|
|
70
|
+
/**
|
|
71
|
+
* Transpile using esbuild
|
|
72
|
+
*/
|
|
73
|
+
private transpileWithEsbuild;
|
|
74
|
+
/**
|
|
75
|
+
* Transpile using SWC
|
|
76
|
+
*/
|
|
77
|
+
private transpileWithSwc;
|
|
78
|
+
/**
|
|
79
|
+
* Fallback transpilation using regex (basic type stripping)
|
|
80
|
+
*
|
|
81
|
+
* Note: This is not a complete TypeScript implementation.
|
|
82
|
+
* Use esbuild or swc for production code.
|
|
83
|
+
*/
|
|
84
|
+
private transpileWithRegex;
|
|
85
|
+
/**
|
|
86
|
+
* Get the best available transpiler
|
|
87
|
+
*/
|
|
88
|
+
private getTranspiler;
|
|
89
|
+
/**
|
|
90
|
+
* Detect if source uses AssemblyScript-specific types
|
|
91
|
+
*/
|
|
92
|
+
private detectAssemblyScript;
|
|
93
|
+
/**
|
|
94
|
+
* Basic syntax check for TypeScript
|
|
95
|
+
*/
|
|
96
|
+
private checkBasicSyntax;
|
|
97
|
+
}
|
|
98
|
+
export declare const typescriptCompiler: TypeScriptCompiler;
|
|
99
|
+
//# sourceMappingURL=typescript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/compilers/typescript.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG5D,kCAAkC;AAClC,MAAM,WAAW,yBAA0B,SAAQ,eAAe;IAChE,wBAAwB;IACxB,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1G,oBAAoB;IACpB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAChC,kCAAkC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4BAA4B;IAC5B,SAAS,CA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 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Compiler for @ebowwa/sandbox
|
|
3
|
+
*
|
|
4
|
+
* Compiles TypeScript to WASM via JavaScript.
|
|
5
|
+
* Uses esbuild for fast TypeScript transpilation, then delegates to JavaScript compiler.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseCompiler, } from "../core/compiler.js";
|
|
8
|
+
import { JavaScriptCompiler } from "./javascript.js";
|
|
9
|
+
/**
|
|
10
|
+
* TypeScript Compiler
|
|
11
|
+
*
|
|
12
|
+
* Transpiles TypeScript to JavaScript, then compiles to WASM.
|
|
13
|
+
* Supports both standard TypeScript and AssemblyScript syntax.
|
|
14
|
+
*/
|
|
15
|
+
export class TypeScriptCompiler extends BaseCompiler {
|
|
16
|
+
language = "typescript";
|
|
17
|
+
jsCompiler;
|
|
18
|
+
esbuildAvailable = null;
|
|
19
|
+
swcAvailable = null;
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.jsCompiler = new JavaScriptCompiler();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if TypeScript compiler is available
|
|
26
|
+
*/
|
|
27
|
+
async isAvailable() {
|
|
28
|
+
// TypeScript compiler is always available (we have built-in support)
|
|
29
|
+
// But transpilers may vary
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate TypeScript syntax
|
|
34
|
+
*/
|
|
35
|
+
async validate(source) {
|
|
36
|
+
try {
|
|
37
|
+
const transpiler = await this.getTranspiler("esbuild");
|
|
38
|
+
if (transpiler?.type === "esbuild") {
|
|
39
|
+
await transpiler.module.transform(source, {
|
|
40
|
+
loader: "ts",
|
|
41
|
+
target: "es2020",
|
|
42
|
+
tsconfigRaw: {
|
|
43
|
+
compilerOptions: {
|
|
44
|
+
strict: true,
|
|
45
|
+
noEmit: true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return { valid: true };
|
|
50
|
+
}
|
|
51
|
+
// Fallback: basic regex check for common syntax errors
|
|
52
|
+
const syntaxErrors = this.checkBasicSyntax(source);
|
|
53
|
+
if (syntaxErrors) {
|
|
54
|
+
return { valid: false, error: syntaxErrors };
|
|
55
|
+
}
|
|
56
|
+
return { valid: true };
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return {
|
|
60
|
+
valid: false,
|
|
61
|
+
error: error instanceof Error ? error.message : String(error),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Compile TypeScript to WASM
|
|
67
|
+
*
|
|
68
|
+
* 1. Transpile TypeScript to JavaScript
|
|
69
|
+
* 2. Use JavaScript compiler for WASM compilation
|
|
70
|
+
*/
|
|
71
|
+
async compile(source, permissions, limits, options) {
|
|
72
|
+
const opts = {
|
|
73
|
+
target: "es2020",
|
|
74
|
+
module: "esm",
|
|
75
|
+
strict: true,
|
|
76
|
+
declaration: false,
|
|
77
|
+
sourceMap: options?.sourceMap ?? false,
|
|
78
|
+
jsx: "transform",
|
|
79
|
+
jsxFactory: "React.createElement",
|
|
80
|
+
jsxFragment: "React.Fragment",
|
|
81
|
+
useAssemblyScript: false,
|
|
82
|
+
transpiler: "esbuild",
|
|
83
|
+
...options,
|
|
84
|
+
};
|
|
85
|
+
// Check if source uses AssemblyScript types
|
|
86
|
+
const isAssemblyScript = this.detectAssemblyScript(source);
|
|
87
|
+
const effectiveUseAssemblyScript = opts.useAssemblyScript || isAssemblyScript;
|
|
88
|
+
// Transpile TypeScript to JavaScript
|
|
89
|
+
const transpiled = await this.transpile(source, {
|
|
90
|
+
...opts,
|
|
91
|
+
useAssemblyScript: effectiveUseAssemblyScript,
|
|
92
|
+
});
|
|
93
|
+
// Delegate to JavaScript compiler
|
|
94
|
+
const jsOptions = {
|
|
95
|
+
target: opts.target,
|
|
96
|
+
module: opts.module,
|
|
97
|
+
strict: opts.strict,
|
|
98
|
+
useAssemblyScript: effectiveUseAssemblyScript,
|
|
99
|
+
optimize: opts.optimize,
|
|
100
|
+
debug: opts.debug,
|
|
101
|
+
sourceMap: opts.sourceMap,
|
|
102
|
+
};
|
|
103
|
+
const result = await this.jsCompiler.compile(transpiled.code, permissions, limits, jsOptions);
|
|
104
|
+
// Include source map if generated
|
|
105
|
+
if (transpiled.map) {
|
|
106
|
+
result.sourceMap = transpiled.map;
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get language capabilities
|
|
112
|
+
*/
|
|
113
|
+
getCapabilities() {
|
|
114
|
+
return {
|
|
115
|
+
repl: true,
|
|
116
|
+
stateful: true,
|
|
117
|
+
compiled: false, // TS transpiles to JS, which is interpreted
|
|
118
|
+
gc: true, // JavaScript has garbage collection
|
|
119
|
+
imports: true,
|
|
120
|
+
async: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Transpile TypeScript to JavaScript
|
|
125
|
+
*/
|
|
126
|
+
async transpile(source, options) {
|
|
127
|
+
// If using AssemblyScript, don't transpile types
|
|
128
|
+
if (options.useAssemblyScript) {
|
|
129
|
+
return {
|
|
130
|
+
code: source,
|
|
131
|
+
map: undefined,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const transpiler = await this.getTranspiler(options.transpiler || "esbuild");
|
|
135
|
+
if (transpiler?.type === "esbuild") {
|
|
136
|
+
return this.transpileWithEsbuild(source, options, transpiler.module);
|
|
137
|
+
}
|
|
138
|
+
if (transpiler?.type === "swc") {
|
|
139
|
+
return this.transpileWithSwc(source, options, transpiler.module);
|
|
140
|
+
}
|
|
141
|
+
// Fallback: strip types using regex (not recommended for production)
|
|
142
|
+
return this.transpileWithRegex(source);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Transpile using esbuild
|
|
146
|
+
*/
|
|
147
|
+
async transpileWithEsbuild(source, options, esbuild) {
|
|
148
|
+
const result = await esbuild.transform(source, {
|
|
149
|
+
loader: "ts",
|
|
150
|
+
target: options.target || "es2020",
|
|
151
|
+
format: options.module === "cjs" ? "cjs" : "esm",
|
|
152
|
+
minify: options.optimize,
|
|
153
|
+
sourcemap: options.sourceMap ? "external" : false,
|
|
154
|
+
jsx: options.jsx === "automatic" ? "automatic" : "transform",
|
|
155
|
+
jsxFactory: options.jsxFactory,
|
|
156
|
+
jsxFragment: options.jsxFragment,
|
|
157
|
+
tsconfigRaw: {
|
|
158
|
+
compilerOptions: {
|
|
159
|
+
strict: options.strict,
|
|
160
|
+
target: options.target,
|
|
161
|
+
module: options.module?.toUpperCase(),
|
|
162
|
+
esModuleInterop: true,
|
|
163
|
+
allowSyntheticDefaultImports: true,
|
|
164
|
+
resolveJsonModule: true,
|
|
165
|
+
declaration: options.declaration,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
code: result.code,
|
|
171
|
+
map: result.map,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Transpile using SWC
|
|
176
|
+
*/
|
|
177
|
+
async transpileWithSwc(source, options, swc) {
|
|
178
|
+
const result = await swc.transform(source, {
|
|
179
|
+
jsc: {
|
|
180
|
+
parser: {
|
|
181
|
+
syntax: "typescript",
|
|
182
|
+
tsx: options.jsx !== "preserve",
|
|
183
|
+
},
|
|
184
|
+
transform: {
|
|
185
|
+
react: {
|
|
186
|
+
runtime: options.jsx === "automatic" ? "automatic" : "classic",
|
|
187
|
+
pragma: options.jsxFactory,
|
|
188
|
+
pragmaFrag: options.jsxFragment,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
target: options.target?.replace("es", "es") || "es2020",
|
|
192
|
+
},
|
|
193
|
+
module: {
|
|
194
|
+
type: options.module === "cjs" ? "commonjs" : "es6",
|
|
195
|
+
},
|
|
196
|
+
minify: options.optimize,
|
|
197
|
+
sourceMaps: options.sourceMap,
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
code: result.code,
|
|
201
|
+
map: result.map,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Fallback transpilation using regex (basic type stripping)
|
|
206
|
+
*
|
|
207
|
+
* Note: This is not a complete TypeScript implementation.
|
|
208
|
+
* Use esbuild or swc for production code.
|
|
209
|
+
*/
|
|
210
|
+
transpileWithRegex(source) {
|
|
211
|
+
let code = source;
|
|
212
|
+
// Strip type annotations
|
|
213
|
+
// This is a simplified implementation
|
|
214
|
+
const patterns = [
|
|
215
|
+
// Remove type annotations: : Type
|
|
216
|
+
/:\s*[A-Z][a-zA-Z0-9_]*(?:<[^>]+>)?(?:\[\])?(?:\s*\|\s*[A-Z][a-zA-Z0-9_]*(?:<[^>]+>)?(?:\[\])?)*/g,
|
|
217
|
+
// Remove interface declarations
|
|
218
|
+
/interface\s+[A-Z][a-zA-Z0-9_]*\s*(?:<[^>]+>)?\s*\{[^}]*\}/g,
|
|
219
|
+
// Remove type declarations
|
|
220
|
+
/type\s+[A-Z][a-zA-Z0-9_]*\s*(?:<[^>]+>)?\s*=\s*[^;]+;/g,
|
|
221
|
+
// Remove enum declarations (convert to const objects)
|
|
222
|
+
/enum\s+([A-Z][a-zA-Z0-9_]*)\s*\{([^}]*)\}/g,
|
|
223
|
+
// Remove generic type parameters
|
|
224
|
+
/<[^>]+>/g,
|
|
225
|
+
// Remove 'as' type assertions
|
|
226
|
+
/\s+as\s+[A-Z][a-zA-Z0-9_]*(?:<[^>]+>)?/g,
|
|
227
|
+
// Remove 'satisfies' type assertions
|
|
228
|
+
/\s+satisfies\s+[A-Z][a-zA-Z0-9_]*(?:<[^>]+>)?/g,
|
|
229
|
+
// Remove 'declare' statements
|
|
230
|
+
/declare\s+(?:const|let|var|function|class|interface|type|enum)\s+[^;]+;/g,
|
|
231
|
+
// Remove 'public', 'private', 'protected', 'readonly' modifiers
|
|
232
|
+
/\b(?:public|private|protected|readonly)\s+/g,
|
|
233
|
+
// Remove 'abstract' modifier
|
|
234
|
+
/\babstract\s+/g,
|
|
235
|
+
// Remove parameter properties in constructors
|
|
236
|
+
/constructor\s*\(([^)]*)\)/g,
|
|
237
|
+
];
|
|
238
|
+
for (const pattern of patterns) {
|
|
239
|
+
code = code.replace(pattern, "");
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
code,
|
|
243
|
+
map: undefined,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get the best available transpiler
|
|
248
|
+
*/
|
|
249
|
+
async getTranspiler(preferred) {
|
|
250
|
+
if (preferred === "esbuild" || preferred === "tsc") {
|
|
251
|
+
if (this.esbuildAvailable === null) {
|
|
252
|
+
try {
|
|
253
|
+
await import("esbuild");
|
|
254
|
+
this.esbuildAvailable = true;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
this.esbuildAvailable = false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (this.esbuildAvailable) {
|
|
261
|
+
const esbuild = await import("esbuild");
|
|
262
|
+
return { type: "esbuild", module: esbuild };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (preferred === "swc") {
|
|
266
|
+
if (this.swcAvailable === null) {
|
|
267
|
+
try {
|
|
268
|
+
await import("@swc/core");
|
|
269
|
+
this.swcAvailable = true;
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
this.swcAvailable = false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (this.swcAvailable) {
|
|
276
|
+
const swc = await import("@swc/core");
|
|
277
|
+
return { type: "swc", module: swc };
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Fallback to esbuild if swc was preferred but not available
|
|
281
|
+
if (preferred === "swc" && this.esbuildAvailable !== false) {
|
|
282
|
+
return this.getTranspiler("esbuild");
|
|
283
|
+
}
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Detect if source uses AssemblyScript-specific types
|
|
288
|
+
*/
|
|
289
|
+
detectAssemblyScript(source) {
|
|
290
|
+
// AssemblyScript uses specific types: i8, i16, i32, i64, f32, f64, usize, etc.
|
|
291
|
+
const assemblyScriptTypes = /\b(i8|i16|i32|i64|f32|f64|usize|isize|bool)\b/;
|
|
292
|
+
return assemblyScriptTypes.test(source);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Basic syntax check for TypeScript
|
|
296
|
+
*/
|
|
297
|
+
checkBasicSyntax(source) {
|
|
298
|
+
// Check for common syntax errors
|
|
299
|
+
const errors = [];
|
|
300
|
+
// Check for unmatched braces
|
|
301
|
+
const openBraces = (source.match(/\{/g) || []).length;
|
|
302
|
+
const closeBraces = (source.match(/\}/g) || []).length;
|
|
303
|
+
if (openBraces !== closeBraces) {
|
|
304
|
+
errors.push(`Unmatched braces: ${openBraces} open, ${closeBraces} close`);
|
|
305
|
+
}
|
|
306
|
+
// Check for unmatched parentheses
|
|
307
|
+
const openParens = (source.match(/\(/g) || []).length;
|
|
308
|
+
const closeParens = (source.match(/\)/g) || []).length;
|
|
309
|
+
if (openParens !== closeParens) {
|
|
310
|
+
errors.push(`Unmatched parentheses: ${openParens} open, ${closeParens} close`);
|
|
311
|
+
}
|
|
312
|
+
// Check for unmatched brackets
|
|
313
|
+
const openBrackets = (source.match(/\[/g) || []).length;
|
|
314
|
+
const closeBrackets = (source.match(/\]/g) || []).length;
|
|
315
|
+
if (openBrackets !== closeBrackets) {
|
|
316
|
+
errors.push(`Unmatched brackets: ${openBrackets} open, ${closeBrackets} close`);
|
|
317
|
+
}
|
|
318
|
+
return errors.length > 0 ? errors.join("; ") : null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// Default instance
|
|
322
|
+
export const typescriptCompiler = new TypeScriptCompiler();
|
|
323
|
+
//# sourceMappingURL=typescript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../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AAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACxD,MAAM,aAAa,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACzD,IAAI,YAAY,KAAK,aAAa,EAAE,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,uBAAuB,YAAY,UAAU,aAAa,QAAQ,CAAC,CAAC;QAClF,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtD,CAAC;CACF;AAED,mBAAmB;AACnB,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cell Primitive
|
|
3
|
+
*
|
|
4
|
+
* Represents a single unit of executable code.
|
|
5
|
+
* Cells can be combined into notebooks for sequential execution.
|
|
6
|
+
*/
|
|
7
|
+
import type { Cell, Language, ExecutionResult, ExecutionContext } from "./types.js";
|
|
8
|
+
import type { CompileResult } from "./compiler.js";
|
|
9
|
+
/**
|
|
10
|
+
* Cell metadata
|
|
11
|
+
*/
|
|
12
|
+
export interface CellMetadata {
|
|
13
|
+
/** Cell display order */
|
|
14
|
+
index?: number;
|
|
15
|
+
/** Cell is collapsed */
|
|
16
|
+
collapsed?: boolean;
|
|
17
|
+
/** Cell execution count */
|
|
18
|
+
executionCount?: number;
|
|
19
|
+
/** Tags for organization */
|
|
20
|
+
tags?: string[];
|
|
21
|
+
/** Custom metadata */
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Cell execution state
|
|
26
|
+
*/
|
|
27
|
+
export type CellState = "idle" | "queued" | "running" | "success" | "error" | "cancelled";
|
|
28
|
+
/**
|
|
29
|
+
* Extended cell with execution tracking
|
|
30
|
+
*/
|
|
31
|
+
export interface ExecutableCell extends Cell {
|
|
32
|
+
/** Current state */
|
|
33
|
+
state: CellState;
|
|
34
|
+
/** Last execution result */
|
|
35
|
+
result?: ExecutionResult;
|
|
36
|
+
/** Execution count (notebook-style) */
|
|
37
|
+
executionCount?: number;
|
|
38
|
+
/** Last execution timestamp */
|
|
39
|
+
lastRun?: Date;
|
|
40
|
+
/** Dependencies on other cells */
|
|
41
|
+
dependencies?: string[];
|
|
42
|
+
/** Exports from this cell */
|
|
43
|
+
exports?: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Cell Builder
|
|
47
|
+
*
|
|
48
|
+
* Fluent API for creating cells.
|
|
49
|
+
*/
|
|
50
|
+
export declare class CellBuilder {
|
|
51
|
+
private id;
|
|
52
|
+
private language;
|
|
53
|
+
private source;
|
|
54
|
+
private metadata;
|
|
55
|
+
setId(id: string): this;
|
|
56
|
+
setLanguage(lang: Language): this;
|
|
57
|
+
setSource(code: string): this;
|
|
58
|
+
addMetadata(key: string, value: unknown): this;
|
|
59
|
+
setIndex(index: number): this;
|
|
60
|
+
addTag(tag: string): this;
|
|
61
|
+
build(): Cell;
|
|
62
|
+
buildExecutable(): ExecutableCell;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Cell Executor
|
|
66
|
+
*
|
|
67
|
+
* Handles execution of individual cells.
|
|
68
|
+
*/
|
|
69
|
+
export declare class CellExecutor {
|
|
70
|
+
private compileFn;
|
|
71
|
+
private executeFn;
|
|
72
|
+
constructor(compileFn: (cell: Cell) => Promise<CompileResult>, executeFn: (compiled: CompileResult, context: ExecutionContext) => Promise<ExecutionResult>);
|
|
73
|
+
/**
|
|
74
|
+
* Execute a cell
|
|
75
|
+
*/
|
|
76
|
+
execute(cell: ExecutableCell, context: ExecutionContext): Promise<ExecutionResult>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Cell Registry
|
|
80
|
+
*
|
|
81
|
+
* Tracks cells and their relationships.
|
|
82
|
+
*/
|
|
83
|
+
export declare class CellRegistry {
|
|
84
|
+
private cells;
|
|
85
|
+
private dependencies;
|
|
86
|
+
private dependents;
|
|
87
|
+
/**
|
|
88
|
+
* Add a cell
|
|
89
|
+
*/
|
|
90
|
+
add(cell: ExecutableCell): void;
|
|
91
|
+
/**
|
|
92
|
+
* Get a cell by ID
|
|
93
|
+
*/
|
|
94
|
+
get(id: string): ExecutableCell | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Remove a cell
|
|
97
|
+
*/
|
|
98
|
+
remove(id: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Get all cells
|
|
101
|
+
*/
|
|
102
|
+
getAll(): ExecutableCell[];
|
|
103
|
+
/**
|
|
104
|
+
* Get cells by language
|
|
105
|
+
*/
|
|
106
|
+
getByLanguage(language: Language): ExecutableCell[];
|
|
107
|
+
/**
|
|
108
|
+
* Get cells by state
|
|
109
|
+
*/
|
|
110
|
+
getByState(state: CellState): ExecutableCell[];
|
|
111
|
+
/**
|
|
112
|
+
* Add dependency between cells
|
|
113
|
+
*/
|
|
114
|
+
addDependency(cellId: string, dependsOn: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get dependencies of a cell
|
|
117
|
+
*/
|
|
118
|
+
getDependencies(cellId: string): string[];
|
|
119
|
+
/**
|
|
120
|
+
* Get dependents of a cell (cells that depend on this one)
|
|
121
|
+
*/
|
|
122
|
+
getDependents(cellId: string): string[];
|
|
123
|
+
/**
|
|
124
|
+
* Get execution order (topological sort)
|
|
125
|
+
*/
|
|
126
|
+
getExecutionOrder(): string[];
|
|
127
|
+
/**
|
|
128
|
+
* Check if cell has circular dependencies
|
|
129
|
+
*/
|
|
130
|
+
hasCircularDependency(cellId: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Get cells that need re-execution after a cell changes
|
|
133
|
+
*/
|
|
134
|
+
getCellsToReexecute(cellId: string): string[];
|
|
135
|
+
/**
|
|
136
|
+
* Clear all cells
|
|
137
|
+
*/
|
|
138
|
+
clear(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Get count
|
|
141
|
+
*/
|
|
142
|
+
get count(): number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a simple cell
|
|
146
|
+
*/
|
|
147
|
+
export declare function createCell(language: Language, source: string, options?: {
|
|
148
|
+
id?: string;
|
|
149
|
+
metadata?: CellMetadata;
|
|
150
|
+
dependencies?: string[];
|
|
151
|
+
}): ExecutableCell;
|
|
152
|
+
/**
|
|
153
|
+
* Create cells from code blocks
|
|
154
|
+
*/
|
|
155
|
+
export declare function createCellsFromMarkdown(markdown: string, defaultLanguage?: Language): ExecutableCell[];
|
|
156
|
+
/**
|
|
157
|
+
* Convert cells to markdown
|
|
158
|
+
*/
|
|
159
|
+
export declare function cellsToMarkdown(cells: ExecutableCell[]): string;
|
|
160
|
+
//# sourceMappingURL=cell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../src/core/cell.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,eAAe,EAEf,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2BAA2B;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,sBAAsB;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,QAAQ,GACR,SAAS,GACT,SAAS,GACT,O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