@secondlayer/cli 8.6.1 → 8.6.3

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.
@@ -387,562 +387,15 @@ var init_plugin_manager = __esm(() => {
387
387
  validateStacksAddress = _validateStacksAddress;
388
388
  });
389
389
 
390
- // src/utils/clarity-conversion.ts
391
- import {
392
- isAbiBuffer,
393
- isAbiList,
394
- isAbiOptional,
395
- isAbiResponse,
396
- isAbiStringAscii,
397
- isAbiStringUtf8,
398
- isAbiTuple,
399
- toCamelCase as toCamelCase2
400
- } from "@secondlayer/stacks/clarity";
401
- function generateClarityConversion(argName, argType) {
402
- const type = argType.type;
403
- if (typeof type === "string") {
404
- switch (type) {
405
- case "uint128":
406
- return `Cl.uint(${argName})`;
407
- case "int128":
408
- return `Cl.int(${argName})`;
409
- case "bool":
410
- return `Cl.bool(${argName})`;
411
- case "principal":
412
- case "trait_reference":
413
- return `(() => {
414
- const [address, contractName] = ${argName}.split(".") as [string, string | undefined];
415
- if (!validateStacksAddress(address)) {
416
- throw new Error("Invalid Stacks address format");
417
- }
418
- if (contractName !== undefined) {
419
- if (!CONTRACT_NAME_REGEX.test(contractName)) {
420
- throw new Error("Invalid contract name format: must start with letter and contain only letters, numbers, and hyphens");
421
- }
422
- return Cl.contractPrincipal(address, contractName);
423
- }
424
- return Cl.standardPrincipal(${argName});
425
- })()`;
426
- default:
427
- return `${argName}`;
428
- }
429
- }
430
- if (isAbiStringAscii(type)) {
431
- return `Cl.stringAscii(${argName})`;
432
- }
433
- if (isAbiStringUtf8(type)) {
434
- return `Cl.stringUtf8(${argName})`;
435
- }
436
- if (isAbiBuffer(type)) {
437
- return `(() => {
438
- const value = ${argName};
439
- if (value instanceof Uint8Array) {
440
- return Cl.buffer(value);
441
- }
442
- if (typeof value === 'object' && value !== null && value.type && value.value) {
443
- switch (value.type) {
444
- case 'ascii':
445
- return Cl.bufferFromAscii(value.value);
446
- case 'utf8':
447
- return Cl.bufferFromUtf8(value.value);
448
- case 'hex':
449
- return Cl.bufferFromHex(value.value);
450
- default:
451
- throw new Error(\`Unsupported buffer type: \${value.type}\`);
452
- }
453
- }
454
- if (typeof value === 'string') {
455
- if (value.startsWith('0x') || /^[0-9a-fA-F]+$/.test(value)) {
456
- return Cl.bufferFromHex(value);
457
- }
458
- const hasNonAscii = value.split('').some(char => char.charCodeAt(0) > 127);
459
- if (hasNonAscii) {
460
- return Cl.bufferFromUtf8(value);
461
- }
462
- return Cl.bufferFromAscii(value);
463
- }
464
- throw new Error(\`Invalid buffer value: \${value}\`);
465
- })()`;
466
- }
467
- if (isAbiOptional(type)) {
468
- const innerConversion = generateClarityConversion(argName, {
469
- type: type.optional
470
- });
471
- return `${argName} !== null ? Cl.some(${innerConversion.replace(argName, `${argName}`)}) : Cl.none()`;
472
- }
473
- if (isAbiList(type)) {
474
- const innerConversion = generateClarityConversion("item", {
475
- type: type.list.type
476
- });
477
- const maxLength = type.list.length || 100;
478
- return `(() => {
479
- const listValue = ${argName};
480
- if (listValue.length > ${maxLength}) {
481
- throw new Error(\`List length \${listValue.length} exceeds max ${maxLength}\`);
482
- }
483
- return Cl.list(listValue.map(item => ${innerConversion}));
484
- })()`;
485
- }
486
- if (isAbiTuple(type)) {
487
- const requiredFields = type.tuple.map((f) => f.name);
488
- const fieldNames = JSON.stringify(requiredFields);
489
- const fields = type.tuple.map((field) => {
490
- const camelFieldName = toCamelCase2(field.name);
491
- const fieldConversion = generateClarityConversion(`tupleValue.${camelFieldName}`, { type: field.type });
492
- return `"${field.name}": ${fieldConversion}`;
493
- }).join(", ");
494
- return `(() => {
495
- const tupleValue = ${argName};
496
- const requiredFields = ${fieldNames};
497
- for (const fieldName of requiredFields) {
498
- const camelName = fieldName.replace(/-([a-z])/g, (_: string, l: string) => l.toUpperCase());
499
- if (!(fieldName in tupleValue) && !(camelName in tupleValue)) {
500
- throw new Error(\`Missing tuple field: \${fieldName}\`);
501
- }
502
- }
503
- return Cl.tuple({ ${fields} });
504
- })()`;
505
- }
506
- if (isAbiResponse(type)) {
507
- const okConversion = generateClarityConversion("responseValue.ok", {
508
- type: type.response.ok
509
- });
510
- const errConversion = generateClarityConversion("responseValue.err", {
511
- type: type.response.error
512
- });
513
- return `(() => {
514
- const responseValue = ${argName};
515
- const hasOk = 'ok' in responseValue;
516
- const hasErr = 'err' in responseValue;
517
- if (hasOk && !hasErr) {
518
- return Cl.ok(${okConversion});
519
- }
520
- if (hasErr && !hasOk) {
521
- return Cl.error(${errConversion});
522
- }
523
- throw new Error("Response must have exactly 'ok' or 'err' property");
524
- })()`;
525
- }
526
- return `${argName}`;
527
- }
528
- var init_clarity_conversion = () => {};
529
-
530
- // src/utils/type-mapping.ts
531
- import {
532
- isAbiBuffer as isAbiBuffer2,
533
- isAbiList as isAbiList2,
534
- isAbiOptional as isAbiOptional2,
535
- isAbiResponse as isAbiResponse2,
536
- isAbiStringAscii as isAbiStringAscii2,
537
- isAbiStringUtf8 as isAbiStringUtf82,
538
- isAbiTuple as isAbiTuple2,
539
- toCamelCase as toCamelCase3
540
- } from "@secondlayer/stacks/clarity";
541
- function clarityTypeToTS(type) {
542
- if (typeof type === "string") {
543
- switch (type) {
544
- case "uint128":
545
- case "int128":
546
- return "bigint";
547
- case "bool":
548
- return "boolean";
549
- case "principal":
550
- case "trait_reference":
551
- return "string";
552
- default: {
553
- const typeStr = type;
554
- if (typeStr === "none") {
555
- return "null";
556
- }
557
- if (typeStr.includes("string") || typeStr.includes("ascii") || typeStr.includes("utf8")) {
558
- return "string";
559
- }
560
- if (typeStr.includes("buff")) {
561
- return "Uint8Array | string | { type: 'ascii' | 'utf8' | 'hex'; value: string }";
562
- }
563
- if (typeStr.includes("uint") || typeStr.includes("int")) {
564
- return "bigint";
565
- }
566
- return "any";
567
- }
568
- }
569
- }
570
- if (isAbiBuffer2(type)) {
571
- return "Uint8Array | string | { type: 'ascii' | 'utf8' | 'hex'; value: string }";
572
- }
573
- if (isAbiStringAscii2(type) || isAbiStringUtf82(type)) {
574
- return "string";
575
- }
576
- if (isAbiOptional2(type)) {
577
- const innerType = clarityTypeToTS(type.optional);
578
- if (innerType.includes(" | ") && !innerType.startsWith("(")) {
579
- return `(${innerType}) | null`;
580
- }
581
- return `${innerType} | null`;
582
- }
583
- if (isAbiList2(type)) {
584
- const innerType = clarityTypeToTS(type.list.type);
585
- if (innerType.includes(" | ") && !innerType.startsWith("(")) {
586
- return `(${innerType})[]`;
587
- }
588
- return `${innerType}[]`;
589
- }
590
- if (isAbiTuple2(type)) {
591
- const fields = type.tuple.map((field) => `${toCamelCase3(field.name)}: ${clarityTypeToTS(field.type)}`).join("; ");
592
- return `{ ${fields} }`;
593
- }
594
- if (isAbiResponse2(type)) {
595
- const okType = clarityTypeToTS(type.response.ok);
596
- const errType = clarityTypeToTS(type.response.error);
597
- return `{ ok: ${okType} } | { err: ${errType} }`;
598
- }
599
- return "any";
600
- }
601
- function getTypeForArg(arg) {
602
- return clarityTypeToTS(arg.type);
603
- }
604
- var init_type_mapping = () => {};
605
-
606
- // src/utils/generator-helpers.ts
607
- import {
608
- isAbiTuple as isAbiTuple3,
609
- toCamelCase as toCamelCase4
610
- } from "@secondlayer/stacks/clarity";
611
- function generateArgsSignature(args) {
612
- if (args.length === 0)
613
- return "";
614
- const argsTypes = args.map((arg) => {
615
- const camelName = toCamelCase4(arg.name);
616
- return `${camelName}: ${getTypeForArg(arg)}`;
617
- }).join("; ");
618
- return `args: { ${argsTypes} }, `;
619
- }
620
- function generateClarityArgs(args) {
621
- if (args.length === 0)
622
- return "";
623
- return args.map((arg) => {
624
- const argName = `args.${toCamelCase4(arg.name)}`;
625
- return generateClarityConversion(argName, arg);
626
- }).join(", ");
627
- }
628
- function generateMapKeyConversion(keyType) {
629
- if (isAbiTuple3(keyType)) {
630
- const fields = keyType.tuple.map((field) => {
631
- const camelFieldName = toCamelCase4(field.name);
632
- const fieldConversion = generateClarityConversion(`key.${camelFieldName}`, { type: field.type });
633
- return `"${field.name}": ${fieldConversion}`;
634
- }).join(", ");
635
- return `Cl.tuple({ ${fields} })`;
636
- }
637
- return generateClarityConversion("key", { type: keyType });
638
- }
639
- var init_generator_helpers = __esm(() => {
640
- init_clarity_conversion();
641
- init_type_mapping();
642
- });
643
-
644
390
  // src/generators/contract.ts
645
391
  import {
646
- toCamelCase as toCamelCase5
647
- } from "@secondlayer/stacks/clarity";
648
- function generateNetworkUtils() {
649
- return `/**
650
- * API URLs for different networks
651
- */
652
- const API_URLS: Record<'mainnet' | 'testnet' | 'devnet', string> = {
653
- mainnet: 'https://api.hiro.so',
654
- testnet: 'https://api.testnet.hiro.so',
655
- devnet: 'http://localhost:3999'
656
- };
657
-
658
- /**
659
- * Infer network from Stacks address prefix
660
- * SP/SM = mainnet, ST/SN = testnet
661
- */
662
- function inferNetworkFromAddress(address: string): 'mainnet' | 'testnet' | undefined {
663
- if (address.startsWith('SP') || address.startsWith('SM')) return 'mainnet';
664
- if (address.startsWith('ST') || address.startsWith('SN')) return 'testnet';
665
- return undefined;
666
- }
667
-
668
- /**
669
- * Get API URL, inferring network from contract address if not specified
670
- */
671
- function getApiUrl(
672
- contractAddress: string,
673
- explicitNetwork?: 'mainnet' | 'testnet' | 'devnet'
674
- ): string {
675
- const network = explicitNetwork ?? inferNetworkFromAddress(contractAddress) ?? 'mainnet';
676
- return API_URLS[network];
677
- }`;
678
- }
679
- function generateValidationUtils() {
680
- return `/**
681
- * Contract name validation regex
682
- * Must start with letter, contain only letters, numbers, and hyphens, max 128 chars
683
- */
684
- const CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;`;
685
- }
392
+ generateContractInterface as buildContractInterface
393
+ } from "@secondlayer/scaffold";
686
394
  async function generateContractInterface(contracts) {
687
- const imports = `import { Cl, validateStacksAddress } from '@secondlayer/stacks'`;
688
- const header = `/**
689
- * Generated by @secondlayer/cli
690
- * DO NOT EDIT MANUALLY
691
- *
692
- * @requires @secondlayer/stacks - Install with: npm install @secondlayer/stacks
693
- */`;
694
- const validationUtils = generateValidationUtils();
695
- const networkUtils = generateNetworkUtils();
696
- const contractsCode = contracts.map((contract) => generateContract(contract)).join(`
697
-
698
- `);
699
- const code = `${imports}
700
-
701
- ${header}
702
-
703
- ${validationUtils}
704
-
705
- ${networkUtils}
706
-
707
- ${contractsCode}`;
708
- return formatCode(code);
709
- }
710
- function generateContract(contract) {
711
- const { name, address, contractName, abi } = contract;
712
- const abiCode = generateAbiConstant(name, abi);
713
- const methods = abi.functions.filter((func) => func.access !== "private").map((func) => generateMethod(func, address, contractName)).join(`,
714
-
715
- `);
716
- const mapsObject = generateMapsObject(abi.maps || [], address, contractName);
717
- const varsObject = generateVarsObject(abi.variables || [], address, contractName);
718
- const constantsObject = generateConstantsObject(abi.variables || [], address, contractName);
719
- const allMembers = [methods, mapsObject, varsObject, constantsObject].filter(Boolean);
720
- const contractCode = `export const ${name} = {
721
- address: '${address}',
722
- contractAddress: '${address}',
723
- contractName: '${contractName}',
724
-
725
- ${allMembers.join(`,
726
-
727
- `)}
728
- } as const`;
729
- return `${abiCode}
730
-
731
- ${contractCode}`;
732
- }
733
- function generateAbiConstant(name, abi) {
734
- const abiJson = JSON.stringify(abi, null, 2).replace(/"([a-zA-Z_$][a-zA-Z0-9_$]*)":/g, "$1:").replace(/"/g, "'");
735
- return `export const ${name}Abi = ${abiJson} as const`;
736
- }
737
- function generateMethod(func, address, contractName) {
738
- const methodName = toCamelCase5(func.name);
739
- if (func.args.length === 0) {
740
- return `${methodName}() {
741
- return {
742
- contractAddress: '${address}',
743
- contractName: '${contractName}',
744
- functionName: '${func.name}',
745
- functionArgs: []
746
- }
747
- }`;
748
- }
749
- if (func.args.length === 1) {
750
- const originalArgName = func.args[0].name;
751
- const argName = toCamelCase5(originalArgName);
752
- const argType = getTypeForArg(func.args[0]);
753
- const clarityConversion = generateClarityConversion(argName, func.args[0]);
754
- return `${methodName}(...args: [{ ${argName}: ${argType} }] | [${argType}]) {
755
- const ${argName} = args.length === 1 && typeof args[0] === 'object' && args[0] !== null && '${argName}' in args[0]
756
- ? args[0].${argName}
757
- : args[0] as ${argType}
758
-
759
- return {
760
- contractAddress: '${address}',
761
- contractName: '${contractName}',
762
- functionName: '${func.name}',
763
- functionArgs: [${clarityConversion}]
764
- }
765
- }`;
766
- }
767
- const argsList = func.args.map((arg) => toCamelCase5(arg.name)).join(", ");
768
- const argsTypes = func.args.map((arg) => {
769
- const camelName = toCamelCase5(arg.name);
770
- return `${camelName}: ${getTypeForArg(arg)}`;
771
- }).join("; ");
772
- const argsArray = func.args.map((arg) => {
773
- const argName = toCamelCase5(arg.name);
774
- return generateClarityConversion(argName, arg);
775
- }).join(", ");
776
- const objectAccess = func.args.map((arg) => {
777
- const camelName = toCamelCase5(arg.name);
778
- return `args[0].${camelName}`;
779
- }).join(", ");
780
- const positionTypes = func.args.map((arg) => getTypeForArg(arg)).join(", ");
781
- return `${methodName}(...args: [{ ${argsTypes} }] | [${positionTypes}]) {
782
- const [${argsList}] = args.length === 1 && typeof args[0] === 'object' && args[0] !== null
783
- ? [${objectAccess}]
784
- : args as [${positionTypes}]
785
-
786
- return {
787
- contractAddress: '${address}',
788
- contractName: '${contractName}',
789
- functionName: '${func.name}',
790
- functionArgs: [${argsArray}]
791
- }
792
- }`;
793
- }
794
- function generateMapsObject(maps, address, contractName) {
795
- if (!maps || maps.length === 0) {
796
- return "";
797
- }
798
- const mapMethods = maps.map((map) => {
799
- const methodName = toCamelCase5(map.name);
800
- const keyType = getTypeForArg({ type: map.key });
801
- const valueType = getTypeForArg({ type: map.value });
802
- const keyConversion = generateMapKeyConversion(map.key);
803
- return `${methodName}: {
804
- async get(key: ${keyType}, options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType} | null> {
805
- try {
806
- const { cvToJSON, serializeCV } = await import('@secondlayer/stacks/clarity');
807
- const baseUrl = getApiUrl('${address}', options?.network);
808
- const mapKey = ${keyConversion};
809
- const keyHex = serializeCV(mapKey).toString('hex');
810
-
811
- const response = await fetch(
812
- \`\${baseUrl}/v2/map_entry/${address}/${contractName}/${map.name}\`,
813
- {
814
- method: 'POST',
815
- headers: { 'Content-Type': 'application/json' },
816
- body: JSON.stringify(keyHex)
817
- }
818
- );
819
-
820
- if (!response.ok) {
821
- throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
822
- }
823
-
824
- const result = await response.json();
825
- if (!result.data || result.data === '0x09') {
826
- return null; // none value
827
- }
828
-
829
- const { deserializeCV } = await import('@secondlayer/stacks/clarity');
830
- const cv = deserializeCV(result.data);
831
- const parsed = cvToJSON(cv);
832
- // Unwrap the (some ...) wrapper
833
- return parsed.value?.value ?? parsed.value ?? null;
834
- } catch (error) {
835
- if (error instanceof Error) {
836
- throw new Error(\`Map access failed for '${map.name}': \${error.message}\`);
837
- }
838
- throw error;
839
- }
840
- },
841
- keyType: ${JSON.stringify(map.key)} as const,
842
- valueType: ${JSON.stringify(map.value)} as const
843
- }`;
844
- });
845
- return `maps: {
846
- ${mapMethods.join(`,
847
-
848
- `)}
849
- }`;
850
- }
851
- function generateVarsObject(variables, address, contractName) {
852
- if (!variables || variables.length === 0) {
853
- return "";
854
- }
855
- const dataVars = variables.filter((v) => v.access === "variable");
856
- if (dataVars.length === 0) {
857
- return "";
858
- }
859
- const varMethods = dataVars.map((variable) => {
860
- const methodName = toCamelCase5(variable.name);
861
- const valueType = getTypeForArg({ type: variable.type });
862
- return `${methodName}: {
863
- async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
864
- try {
865
- const { cvToJSON, deserializeCV } = await import('@secondlayer/stacks/clarity');
866
- const baseUrl = getApiUrl('${address}', options?.network);
867
-
868
- const response = await fetch(
869
- \`\${baseUrl}/v2/data_var/${address}/${contractName}/${variable.name}?proof=0\`
870
- );
871
-
872
- if (!response.ok) {
873
- throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
874
- }
875
-
876
- const result = await response.json();
877
- const cv = deserializeCV(result.data);
878
- const parsed = cvToJSON(cv);
879
- return parsed.value ?? parsed;
880
- } catch (error) {
881
- if (error instanceof Error) {
882
- throw new Error(\`Variable access failed for '${variable.name}': \${error.message}\`);
883
- }
884
- throw error;
885
- }
886
- },
887
- type: ${JSON.stringify(variable.type)} as const
888
- }`;
889
- });
890
- return `vars: {
891
- ${varMethods.join(`,
892
-
893
- `)}
894
- }`;
895
- }
896
- function generateConstantsObject(variables, address, contractName) {
897
- if (!variables || variables.length === 0) {
898
- return "";
899
- }
900
- const constants = variables.filter((v) => v.access === "constant");
901
- if (constants.length === 0) {
902
- return "";
903
- }
904
- const constMethods = constants.map((constant) => {
905
- const methodName = toCamelCase5(constant.name);
906
- const valueType = getTypeForArg({ type: constant.type });
907
- return `${methodName}: {
908
- async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
909
- try {
910
- const { cvToJSON, deserializeCV } = await import('@secondlayer/stacks/clarity');
911
- const baseUrl = getApiUrl('${address}', options?.network);
912
-
913
- const response = await fetch(
914
- \`\${baseUrl}/v2/constant_val/${address}/${contractName}/${constant.name}?proof=0\`
915
- );
916
-
917
- if (!response.ok) {
918
- throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
919
- }
920
-
921
- const result = await response.json();
922
- const cv = deserializeCV(result.data);
923
- const parsed = cvToJSON(cv);
924
- return parsed.value ?? parsed;
925
- } catch (error) {
926
- if (error instanceof Error) {
927
- throw new Error(\`Constant access failed for '${constant.name}': \${error.message}\`);
928
- }
929
- throw error;
930
- }
931
- },
932
- type: ${JSON.stringify(constant.type)} as const
933
- }`;
934
- });
935
- return `constants: {
936
- ${constMethods.join(`,
937
-
938
- `)}
939
- }`;
395
+ return formatCode(buildContractInterface(contracts));
940
396
  }
941
397
  var init_contract = __esm(() => {
942
- init_clarity_conversion();
943
398
  init_format();
944
- init_generator_helpers();
945
- init_type_mapping();
946
399
  });
947
400
 
948
401
  // src/utils/abi-compat.ts
@@ -1104,9 +557,9 @@ init_plugin_manager();
1104
557
  // src/plugins/clarinet/index.ts
1105
558
  init_contract();
1106
559
  import { initSimnet } from "@hirosystems/clarinet-sdk";
1107
- import { toCamelCase as toCamelCase6 } from "@secondlayer/stacks/clarity";
560
+ import { toCamelCase as toCamelCase2 } from "@secondlayer/stacks/clarity";
1108
561
  function sanitizeContractName(name) {
1109
- return toCamelCase6(name);
562
+ return toCamelCase2(name);
1110
563
  }
1111
564
  async function isUserDefinedContract(contractId, manifestPath) {
1112
565
  const { address, contractName } = parseContractId(contractId);
@@ -1217,8 +670,16 @@ async function hasClarinetProject(path2 = "./Clarinet.toml") {
1217
670
  }
1218
671
  }
1219
672
  // src/plugins/actions/generators.ts
1220
- init_generator_helpers();
1221
- import { toCamelCase as toCamelCase7 } from "@secondlayer/stacks/clarity";
673
+ import { toCamelCase as toCamelCase3 } from "@secondlayer/stacks/clarity";
674
+
675
+ // src/utils/generator-helpers.ts
676
+ import {
677
+ generateArgsSignature,
678
+ generateClarityArgs,
679
+ generateMapKeyConversion
680
+ } from "@secondlayer/scaffold";
681
+
682
+ // src/plugins/actions/generators.ts
1222
683
  function generateReadHelpers(contract, options) {
1223
684
  const { abi } = contract;
1224
685
  const functions = abi.functions || [];
@@ -1239,7 +700,7 @@ function generateReadHelpers(contract, options) {
1239
700
  return "";
1240
701
  }
1241
702
  const helpers = filteredFunctions.map((func) => {
1242
- const methodName = toCamelCase7(func.name);
703
+ const methodName = toCamelCase3(func.name);
1243
704
  const argsSignature = generateArgsSignature(func.args);
1244
705
  const clarityArgs = generateClarityArgs(func.args);
1245
706
  return `async ${methodName}(${argsSignature}options?: {
@@ -1283,7 +744,7 @@ function generateWriteHelpers(contract, options) {
1283
744
  return "";
1284
745
  }
1285
746
  const helpers = filteredFunctions.map((func) => {
1286
- const methodName = toCamelCase7(func.name);
747
+ const methodName = toCamelCase3(func.name);
1287
748
  const argsSignature = generateArgsSignature(func.args);
1288
749
  const clarityArgs = generateClarityArgs(func.args);
1289
750
  return `async ${methodName}(${argsSignature}senderKey?: string, options?: {
@@ -1417,36 +878,42 @@ ${indentedHelpersCode}
1417
878
  init_format();
1418
879
 
1419
880
  // src/utils/case-conversion.ts
1420
- import { toCamelCase as toCamelCase8 } from "@secondlayer/stacks/clarity";
881
+ import { toCamelCase as toCamelCase4 } from "@secondlayer/stacks/clarity";
1421
882
  function capitalize(str) {
1422
883
  return str.charAt(0).toUpperCase() + str.slice(1);
1423
884
  }
1424
885
  function toPascalCase(str) {
1425
- return capitalize(toCamelCase8(str));
886
+ return capitalize(toCamelCase4(str));
1426
887
  }
1427
888
 
889
+ // src/utils/type-mapping.ts
890
+ import {
891
+ clarityTypeToTS,
892
+ generateArgsTypeSignature,
893
+ getTypeForArg
894
+ } from "@secondlayer/scaffold";
895
+
1428
896
  // src/plugins/react/generators/utils.ts
1429
- init_type_mapping();
1430
897
  function generateHookArgsSignature(args) {
1431
898
  if (args.length === 0)
1432
899
  return "";
1433
- const argsList = args.map((arg) => `${toCamelCase8(arg.name)}: ${clarityTypeToTS(arg.type)}`).join(", ");
900
+ const argsList = args.map((arg) => `${toCamelCase4(arg.name)}: ${clarityTypeToTS(arg.type)}`).join(", ");
1434
901
  return `${argsList}`;
1435
902
  }
1436
903
  function generateArgsType(args) {
1437
904
  if (args.length === 0)
1438
905
  return "void";
1439
- const argsList = args.map((arg) => `${toCamelCase8(arg.name)}: ${clarityTypeToTS(arg.type)}`).join("; ");
906
+ const argsList = args.map((arg) => `${toCamelCase4(arg.name)}: ${clarityTypeToTS(arg.type)}`).join("; ");
1440
907
  return `{ ${argsList} }`;
1441
908
  }
1442
909
  function generateArgNames(args) {
1443
910
  if (args.length === 0)
1444
911
  return "";
1445
- return args.map((arg) => toCamelCase8(arg.name)).join(", ");
912
+ return args.map((arg) => toCamelCase4(arg.name)).join(", ");
1446
913
  }
1447
914
  function generateEnabledCondition(args) {
1448
915
  return args.map((arg) => {
1449
- const camelName = toCamelCase8(arg.name);
916
+ const camelName = toCamelCase4(arg.name);
1450
917
  const type = clarityTypeToTS(arg.type);
1451
918
  if (type === "string")
1452
919
  return `!!${camelName}`;
@@ -1458,7 +925,7 @@ function generateEnabledCondition(args) {
1458
925
  function generateObjectArgs(args) {
1459
926
  if (args.length === 0)
1460
927
  return "";
1461
- return args.map((arg) => `${arg.name}: ${toCamelCase8(arg.name)}`).join(", ");
928
+ return args.map((arg) => `${arg.name}: ${toCamelCase4(arg.name)}`).join(", ");
1462
929
  }
1463
930
 
1464
931
  // src/plugins/react/generators/contract.ts
@@ -1491,21 +958,21 @@ function generateContractHookMethods(contract, excludeList) {
1491
958
  const readOnlyFunctions = functions.filter((f) => f.access === "read-only");
1492
959
  const publicFunctions = functions.filter((f) => f.access === "public");
1493
960
  const readHooks = readOnlyFunctions.map((func) => {
1494
- const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(func.name))}`;
961
+ const hookName = `use${capitalize(name)}${capitalize(toCamelCase4(func.name))}`;
1495
962
  if (excludeList.includes(hookName)) {
1496
963
  return null;
1497
964
  }
1498
965
  return generateReadHook(func, name);
1499
966
  }).filter(Boolean);
1500
967
  const writeHooks = publicFunctions.map((func) => {
1501
- const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(func.name))}`;
968
+ const hookName = `use${capitalize(name)}${capitalize(toCamelCase4(func.name))}`;
1502
969
  if (excludeList.includes(hookName)) {
1503
970
  return null;
1504
971
  }
1505
972
  return generateWriteHook(func, name);
1506
973
  }).filter(Boolean);
1507
974
  const mapHooks = maps.map((map) => {
1508
- const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(map.name))}`;
975
+ const hookName = `use${capitalize(name)}${capitalize(toCamelCase4(map.name))}`;
1509
976
  if (excludeList.includes(hookName)) {
1510
977
  return null;
1511
978
  }
@@ -1513,7 +980,7 @@ function generateContractHookMethods(contract, excludeList) {
1513
980
  }).filter(Boolean);
1514
981
  const dataVars = variables.filter((v) => v.access === "variable");
1515
982
  const varHooks = dataVars.map((variable) => {
1516
- const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(variable.name))}`;
983
+ const hookName = `use${capitalize(name)}${capitalize(toCamelCase4(variable.name))}`;
1517
984
  if (excludeList.includes(hookName)) {
1518
985
  return null;
1519
986
  }
@@ -1521,7 +988,7 @@ function generateContractHookMethods(contract, excludeList) {
1521
988
  }).filter(Boolean);
1522
989
  const constants = variables.filter((v) => v.access === "constant");
1523
990
  const constantHooks = constants.map((constant) => {
1524
- const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(constant.name))}`;
991
+ const hookName = `use${capitalize(name)}${capitalize(toCamelCase4(constant.name))}`;
1525
992
  if (excludeList.includes(hookName)) {
1526
993
  return null;
1527
994
  }
@@ -1542,7 +1009,7 @@ function generateContractHookMethods(contract, excludeList) {
1542
1009
  `);
1543
1010
  }
1544
1011
  function generateReadHook(func, contractName) {
1545
- const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase8(func.name))}`;
1012
+ const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase4(func.name))}`;
1546
1013
  const argsSignature = generateHookArgsSignature(func.args);
1547
1014
  const enabledParam = func.args.length > 0 ? ", options?: { enabled?: boolean }" : "options?: { enabled?: boolean }";
1548
1015
  const returnType = clarityTypeToTS(func.outputs);
@@ -1551,7 +1018,7 @@ function generateReadHook(func, contractName) {
1551
1018
 
1552
1019
  return useQuery<${returnType}>({
1553
1020
  queryKey: ['${func.name}', ${contractName}.address, ${generateArgNames(func.args)}],
1554
- queryFn: () => ${contractName}.read.${toCamelCase8(func.name)}(${generateArgNames(func.args) ? `{ ${generateObjectArgs(func.args)} }, ` : ""}{
1021
+ queryFn: () => ${contractName}.read.${toCamelCase4(func.name)}(${generateArgNames(func.args) ? `{ ${generateObjectArgs(func.args)} }, ` : ""}{
1555
1022
  network: config.network,
1556
1023
  senderAddress: config.senderAddress || 'SP000000000000000000002Q6VF78'
1557
1024
  }),
@@ -1561,7 +1028,7 @@ function generateReadHook(func, contractName) {
1561
1028
  }`;
1562
1029
  }
1563
1030
  function generateWriteHook(func, contractName) {
1564
- const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase8(func.name))}`;
1031
+ const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase4(func.name))}`;
1565
1032
  const argsType = generateArgsType(func.args);
1566
1033
  return `export function ${hookName}() {
1567
1034
  const config = useSecondLayerConfig()
@@ -1578,7 +1045,7 @@ function generateWriteHook(func, contractName) {
1578
1045
  };
1579
1046
  }) => {
1580
1047
  const { args, options = {} } = params
1581
- const contractCallData = ${contractName}.${toCamelCase8(func.name)}(args)
1048
+ const contractCallData = ${contractName}.${toCamelCase4(func.name)}(args)
1582
1049
  const { contractAddress, contractName: name, functionName, functionArgs } = contractCallData
1583
1050
  const network = config.network || 'mainnet'
1584
1051
  const contract = \`\${contractAddress}.\${name}\`
@@ -1603,7 +1070,7 @@ function generateWriteHook(func, contractName) {
1603
1070
  }
1604
1071
  })
1605
1072
 
1606
- const ${toCamelCase8(func.name)} = useCallback(async (
1073
+ const ${toCamelCase4(func.name)} = useCallback(async (
1607
1074
  args: ${argsType},
1608
1075
  options?: {
1609
1076
  postConditions?: PostCondition[];
@@ -1616,7 +1083,7 @@ function generateWriteHook(func, contractName) {
1616
1083
  }, [mutation])
1617
1084
 
1618
1085
  return {
1619
- ${toCamelCase8(func.name)},
1086
+ ${toCamelCase4(func.name)},
1620
1087
  // Expose mutation state
1621
1088
  isPending: mutation.isPending,
1622
1089
  isError: mutation.isError,
@@ -1628,7 +1095,7 @@ function generateWriteHook(func, contractName) {
1628
1095
  }`;
1629
1096
  }
1630
1097
  function generateMapHook(map, contractVarName, _address, _contractName) {
1631
- const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase8(map.name))}`;
1098
+ const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase4(map.name))}`;
1632
1099
  const keyType = clarityTypeToTS(map.key);
1633
1100
  const valueType = clarityTypeToTS(map.value);
1634
1101
  return `export function ${hookName}(key: ${keyType}, options?: { enabled?: boolean }) {
@@ -1637,14 +1104,14 @@ function generateMapHook(map, contractVarName, _address, _contractName) {
1637
1104
  return useQuery<${valueType} | null>({
1638
1105
  queryKey: ['${contractVarName}', '${map.name}', 'map', key, config.network],
1639
1106
  queryFn: async () => {
1640
- return ${contractVarName}.maps.${toCamelCase8(map.name)}.get(key, { network: config.network })
1107
+ return ${contractVarName}.maps.${toCamelCase4(map.name)}.get(key, { network: config.network })
1641
1108
  },
1642
1109
  enabled: options?.enabled ?? true
1643
1110
  })
1644
1111
  }`;
1645
1112
  }
1646
1113
  function generateVarHook(variable, contractVarName, _address, _contractName) {
1647
- const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase8(variable.name))}`;
1114
+ const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase4(variable.name))}`;
1648
1115
  const valueType = clarityTypeToTS(variable.type);
1649
1116
  return `export function ${hookName}(options?: { enabled?: boolean }) {
1650
1117
  const config = useSecondLayerConfig()
@@ -1652,14 +1119,14 @@ function generateVarHook(variable, contractVarName, _address, _contractName) {
1652
1119
  return useQuery<${valueType}>({
1653
1120
  queryKey: ['${contractVarName}', '${variable.name}', 'var', config.network],
1654
1121
  queryFn: async () => {
1655
- return ${contractVarName}.vars.${toCamelCase8(variable.name)}.get({ network: config.network })
1122
+ return ${contractVarName}.vars.${toCamelCase4(variable.name)}.get({ network: config.network })
1656
1123
  },
1657
1124
  enabled: options?.enabled ?? true
1658
1125
  })
1659
1126
  }`;
1660
1127
  }
1661
1128
  function generateConstantHook(constant, contractVarName, _address, _contractName) {
1662
- const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase8(constant.name))}`;
1129
+ const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase4(constant.name))}`;
1663
1130
  const valueType = clarityTypeToTS(constant.type);
1664
1131
  return `export function ${hookName}(options?: { enabled?: boolean }) {
1665
1132
  const config = useSecondLayerConfig()
@@ -1667,7 +1134,7 @@ function generateConstantHook(constant, contractVarName, _address, _contractName
1667
1134
  return useQuery<${valueType}>({
1668
1135
  queryKey: ['${contractVarName}', '${constant.name}', 'constant', config.network],
1669
1136
  queryFn: async () => {
1670
- return ${contractVarName}.constants.${toCamelCase8(constant.name)}.get({ network: config.network })
1137
+ return ${contractVarName}.constants.${toCamelCase4(constant.name)}.get({ network: config.network })
1671
1138
  },
1672
1139
  enabled: options?.enabled ?? true,
1673
1140
  staleTime: Infinity // Constants never change
@@ -2518,12 +1985,10 @@ var react = (options = {}) => {
2518
1985
  };
2519
1986
  // src/plugins/testing/generators.ts
2520
1987
  import {
2521
- isAbiTuple as isAbiTuple4
1988
+ isAbiTuple
2522
1989
  } from "@secondlayer/stacks/clarity";
2523
- init_generator_helpers();
2524
- init_type_mapping();
2525
1990
  function generatePublicFunction(func, contractId) {
2526
- const methodName = toCamelCase8(func.name);
1991
+ const methodName = toCamelCase4(func.name);
2527
1992
  const argsSignature = generateArgsSignature(func.args);
2528
1993
  const clarityArgs = generateClarityArgs(func.args);
2529
1994
  return `${methodName}: (${argsSignature}caller: string) => {
@@ -2537,7 +2002,7 @@ function generatePublicFunction(func, contractId) {
2537
2002
  }`;
2538
2003
  }
2539
2004
  function generateReadOnlyFunction(func, contractId) {
2540
- const methodName = toCamelCase8(func.name);
2005
+ const methodName = toCamelCase4(func.name);
2541
2006
  const argsSignature = generateArgsSignature(func.args);
2542
2007
  const clarityArgs = generateClarityArgs(func.args);
2543
2008
  const hasArgs = func.args.length > 0;
@@ -2552,7 +2017,7 @@ function generateReadOnlyFunction(func, contractId) {
2552
2017
  }`;
2553
2018
  }
2554
2019
  function generatePrivateFunction(func, contractId) {
2555
- const methodName = toCamelCase8(func.name);
2020
+ const methodName = toCamelCase4(func.name);
2556
2021
  const argsSignature = generateArgsSignature(func.args);
2557
2022
  const clarityArgs = generateClarityArgs(func.args);
2558
2023
  return `${methodName}: (${argsSignature}caller: string) => {
@@ -2566,20 +2031,20 @@ function generatePrivateFunction(func, contractId) {
2566
2031
  }`;
2567
2032
  }
2568
2033
  function generateDataVarHelper(variable, contractId) {
2569
- const methodName = toCamelCase8(variable.name);
2034
+ const methodName = toCamelCase4(variable.name);
2570
2035
  return `${methodName}: () => {
2571
2036
  return simnet.getDataVar('${contractId}', '${variable.name}');
2572
2037
  }`;
2573
2038
  }
2574
2039
  function getMapKeyType(keyType) {
2575
- if (isAbiTuple4(keyType)) {
2576
- const fields = keyType.tuple.map((field) => `${toCamelCase8(field.name)}: ${getTypeForArg({ type: field.type })}`).join("; ");
2040
+ if (isAbiTuple(keyType)) {
2041
+ const fields = keyType.tuple.map((field) => `${toCamelCase4(field.name)}: ${getTypeForArg({ type: field.type })}`).join("; ");
2577
2042
  return `{ ${fields} }`;
2578
2043
  }
2579
2044
  return getTypeForArg({ type: keyType });
2580
2045
  }
2581
2046
  function generateMapEntryHelper(map, contractId) {
2582
- const methodName = toCamelCase8(map.name);
2047
+ const methodName = toCamelCase4(map.name);
2583
2048
  const keyType = getMapKeyType(map.key);
2584
2049
  const keyConversion = generateMapKeyConversion(map.key);
2585
2050
  return `${methodName}: (key: ${keyType}) => {
@@ -2590,7 +2055,7 @@ function generateMapEntryHelper(map, contractId) {
2590
2055
  );
2591
2056
  }`;
2592
2057
  }
2593
- function generateVarsObject2(variables, contractId) {
2058
+ function generateVarsObject(variables, contractId) {
2594
2059
  const dataVars = variables.filter((v) => v.access === "variable");
2595
2060
  if (dataVars.length === 0) {
2596
2061
  return "";
@@ -2602,7 +2067,7 @@ function generateVarsObject2(variables, contractId) {
2602
2067
  `)}
2603
2068
  }`;
2604
2069
  }
2605
- function generateMapsObject2(maps, contractId) {
2070
+ function generateMapsObject(maps, contractId) {
2606
2071
  if (maps.length === 0) {
2607
2072
  return "";
2608
2073
  }
@@ -2625,8 +2090,8 @@ function generateContractHelper(contract, options) {
2625
2090
  const publicHelpers = publicFns.map((f) => generatePublicFunction(f, address));
2626
2091
  const readOnlyHelpers = readOnlyFns.map((f) => generateReadOnlyFunction(f, address));
2627
2092
  const privateHelpers = privateFns.map((f) => generatePrivateFunction(f, address));
2628
- const varsObject = generateVarsObject2(variables, address);
2629
- const mapsObject = generateMapsObject2(maps, address);
2093
+ const varsObject = generateVarsObject(variables, address);
2094
+ const mapsObject = generateMapsObject(maps, address);
2630
2095
  const allHelpers = [...publicHelpers, ...readOnlyHelpers, ...privateHelpers];
2631
2096
  if (varsObject) {
2632
2097
  allHelpers.push(varsObject);
@@ -2649,7 +2114,7 @@ function generateContractHelper(contract, options) {
2649
2114
  }
2650
2115
  function generateGetContracts(contracts) {
2651
2116
  const contractEntries = contracts.map((contract) => {
2652
- const camelName = toCamelCase8(contract.name);
2117
+ const camelName = toCamelCase4(contract.name);
2653
2118
  const pascalName = toPascalCase(contract.name);
2654
2119
  return `${camelName}: get${pascalName}(simnet)`;
2655
2120
  }).join(`,
@@ -2777,5 +2242,5 @@ export {
2777
2242
  PluginManager
2778
2243
  };
2779
2244
 
2780
- //# debugId=E3DECC5373F2A20964756E2164756E21
2245
+ //# debugId=29216900E6AC4AF864756E2164756E21
2781
2246
  //# sourceMappingURL=index.js.map