@5ive-tech/sdk 1.1.10 → 1.1.13
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 +3 -4
- package/dist/FiveSDK.js +47 -5
- package/dist/accounts/index.js +3 -2
- 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/bin/gen-types.js +0 -0
- 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 +62 -23
- package/dist/modules/execute.js +71 -37
- package/dist/modules/vm-state.js +6 -1
- package/dist/program/FunctionBuilder.d.ts +8 -0
- package/dist/program/FunctionBuilder.js +18 -5
- 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,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.13",
|
|
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
|
+
}
|