@secondlayer/cli 0.3.6 → 0.3.7
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/cli.js +22 -23
- package/dist/cli.js.map +4 -4
- package/dist/index.js +24 -37
- package/dist/index.js.map +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -344,17 +344,19 @@ function clarityTypeToTS(type) {
|
|
|
344
344
|
case "principal":
|
|
345
345
|
case "trait_reference":
|
|
346
346
|
return "string";
|
|
347
|
-
default:
|
|
348
|
-
|
|
347
|
+
default: {
|
|
348
|
+
const typeStr = type;
|
|
349
|
+
if (typeStr.includes("string") || typeStr.includes("ascii") || typeStr.includes("utf8")) {
|
|
349
350
|
return "string";
|
|
350
351
|
}
|
|
351
|
-
if (
|
|
352
|
+
if (typeStr.includes("buff")) {
|
|
352
353
|
return "Uint8Array | string | { type: 'ascii' | 'utf8' | 'hex'; value: string }";
|
|
353
354
|
}
|
|
354
|
-
if (
|
|
355
|
+
if (typeStr.includes("uint") || typeStr.includes("int")) {
|
|
355
356
|
return "bigint";
|
|
356
357
|
}
|
|
357
358
|
return "any";
|
|
359
|
+
}
|
|
358
360
|
}
|
|
359
361
|
}
|
|
360
362
|
if (isClarityBuffer(type)) {
|
|
@@ -424,15 +426,22 @@ function getApiUrl(
|
|
|
424
426
|
return API_URLS[network];
|
|
425
427
|
}`;
|
|
426
428
|
}
|
|
429
|
+
function generateValidationUtils() {
|
|
430
|
+
return `/**
|
|
431
|
+
* Contract name validation regex
|
|
432
|
+
* Must start with letter, contain only letters, numbers, and hyphens, max 128 chars
|
|
433
|
+
*/
|
|
434
|
+
const CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;`;
|
|
435
|
+
}
|
|
427
436
|
async function generateContractInterface(contracts) {
|
|
428
|
-
const imports = `import { Cl, validateStacksAddress } from '@stacks/transactions'
|
|
429
|
-
import { jsToClarity, ClarityConversionError, CONTRACT_NAME_REGEX } from '@secondlayer/clarity-types'`;
|
|
437
|
+
const imports = `import { Cl, validateStacksAddress } from '@stacks/transactions'`;
|
|
430
438
|
const header = `/**
|
|
431
439
|
* Generated by @secondlayer/cli
|
|
432
440
|
* DO NOT EDIT MANUALLY
|
|
433
441
|
*
|
|
434
442
|
* @requires @stacks/transactions - Install with: npm install @stacks/transactions
|
|
435
443
|
*/`;
|
|
444
|
+
const validationUtils = generateValidationUtils();
|
|
436
445
|
const networkUtils = generateNetworkUtils();
|
|
437
446
|
const contractsCode = contracts.map((contract) => generateContract(contract)).join(`
|
|
438
447
|
|
|
@@ -441,6 +450,8 @@ import { jsToClarity, ClarityConversionError, CONTRACT_NAME_REGEX } from '@secon
|
|
|
441
450
|
|
|
442
451
|
${header}
|
|
443
452
|
|
|
453
|
+
${validationUtils}
|
|
454
|
+
|
|
444
455
|
${networkUtils}
|
|
445
456
|
|
|
446
457
|
${contractsCode}`;
|
|
@@ -623,11 +634,7 @@ function generateClarityConversion(argName, argType) {
|
|
|
623
634
|
return `(() => {
|
|
624
635
|
const listValue = ${argName};
|
|
625
636
|
if (listValue.length > ${maxLength}) {
|
|
626
|
-
throw new
|
|
627
|
-
\`List length \${listValue.length} exceeds max ${maxLength}\`,
|
|
628
|
-
${JSON.stringify(type)},
|
|
629
|
-
listValue
|
|
630
|
-
);
|
|
637
|
+
throw new Error(\`List length \${listValue.length} exceeds max ${maxLength}\`);
|
|
631
638
|
}
|
|
632
639
|
return Cl.list(listValue.map(item => ${innerConversion}));
|
|
633
640
|
})()`;
|
|
@@ -646,11 +653,7 @@ function generateClarityConversion(argName, argType) {
|
|
|
646
653
|
for (const fieldName of requiredFields) {
|
|
647
654
|
const camelName = fieldName.replace(/-([a-z])/g, (_: string, l: string) => l.toUpperCase());
|
|
648
655
|
if (!(fieldName in tupleValue) && !(camelName in tupleValue)) {
|
|
649
|
-
throw new
|
|
650
|
-
\`Missing tuple field: \${fieldName}\`,
|
|
651
|
-
${JSON.stringify(type)},
|
|
652
|
-
tupleValue
|
|
653
|
-
);
|
|
656
|
+
throw new Error(\`Missing tuple field: \${fieldName}\`);
|
|
654
657
|
}
|
|
655
658
|
}
|
|
656
659
|
return Cl.tuple({ ${fields} });
|
|
@@ -673,11 +676,7 @@ function generateClarityConversion(argName, argType) {
|
|
|
673
676
|
if (hasErr && !hasOk) {
|
|
674
677
|
return Cl.error(${errConversion});
|
|
675
678
|
}
|
|
676
|
-
throw new
|
|
677
|
-
"Response must have exactly 'ok' or 'err' property",
|
|
678
|
-
${JSON.stringify(type)},
|
|
679
|
-
responseValue
|
|
680
|
-
);
|
|
679
|
+
throw new Error("Response must have exactly 'ok' or 'err' property");
|
|
681
680
|
})()`;
|
|
682
681
|
}
|
|
683
682
|
return `${argName}`;
|
|
@@ -1033,11 +1032,7 @@ function generateClarityConversion2(argName, argType) {
|
|
|
1033
1032
|
return `(() => {
|
|
1034
1033
|
const listValue = ${argName};
|
|
1035
1034
|
if (listValue.length > ${maxLength}) {
|
|
1036
|
-
throw new
|
|
1037
|
-
\`List length \${listValue.length} exceeds max ${maxLength}\`,
|
|
1038
|
-
${JSON.stringify(type)},
|
|
1039
|
-
listValue
|
|
1040
|
-
);
|
|
1035
|
+
throw new Error(\`List length \${listValue.length} exceeds max ${maxLength}\`);
|
|
1041
1036
|
}
|
|
1042
1037
|
return Cl.list(listValue.map(item => ${innerConversion}));
|
|
1043
1038
|
})()`;
|
|
@@ -1056,11 +1051,7 @@ function generateClarityConversion2(argName, argType) {
|
|
|
1056
1051
|
for (const fieldName of requiredFields) {
|
|
1057
1052
|
const camelName = fieldName.replace(/-([a-z])/g, (_: string, l: string) => l.toUpperCase());
|
|
1058
1053
|
if (!(fieldName in tupleValue) && !(camelName in tupleValue)) {
|
|
1059
|
-
throw new
|
|
1060
|
-
\`Missing tuple field: \${fieldName}\`,
|
|
1061
|
-
${JSON.stringify(type)},
|
|
1062
|
-
tupleValue
|
|
1063
|
-
);
|
|
1054
|
+
throw new Error(\`Missing tuple field: \${fieldName}\`);
|
|
1064
1055
|
}
|
|
1065
1056
|
}
|
|
1066
1057
|
return Cl.tuple({ ${fields} });
|
|
@@ -1083,11 +1074,7 @@ function generateClarityConversion2(argName, argType) {
|
|
|
1083
1074
|
if (hasErr && !hasOk) {
|
|
1084
1075
|
return Cl.error(${errConversion});
|
|
1085
1076
|
}
|
|
1086
|
-
throw new
|
|
1087
|
-
"Response must have exactly 'ok' or 'err' property",
|
|
1088
|
-
${JSON.stringify(type)},
|
|
1089
|
-
responseValue
|
|
1090
|
-
);
|
|
1077
|
+
throw new Error("Response must have exactly 'ok' or 'err' property");
|
|
1091
1078
|
})()`;
|
|
1092
1079
|
}
|
|
1093
1080
|
return `${argName}`;
|
|
@@ -2937,5 +2924,5 @@ export {
|
|
|
2937
2924
|
PluginManager
|
|
2938
2925
|
};
|
|
2939
2926
|
|
|
2940
|
-
//# debugId=
|
|
2927
|
+
//# debugId=7C8745101A6FCC2D64756E2164756E21
|
|
2941
2928
|
//# sourceMappingURL=index.js.map
|