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