@5ive-tech/sdk 1.1.10 → 1.1.12
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 +1 -1
- package/dist/FiveSDK.d.ts +1 -4
- package/dist/FiveSDK.js +47 -5
- package/dist/accounts/index.js +3 -2
- package/dist/assets/vm/dummy.file +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.js +3307 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm +0 -0
- package/dist/assets/vm/five_vm_wasm_bg.wasm.d.ts +5 -5
- package/dist/compiler/BytecodeCompiler.d.ts +1 -7
- package/dist/compiler/BytecodeCompiler.js +105 -44
- package/dist/config/ProgramIdResolver.d.ts +1 -6
- package/dist/config/ProgramIdResolver.js +11 -16
- package/dist/config/VmClusterConfigResolver.d.ts +27 -0
- package/dist/config/VmClusterConfigResolver.js +111 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/modules/accounts.js +7 -1
- package/dist/modules/admin.js +25 -12
- package/dist/modules/deploy.js +55 -21
- package/dist/modules/execute.js +58 -32
- package/dist/modules/vm-state.js +6 -1
- package/dist/project/config.js +0 -1
- package/dist/testing/TestRunner.js +6 -1
- package/dist/types.d.ts +19 -2
- package/dist/utils/abi.d.ts +4 -0
- package/dist/utils/abi.js +3 -0
- package/dist/utils/transaction.d.ts +22 -0
- package/dist/utils/transaction.js +94 -12
- package/dist/wasm/compiler/CompilationLogic.d.ts +0 -5
- package/dist/wasm/compiler/CompilationLogic.js +45 -163
- package/dist/wasm/compiler/FiveCompiler.d.ts +0 -5
- package/dist/wasm/compiler/FiveCompiler.js +0 -6
- package/dist/wasm/compiler/utils.d.ts +34 -1
- package/dist/wasm/compiler/utils.js +223 -5
- package/package.json +4 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, writeFile } from "fs/promises";
|
|
2
|
-
import { createCompilerError, extractMetrics, extractAbi } from "./utils.js";
|
|
2
|
+
import { createCompilerError, extractMetrics, extractAbi, extractFormattedErrors, extractDiagnostics, } from "./utils.js";
|
|
3
3
|
export async function compile(ctx, source, options) {
|
|
4
4
|
if (!ctx.compiler) {
|
|
5
5
|
throw createCompilerError("Compiler not initialized");
|
|
@@ -25,7 +25,8 @@ export async function compile(ctx, source, options) {
|
|
|
25
25
|
.with_metrics(includeMetrics)
|
|
26
26
|
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
27
27
|
.with_metrics_format(metricsFormat)
|
|
28
|
-
.with_error_format(errorFormat)
|
|
28
|
+
.with_error_format(errorFormat)
|
|
29
|
+
.with_source_file(options?.sourceFile || "input.v");
|
|
29
30
|
result = ctx.compiler.compile(source, compilationOptions);
|
|
30
31
|
if (result.compiler_errors && result.compiler_errors.length > 0) {
|
|
31
32
|
ctx.logger.debug(`WASM returned ${result.compiler_errors.length} compiler errors`);
|
|
@@ -50,6 +51,8 @@ export async function compile(ctx, source, options) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
54
|
+
const formattedErrors = extractFormattedErrors(result);
|
|
55
|
+
const diagnostics = extractDiagnostics(result, ctx.logger);
|
|
53
56
|
if (result.success && result.bytecode) {
|
|
54
57
|
return {
|
|
55
58
|
success: true,
|
|
@@ -58,79 +61,33 @@ export async function compile(ctx, source, options) {
|
|
|
58
61
|
metadata: result.metadata,
|
|
59
62
|
metrics: metricsPayload,
|
|
60
63
|
metricsReport: metricsPayload,
|
|
64
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
65
|
+
formattedErrorsJson: formattedErrors.json,
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
else {
|
|
64
69
|
return {
|
|
65
70
|
success: false,
|
|
66
|
-
errors:
|
|
71
|
+
errors: diagnostics,
|
|
72
|
+
warnings: diagnostics.filter((diag) => diag.severity === "warning"),
|
|
73
|
+
diagnostics,
|
|
67
74
|
metadata: result.metadata,
|
|
68
75
|
metrics: metricsPayload,
|
|
69
76
|
metricsReport: metricsPayload,
|
|
77
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
78
|
+
formattedErrorsJson: formattedErrors.json,
|
|
70
79
|
};
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
catch (error) {
|
|
74
|
-
if (
|
|
75
|
-
|
|
83
|
+
if (error &&
|
|
84
|
+
typeof error === "object" &&
|
|
85
|
+
error.code === "COMPILER_ERROR") {
|
|
86
|
+
throw error;
|
|
76
87
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export async function compileModules(ctx, mainSource, modules, options) {
|
|
83
|
-
if (!ctx.compiler) {
|
|
84
|
-
throw createCompilerError("Compiler not initialized");
|
|
85
|
-
}
|
|
86
|
-
const startTime = Date.now();
|
|
87
|
-
try {
|
|
88
|
-
let WasmCompilationOptions = ctx.WasmCompilationOptions;
|
|
89
|
-
if (!WasmCompilationOptions && ctx.wasmModuleRef) {
|
|
90
|
-
WasmCompilationOptions = ctx.wasmModuleRef.WasmCompilationOptions;
|
|
91
|
-
}
|
|
92
|
-
const metricsFormat = options?.metricsFormat || "json";
|
|
93
|
-
const includeMetrics = options?.includeMetrics || Boolean(options?.metricsOutput);
|
|
94
|
-
const errorFormat = options?.errorFormat || "terminal";
|
|
95
|
-
const comprehensiveMetrics = options?.comprehensiveMetrics || false;
|
|
96
|
-
const compilationOptions = new WasmCompilationOptions()
|
|
97
|
-
.with_mode(options?.target || "deployment")
|
|
98
|
-
.with_optimization_level(options?.optimizationLevel || "production")
|
|
99
|
-
.with_v2_preview(true)
|
|
100
|
-
.with_constraint_cache(false)
|
|
101
|
-
.with_enhanced_errors(true)
|
|
102
|
-
.with_metrics(includeMetrics)
|
|
103
|
-
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
104
|
-
.with_metrics_format(metricsFormat)
|
|
105
|
-
.with_error_format(errorFormat);
|
|
106
|
-
const result = ctx.compiler.compile_multi(mainSource, modules, compilationOptions);
|
|
107
|
-
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
108
|
-
if (result.success && result.bytecode) {
|
|
109
|
-
return {
|
|
110
|
-
success: true,
|
|
111
|
-
bytecode: result.bytecode,
|
|
112
|
-
abi: extractAbi(result, ctx.logger),
|
|
113
|
-
metadata: result.metadata,
|
|
114
|
-
metrics: metricsPayload,
|
|
115
|
-
metricsReport: metricsPayload,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return {
|
|
120
|
-
success: false,
|
|
121
|
-
errors: result.compiler_errors || [],
|
|
122
|
-
metadata: result.metadata,
|
|
123
|
-
metrics: metricsPayload,
|
|
124
|
-
metricsReport: metricsPayload,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error);
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
const compilationTime = Date.now() - startTime;
|
|
133
|
-
ctx.logger.debug(`Multi-file compilation completed in ${compilationTime}ms`);
|
|
88
|
+
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error, {
|
|
89
|
+
phase: "compile",
|
|
90
|
+
});
|
|
134
91
|
}
|
|
135
92
|
}
|
|
136
93
|
export async function compileFile(ctx, options) {
|
|
@@ -233,60 +190,17 @@ export async function compileFile(ctx, options) {
|
|
|
233
190
|
}
|
|
234
191
|
const compilationTime = Date.now() - startTime;
|
|
235
192
|
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
const jsonErrors = result.format_all_json
|
|
240
|
-
? result.format_all_json()
|
|
241
|
-
: null;
|
|
242
|
-
if (jsonErrors) {
|
|
243
|
-
const parsedErrors = JSON.parse(jsonErrors);
|
|
244
|
-
convertedErrors = parsedErrors.map((error) => ({
|
|
245
|
-
type: "enhanced",
|
|
246
|
-
...error,
|
|
247
|
-
code: error.code || "E0000",
|
|
248
|
-
severity: error.severity || "error",
|
|
249
|
-
category: error.category || "compilation",
|
|
250
|
-
message: error.message || "Unknown error",
|
|
251
|
-
}));
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
convertedErrors = [
|
|
255
|
-
{
|
|
256
|
-
type: "enhanced",
|
|
257
|
-
code: "E0004",
|
|
258
|
-
severity: "error",
|
|
259
|
-
category: "compilation",
|
|
260
|
-
message: "InvalidScript",
|
|
261
|
-
description: "The script contains syntax or semantic errors",
|
|
262
|
-
location: undefined,
|
|
263
|
-
suggestions: [],
|
|
264
|
-
},
|
|
265
|
-
];
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
catch (parseError) {
|
|
269
|
-
ctx.logger.debug("Failed to parse JSON errors from WASM:", parseError);
|
|
270
|
-
convertedErrors = [
|
|
271
|
-
{
|
|
272
|
-
type: "enhanced",
|
|
273
|
-
code: "E0004",
|
|
274
|
-
severity: "error",
|
|
275
|
-
category: "compilation",
|
|
276
|
-
message: "InvalidScript",
|
|
277
|
-
description: "Compilation failed with enhanced error system",
|
|
278
|
-
location: undefined,
|
|
279
|
-
suggestions: [],
|
|
280
|
-
},
|
|
281
|
-
];
|
|
282
|
-
}
|
|
283
|
-
}
|
|
193
|
+
const formattedErrors = extractFormattedErrors(result);
|
|
194
|
+
const diagnostics = extractDiagnostics(result, ctx.logger);
|
|
284
195
|
const compilationResult = {
|
|
285
196
|
success: result.success,
|
|
286
197
|
bytecode: result.bytecode ? new Uint8Array(result.bytecode) : undefined,
|
|
287
198
|
abi: result.abi || undefined,
|
|
288
|
-
errors:
|
|
289
|
-
warnings:
|
|
199
|
+
errors: diagnostics,
|
|
200
|
+
warnings: diagnostics.filter((diag) => diag.severity === "warning"),
|
|
201
|
+
diagnostics,
|
|
202
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
203
|
+
formattedErrorsJson: formattedErrors.json,
|
|
290
204
|
metrics: {
|
|
291
205
|
compilationTime: result.compilation_time || compilationTime,
|
|
292
206
|
bytecodeSize: result.bytecode_size || 0,
|
|
@@ -353,9 +267,12 @@ export async function compileWithDiscovery(ctx, entryPoint, options) {
|
|
|
353
267
|
.with_metrics(includeMetrics)
|
|
354
268
|
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
355
269
|
.with_metrics_format(metricsFormat)
|
|
356
|
-
.with_error_format(errorFormat)
|
|
270
|
+
.with_error_format(errorFormat)
|
|
271
|
+
.with_source_file(entryPoint);
|
|
357
272
|
const result = ctx.compiler.compileMultiWithDiscovery(entryPoint, compilationOptions);
|
|
358
273
|
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
274
|
+
const formattedErrors = extractFormattedErrors(result);
|
|
275
|
+
const diagnostics = extractDiagnostics(result, ctx.logger);
|
|
359
276
|
if (result.success && result.bytecode) {
|
|
360
277
|
return {
|
|
361
278
|
success: true,
|
|
@@ -364,68 +281,33 @@ export async function compileWithDiscovery(ctx, entryPoint, options) {
|
|
|
364
281
|
metadata: result.metadata,
|
|
365
282
|
metrics: metricsPayload,
|
|
366
283
|
metricsReport: metricsPayload,
|
|
284
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
285
|
+
formattedErrorsJson: formattedErrors.json,
|
|
367
286
|
};
|
|
368
287
|
}
|
|
369
288
|
else {
|
|
370
289
|
return {
|
|
371
290
|
success: false,
|
|
372
|
-
errors:
|
|
291
|
+
errors: diagnostics,
|
|
292
|
+
warnings: diagnostics.filter((diag) => diag.severity === "warning"),
|
|
293
|
+
diagnostics,
|
|
373
294
|
metadata: result.metadata,
|
|
374
295
|
metrics: metricsPayload,
|
|
375
296
|
metricsReport: metricsPayload,
|
|
297
|
+
formattedErrorsTerminal: formattedErrors.terminal,
|
|
298
|
+
formattedErrorsJson: formattedErrors.json,
|
|
376
299
|
};
|
|
377
300
|
}
|
|
378
301
|
}
|
|
379
302
|
catch (error) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (!ctx.compiler) {
|
|
385
|
-
throw createCompilerError("Compiler not initialized");
|
|
386
|
-
}
|
|
387
|
-
try {
|
|
388
|
-
let WasmCompilationOptions = ctx.WasmCompilationOptions;
|
|
389
|
-
if (!WasmCompilationOptions && ctx.wasmModuleRef) {
|
|
390
|
-
WasmCompilationOptions = ctx.wasmModuleRef.WasmCompilationOptions;
|
|
303
|
+
if (error &&
|
|
304
|
+
typeof error === "object" &&
|
|
305
|
+
error.code === "COMPILER_ERROR") {
|
|
306
|
+
throw error;
|
|
391
307
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const compilationOptions = new WasmCompilationOptions()
|
|
397
|
-
.with_mode(options?.target || "deployment")
|
|
398
|
-
.with_optimization_level(options?.optimizationLevel || "production")
|
|
399
|
-
.with_v2_preview(true)
|
|
400
|
-
.with_constraint_cache(false)
|
|
401
|
-
.with_enhanced_errors(true)
|
|
402
|
-
.with_metrics(includeMetrics)
|
|
403
|
-
.with_comprehensive_metrics(comprehensiveMetrics)
|
|
404
|
-
.with_metrics_format(metricsFormat)
|
|
405
|
-
.with_error_format(errorFormat);
|
|
406
|
-
const result = ctx.compiler.compileModules(moduleFiles, entryPoint, compilationOptions);
|
|
407
|
-
const metricsPayload = extractMetrics(result, metricsFormat);
|
|
408
|
-
if (result.success && result.bytecode) {
|
|
409
|
-
return {
|
|
410
|
-
success: true,
|
|
411
|
-
bytecode: result.bytecode,
|
|
412
|
-
abi: result.abi,
|
|
413
|
-
metadata: result.metadata,
|
|
414
|
-
metrics: metricsPayload,
|
|
415
|
-
metricsReport: metricsPayload,
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
return {
|
|
420
|
-
success: false,
|
|
421
|
-
errors: result.compiler_errors || [],
|
|
422
|
-
metadata: result.metadata,
|
|
423
|
-
metrics: metricsPayload,
|
|
424
|
-
metricsReport: metricsPayload,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
catch (error) {
|
|
429
|
-
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error);
|
|
308
|
+
throw createCompilerError(`Compilation error: ${error instanceof Error ? error.message : "Unknown error"}`, error, {
|
|
309
|
+
phase: "compileWithDiscovery",
|
|
310
|
+
entryPoint,
|
|
311
|
+
});
|
|
430
312
|
}
|
|
431
313
|
}
|
|
@@ -17,13 +17,8 @@ export declare class FiveCompiler {
|
|
|
17
17
|
initialize(): Promise<void>;
|
|
18
18
|
private getContext;
|
|
19
19
|
compile(source: string, options?: any): Promise<any>;
|
|
20
|
-
compileModules(mainSource: string, modules: Array<{
|
|
21
|
-
name: string;
|
|
22
|
-
source: string;
|
|
23
|
-
}>, options?: any): Promise<any>;
|
|
24
20
|
compileFile(options: CompilationOptions): Promise<CompilationResult>;
|
|
25
21
|
compileWithDiscovery(entryPoint: string, options?: any): Promise<any>;
|
|
26
|
-
compileModulesExplicit(moduleFiles: string[], entryPoint: string, options?: any): Promise<any>;
|
|
27
22
|
generateABI(sourceCode: string): Promise<any>;
|
|
28
23
|
extractAccountDefinitions(sourceCode: string): Promise<any>;
|
|
29
24
|
extractFunctionSignatures(sourceCode: string): Promise<any>;
|
|
@@ -121,18 +121,12 @@ export class FiveCompiler {
|
|
|
121
121
|
async compile(source, options) {
|
|
122
122
|
return CompilationLogic.compile(this.getContext(), source, options);
|
|
123
123
|
}
|
|
124
|
-
async compileModules(mainSource, modules, options) {
|
|
125
|
-
return CompilationLogic.compileModules(this.getContext(), mainSource, modules, options);
|
|
126
|
-
}
|
|
127
124
|
async compileFile(options) {
|
|
128
125
|
return CompilationLogic.compileFile(this.getContext(), options);
|
|
129
126
|
}
|
|
130
127
|
async compileWithDiscovery(entryPoint, options) {
|
|
131
128
|
return CompilationLogic.compileWithDiscovery(this.getContext(), entryPoint, options);
|
|
132
129
|
}
|
|
133
|
-
async compileModulesExplicit(moduleFiles, entryPoint, options) {
|
|
134
|
-
return CompilationLogic.compileModulesExplicit(this.getContext(), moduleFiles, entryPoint, options);
|
|
135
|
-
}
|
|
136
130
|
// --- ABI & Extraction ---
|
|
137
131
|
async generateABI(sourceCode) {
|
|
138
132
|
return AbiLogic.generateABI(this.getContext(), sourceCode);
|
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
import { CLIError } from "../../types.js";
|
|
2
|
-
export
|
|
2
|
+
export interface NormalizedCompilationSuggestion {
|
|
3
|
+
message: string;
|
|
4
|
+
explanation?: string;
|
|
5
|
+
confidence?: number;
|
|
6
|
+
codeSuggestion?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface NormalizedCompilationDiagnostic {
|
|
9
|
+
type: string;
|
|
10
|
+
code: string;
|
|
11
|
+
severity: string;
|
|
12
|
+
category: string;
|
|
13
|
+
message: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
line?: number;
|
|
16
|
+
column?: number;
|
|
17
|
+
sourceLocation?: string;
|
|
18
|
+
location?: any;
|
|
19
|
+
suggestion?: string;
|
|
20
|
+
suggestions?: NormalizedCompilationSuggestion[];
|
|
21
|
+
sourceLine?: string;
|
|
22
|
+
sourceSnippet?: string;
|
|
23
|
+
rendered?: string;
|
|
24
|
+
raw?: any;
|
|
25
|
+
}
|
|
26
|
+
export interface FormattedErrors {
|
|
27
|
+
terminal?: string;
|
|
28
|
+
json?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function createCompilerError(message: string, cause?: Error, details?: Record<string, unknown>): CLIError;
|
|
31
|
+
export declare function extractFormattedErrors(result: any): FormattedErrors;
|
|
32
|
+
export declare function normalizeDiagnostic(error: any): NormalizedCompilationDiagnostic;
|
|
33
|
+
export declare function extractDiagnostics(result: any, logger?: {
|
|
34
|
+
debug?: (...args: any[]) => void;
|
|
35
|
+
}): NormalizedCompilationDiagnostic[];
|
|
3
36
|
export declare function extractMetrics(result: any, defaultFormat: string): {
|
|
4
37
|
format: string;
|
|
5
38
|
exported: string;
|
|
@@ -1,17 +1,235 @@
|
|
|
1
|
-
|
|
1
|
+
const COMPILER_ERROR_CODE = "COMPILER_ERROR";
|
|
2
|
+
function isObject(value) {
|
|
3
|
+
return typeof value === "object" && value !== null;
|
|
4
|
+
}
|
|
5
|
+
function toOptionalString(value) {
|
|
6
|
+
return typeof value === "string" && value.trim().length > 0
|
|
7
|
+
? value
|
|
8
|
+
: undefined;
|
|
9
|
+
}
|
|
10
|
+
function toOptionalNumber(value) {
|
|
11
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
15
|
+
const parsed = Number(value);
|
|
16
|
+
if (Number.isFinite(parsed)) {
|
|
17
|
+
return parsed;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
function readStringMethod(target, methodName) {
|
|
23
|
+
if (!target || typeof target !== "object") {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const maybeMethod = target[methodName];
|
|
27
|
+
if (typeof maybeMethod !== "function") {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const value = maybeMethod.call(target);
|
|
32
|
+
return toOptionalString(value);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function readStringProperty(target, propName) {
|
|
39
|
+
if (!target || typeof target !== "object") {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return toOptionalString(target[propName]);
|
|
43
|
+
}
|
|
44
|
+
function normalizeSuggestion(suggestion) {
|
|
45
|
+
if (typeof suggestion === "string") {
|
|
46
|
+
return { message: suggestion };
|
|
47
|
+
}
|
|
48
|
+
if (!isObject(suggestion)) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const message = toOptionalString(suggestion.message) ??
|
|
52
|
+
toOptionalString(suggestion.explanation);
|
|
53
|
+
if (!message) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
message,
|
|
58
|
+
explanation: toOptionalString(suggestion.explanation),
|
|
59
|
+
confidence: toOptionalNumber(suggestion.confidence),
|
|
60
|
+
codeSuggestion: toOptionalString(suggestion.code_suggestion) ??
|
|
61
|
+
toOptionalString(suggestion.codeSuggestion),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function pickSuggestions(rawSuggestions) {
|
|
65
|
+
if (!Array.isArray(rawSuggestions)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const normalized = rawSuggestions
|
|
69
|
+
.map((item) => normalizeSuggestion(item))
|
|
70
|
+
.filter((item) => Boolean(item));
|
|
71
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
72
|
+
}
|
|
73
|
+
function buildFallbackSuggestions(code) {
|
|
74
|
+
switch (code) {
|
|
75
|
+
case "E2000":
|
|
76
|
+
return [
|
|
77
|
+
{
|
|
78
|
+
message: "Declare the variable before use with `let <name> = ...`.",
|
|
79
|
+
confidence: 0.8,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
message: "Check for spelling differences between parameter/field names and usages.",
|
|
83
|
+
confidence: 0.7,
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
case "E0002":
|
|
87
|
+
return [
|
|
88
|
+
{
|
|
89
|
+
message: "Check for missing closing `}`, `)`, or an incomplete function signature.",
|
|
90
|
+
confidence: 0.75,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
case "E0001":
|
|
94
|
+
case "E0004":
|
|
95
|
+
return [
|
|
96
|
+
{
|
|
97
|
+
message: "Check for missing punctuation (`;`, `{`, `}`) near the reported statement.",
|
|
98
|
+
confidence: 0.7,
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
default:
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function createCompilerError(message, cause, details) {
|
|
106
|
+
if (cause &&
|
|
107
|
+
isObject(cause) &&
|
|
108
|
+
cause.code === COMPILER_ERROR_CODE) {
|
|
109
|
+
return cause;
|
|
110
|
+
}
|
|
2
111
|
const error = new Error(message);
|
|
3
112
|
error.name = "CompilerError";
|
|
4
|
-
error.code =
|
|
113
|
+
error.code = COMPILER_ERROR_CODE;
|
|
5
114
|
error.category = "wasm";
|
|
6
115
|
error.exitCode = 1;
|
|
7
|
-
if (cause) {
|
|
116
|
+
if (cause || details) {
|
|
117
|
+
const inheritedDetails = cause && isObject(cause.details)
|
|
118
|
+
? cause.details
|
|
119
|
+
: undefined;
|
|
8
120
|
error.details = {
|
|
9
|
-
|
|
10
|
-
|
|
121
|
+
...(inheritedDetails || {}),
|
|
122
|
+
...(details || {}),
|
|
123
|
+
...(cause
|
|
124
|
+
? {
|
|
125
|
+
cause: cause.message,
|
|
126
|
+
stack: cause.stack,
|
|
127
|
+
}
|
|
128
|
+
: {}),
|
|
11
129
|
};
|
|
12
130
|
}
|
|
13
131
|
return error;
|
|
14
132
|
}
|
|
133
|
+
export function extractFormattedErrors(result) {
|
|
134
|
+
const terminal = readStringMethod(result, "get_formatted_errors_terminal") ||
|
|
135
|
+
readStringProperty(result, "formattedErrorsTerminal") ||
|
|
136
|
+
readStringProperty(result, "formatted_errors_terminal") ||
|
|
137
|
+
readStringMethod(result, "format_all_terminal");
|
|
138
|
+
const json = readStringMethod(result, "format_all_json") ||
|
|
139
|
+
readStringMethod(result, "get_formatted_errors_json") ||
|
|
140
|
+
readStringProperty(result, "formattedErrorsJson") ||
|
|
141
|
+
readStringProperty(result, "formatted_errors_json");
|
|
142
|
+
return { terminal, json };
|
|
143
|
+
}
|
|
144
|
+
export function normalizeDiagnostic(error) {
|
|
145
|
+
let parsedJson;
|
|
146
|
+
if (error && typeof error?.format_json === "function") {
|
|
147
|
+
try {
|
|
148
|
+
const raw = error.format_json();
|
|
149
|
+
const parsed = JSON.parse(raw);
|
|
150
|
+
if (isObject(parsed)) {
|
|
151
|
+
parsedJson = parsed;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Ignore formatter/parsing failures and continue with direct field access.
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const merged = {
|
|
159
|
+
...(parsedJson || {}),
|
|
160
|
+
...(isObject(error) ? error : {}),
|
|
161
|
+
};
|
|
162
|
+
const location = isObject(merged.location) ? merged.location : undefined;
|
|
163
|
+
const line = toOptionalNumber(merged.line) ?? toOptionalNumber(location?.line);
|
|
164
|
+
const column = toOptionalNumber(merged.column) ?? toOptionalNumber(location?.column);
|
|
165
|
+
const file = toOptionalString(merged.sourceLocation) ??
|
|
166
|
+
toOptionalString(location?.file);
|
|
167
|
+
const code = toOptionalString(merged.code) || "E0000";
|
|
168
|
+
const suggestionList = pickSuggestions(merged.suggestions) || buildFallbackSuggestions(code);
|
|
169
|
+
const rendered = toOptionalString(merged.rendered) ||
|
|
170
|
+
(typeof merged.format_terminal === "function"
|
|
171
|
+
? toOptionalString(merged.format_terminal())
|
|
172
|
+
: undefined);
|
|
173
|
+
return {
|
|
174
|
+
type: toOptionalString(merged.type) || "enhanced",
|
|
175
|
+
code,
|
|
176
|
+
severity: toOptionalString(merged.severity) || "error",
|
|
177
|
+
category: toOptionalString(merged.category) || "compilation",
|
|
178
|
+
message: toOptionalString(merged.message) ||
|
|
179
|
+
toOptionalString(merged.description) ||
|
|
180
|
+
"Unknown compiler error",
|
|
181
|
+
description: toOptionalString(merged.description),
|
|
182
|
+
line,
|
|
183
|
+
column,
|
|
184
|
+
sourceLocation: file,
|
|
185
|
+
location,
|
|
186
|
+
suggestion: suggestionList?.[0]?.message,
|
|
187
|
+
suggestions: suggestionList,
|
|
188
|
+
sourceLine: toOptionalString(merged.source_line) ||
|
|
189
|
+
toOptionalString(merged.sourceLine),
|
|
190
|
+
sourceSnippet: toOptionalString(merged.source_snippet) ||
|
|
191
|
+
toOptionalString(merged.sourceSnippet),
|
|
192
|
+
rendered,
|
|
193
|
+
raw: error,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function parseDiagnosticsJson(jsonPayload, logger) {
|
|
197
|
+
try {
|
|
198
|
+
const parsed = JSON.parse(jsonPayload);
|
|
199
|
+
const arr = Array.isArray(parsed)
|
|
200
|
+
? parsed
|
|
201
|
+
: Array.isArray(parsed?.errors)
|
|
202
|
+
? parsed.errors
|
|
203
|
+
: [];
|
|
204
|
+
return arr.map((item) => normalizeDiagnostic(item));
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
logger?.debug?.("[Compilation] Failed to parse formatted JSON diagnostics", error);
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export function extractDiagnostics(result, logger) {
|
|
212
|
+
const formatted = extractFormattedErrors(result);
|
|
213
|
+
if (formatted.json) {
|
|
214
|
+
const parsed = parseDiagnosticsJson(formatted.json, logger);
|
|
215
|
+
if (parsed.length > 0) {
|
|
216
|
+
return parsed;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (Array.isArray(result?.compiler_errors)) {
|
|
220
|
+
const fromCompiler = result.compiler_errors.map((item) => normalizeDiagnostic(item));
|
|
221
|
+
if (fromCompiler.length > 0) {
|
|
222
|
+
return fromCompiler;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (Array.isArray(result?.errors)) {
|
|
226
|
+
const fromErrors = result.errors.map((item) => normalizeDiagnostic(item));
|
|
227
|
+
if (fromErrors.length > 0) {
|
|
228
|
+
return fromErrors;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
15
233
|
export function extractMetrics(result, defaultFormat) {
|
|
16
234
|
if (!result || typeof result !== "object") {
|
|
17
235
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@5ive-tech/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "Client-agnostic TypeScript SDK for Five VM scripts on Solana",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"sync:wasm:rebuild": "bash ../scripts/sync-wasm-assets.sh --rebuild",
|
|
35
35
|
"verify:wasm": "bash ../scripts/verify-wasm-sync.sh",
|
|
36
36
|
"copy-assets": "mkdir -p dist/assets/vm && COPYFILE_DISABLE=1 cp src/assets/vm/* dist/assets/vm/",
|
|
37
|
-
"test": "
|
|
37
|
+
"test": "npm run test:jest --",
|
|
38
|
+
"test:example": "node src/examples/basic-usage.js",
|
|
38
39
|
"test:jest": "NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
|
|
39
40
|
"test:localnet": "USE_SOLANA_MOCKS=0 RUN_LOCALNET_VALIDATOR_TESTS=1 NODE_OPTIONS=--experimental-vm-modules jest --runInBand src/__tests__/integration/localnet-fee-vault.test.ts",
|
|
40
41
|
"gen-types": "node ./node_modules/typescript/bin/tsc && node dist/bin/gen-types.js",
|
|
@@ -57,4 +58,4 @@
|
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|
|
59
60
|
}
|
|
60
|
-
}
|
|
61
|
+
}
|