forked from StarknetAstro/AstroEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.ts
More file actions
95 lines (79 loc) · 3.23 KB
/
worker.ts
File metadata and controls
95 lines (79 loc) · 3.23 KB
1
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import wasmCairo, {
compileStarknetContract,
runTests,
runCairoProgram,
compileCairoProgram,
greet,
getCairoVersion,
// Multi-file project APIs
compileCairoProject,
runCairoProject,
compileStarknetProject,
runProjectTests,
} from './src/pkg/wasm-cairo.js';
import * as Comlink from 'comlink';
interface ITestOptions {
cairoProgram: string;
allowWarnings: boolean;
filter: string;
includeIgnored: boolean;
ignored: boolean;
starknet: boolean;
runProfiler: string;
gasDisabled: boolean;
printResourceUsage: boolean;
}
interface IProjectInput {
projectJson: string;
}
class CairoWorker {
private initPromise: Promise<void>;
init = async () => {
await wasmCairo();
greet('Hello World');
}
constructor() {
this.initPromise = this.init();
}
// ========== Version info ==========
async getCairoVersion() {
await this.initPromise;
return getCairoVersion();
}
// ========== Single-file APIs ==========
async runCairoProgram({cairoProgram, availableGas, printFullMemory, useDBGPrintHint, allWarnings = true, runProfiler = false}: any) {
const res = runCairoProgram(cairoProgram, availableGas, allWarnings, printFullMemory, runProfiler, useDBGPrintHint);
return res;
}
async compileCairoProgram({cairoProgram, replaceIds}: any) {
const res = compileCairoProgram(cairoProgram, replaceIds);
return res;
}
async compileStarknetContract({starknetContract, allowWarnings, replaceIds, outputCasm = false}: any) {
const res = compileStarknetContract(starknetContract, allowWarnings, replaceIds, outputCasm);
return res;
}
async runTests({cairoProgram, allowWarnings = true, filter = '', includeIgnored = true, ignored = true, starknet = false, runProfiler = '', gasDisabled = true, printResourceUsage = true, }: ITestOptions) {
const res = runTests(cairoProgram, allowWarnings, filter, includeIgnored, ignored, starknet, runProfiler, gasDisabled, printResourceUsage);
return res;
}
// ========== Multi-file project APIs ==========
async compileCairoProject({projectJson, replaceIds = true}: any) {
const res = compileCairoProject(projectJson, replaceIds);
return res;
}
async runCairoProject({projectJson, availableGas, allowWarnings = true, printFullMemory = true, runProfiler = false, useDBGPrintHint = true}: any) {
const res = runCairoProject(projectJson, availableGas, allowWarnings, printFullMemory, runProfiler, useDBGPrintHint);
return res;
}
async compileStarknetProject({projectJson, allowWarnings = true, replaceIds = true, outputCasm = false}: any) {
const res = compileStarknetProject(projectJson, allowWarnings, replaceIds, outputCasm);
return res;
}
async runProjectTests({projectJson, allowWarnings = true, filter = '', includeIgnored = true, ignored = true, starknet = false, gasDisabled = true, printResourceUsage = true}: any) {
const res = runProjectTests(projectJson, allowWarnings, filter, includeIgnored, ignored, starknet, gasDisabled, printResourceUsage);
return res;
}
}
export {CairoWorker};
Comlink.expose(CairoWorker);