@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/cli.js
CHANGED
|
@@ -15885,17 +15885,19 @@ function clarityTypeToTS(type) {
|
|
|
15885
15885
|
case "principal":
|
|
15886
15886
|
case "trait_reference":
|
|
15887
15887
|
return "string";
|
|
15888
|
-
default:
|
|
15889
|
-
|
|
15888
|
+
default: {
|
|
15889
|
+
const typeStr = type;
|
|
15890
|
+
if (typeStr.includes("string") || typeStr.includes("ascii") || typeStr.includes("utf8")) {
|
|
15890
15891
|
return "string";
|
|
15891
15892
|
}
|
|
15892
|
-
if (
|
|
15893
|
+
if (typeStr.includes("buff")) {
|
|
15893
15894
|
return "Uint8Array | string | { type: 'ascii' | 'utf8' | 'hex'; value: string }";
|
|
15894
15895
|
}
|
|
15895
|
-
if (
|
|
15896
|
+
if (typeStr.includes("uint") || typeStr.includes("int")) {
|
|
15896
15897
|
return "bigint";
|
|
15897
15898
|
}
|
|
15898
15899
|
return "any";
|
|
15900
|
+
}
|
|
15899
15901
|
}
|
|
15900
15902
|
}
|
|
15901
15903
|
if (isClarityBuffer(type)) {
|
|
@@ -15970,15 +15972,22 @@ function getApiUrl(
|
|
|
15970
15972
|
return API_URLS[network];
|
|
15971
15973
|
}`;
|
|
15972
15974
|
}
|
|
15975
|
+
function generateValidationUtils() {
|
|
15976
|
+
return `/**
|
|
15977
|
+
* Contract name validation regex
|
|
15978
|
+
* Must start with letter, contain only letters, numbers, and hyphens, max 128 chars
|
|
15979
|
+
*/
|
|
15980
|
+
const CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;`;
|
|
15981
|
+
}
|
|
15973
15982
|
async function generateContractInterface(contracts) {
|
|
15974
|
-
const imports = `import { Cl, validateStacksAddress } from '@stacks/transactions'
|
|
15975
|
-
import { jsToClarity, ClarityConversionError, CONTRACT_NAME_REGEX } from '@secondlayer/clarity-types'`;
|
|
15983
|
+
const imports = `import { Cl, validateStacksAddress } from '@stacks/transactions'`;
|
|
15976
15984
|
const header = `/**
|
|
15977
15985
|
* Generated by @secondlayer/cli
|
|
15978
15986
|
* DO NOT EDIT MANUALLY
|
|
15979
15987
|
*
|
|
15980
15988
|
* @requires @stacks/transactions - Install with: npm install @stacks/transactions
|
|
15981
15989
|
*/`;
|
|
15990
|
+
const validationUtils = generateValidationUtils();
|
|
15982
15991
|
const networkUtils = generateNetworkUtils();
|
|
15983
15992
|
const contractsCode = contracts.map((contract) => generateContract(contract)).join(`
|
|
15984
15993
|
|
|
@@ -15987,6 +15996,8 @@ import { jsToClarity, ClarityConversionError, CONTRACT_NAME_REGEX } from '@secon
|
|
|
15987
15996
|
|
|
15988
15997
|
${header}
|
|
15989
15998
|
|
|
15999
|
+
${validationUtils}
|
|
16000
|
+
|
|
15990
16001
|
${networkUtils}
|
|
15991
16002
|
|
|
15992
16003
|
${contractsCode}`;
|
|
@@ -16169,11 +16180,7 @@ function generateClarityConversion(argName, argType) {
|
|
|
16169
16180
|
return `(() => {
|
|
16170
16181
|
const listValue = ${argName};
|
|
16171
16182
|
if (listValue.length > ${maxLength}) {
|
|
16172
|
-
throw new
|
|
16173
|
-
\`List length \${listValue.length} exceeds max ${maxLength}\`,
|
|
16174
|
-
${JSON.stringify(type)},
|
|
16175
|
-
listValue
|
|
16176
|
-
);
|
|
16183
|
+
throw new Error(\`List length \${listValue.length} exceeds max ${maxLength}\`);
|
|
16177
16184
|
}
|
|
16178
16185
|
return Cl.list(listValue.map(item => ${innerConversion}));
|
|
16179
16186
|
})()`;
|
|
@@ -16192,11 +16199,7 @@ function generateClarityConversion(argName, argType) {
|
|
|
16192
16199
|
for (const fieldName of requiredFields) {
|
|
16193
16200
|
const camelName = fieldName.replace(/-([a-z])/g, (_: string, l: string) => l.toUpperCase());
|
|
16194
16201
|
if (!(fieldName in tupleValue) && !(camelName in tupleValue)) {
|
|
16195
|
-
throw new
|
|
16196
|
-
\`Missing tuple field: \${fieldName}\`,
|
|
16197
|
-
${JSON.stringify(type)},
|
|
16198
|
-
tupleValue
|
|
16199
|
-
);
|
|
16202
|
+
throw new Error(\`Missing tuple field: \${fieldName}\`);
|
|
16200
16203
|
}
|
|
16201
16204
|
}
|
|
16202
16205
|
return Cl.tuple({ ${fields} });
|
|
@@ -16219,11 +16222,7 @@ function generateClarityConversion(argName, argType) {
|
|
|
16219
16222
|
if (hasErr && !hasOk) {
|
|
16220
16223
|
return Cl.error(${errConversion});
|
|
16221
16224
|
}
|
|
16222
|
-
throw new
|
|
16223
|
-
"Response must have exactly 'ok' or 'err' property",
|
|
16224
|
-
${JSON.stringify(type)},
|
|
16225
|
-
responseValue
|
|
16226
|
-
);
|
|
16225
|
+
throw new Error("Response must have exactly 'ok' or 'err' property");
|
|
16227
16226
|
})()`;
|
|
16228
16227
|
}
|
|
16229
16228
|
return `${argName}`;
|
|
@@ -28235,7 +28234,7 @@ var {
|
|
|
28235
28234
|
// package.json
|
|
28236
28235
|
var package_default = {
|
|
28237
28236
|
name: "@secondlayer/cli",
|
|
28238
|
-
version: "0.3.
|
|
28237
|
+
version: "0.3.7",
|
|
28239
28238
|
description: "CLI for generating type-safe contract interfaces for the Stacks blockchain",
|
|
28240
28239
|
type: "module",
|
|
28241
28240
|
bin: {
|
|
@@ -28311,5 +28310,5 @@ program.command("init").description("Initialize a new stacks.config.ts file").ac
|
|
|
28311
28310
|
});
|
|
28312
28311
|
program.parse();
|
|
28313
28312
|
|
|
28314
|
-
//# debugId=
|
|
28313
|
+
//# debugId=58D4865FBB414E7B64756E2164756E21
|
|
28315
28314
|
//# sourceMappingURL=cli.js.map
|