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