@secondlayer/cli 8.14.3 → 9.0.0
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/README.md +12 -8
- package/dist/cli.js +103 -7
- package/dist/cli.js.map +3 -3
- package/dist/plugins/index.d.ts +6 -19
- package/dist/plugins/index.js +72 -237
- package/dist/plugins/index.js.map +6 -8
- package/package.json +5 -5
package/dist/plugins/index.d.ts
CHANGED
|
@@ -287,6 +287,11 @@ interface ClarinetPluginOptions {
|
|
|
287
287
|
include?: string[];
|
|
288
288
|
/** Exclude specific contracts */
|
|
289
289
|
exclude?: string[];
|
|
290
|
+
/**
|
|
291
|
+
* Also generate interfaces for dependency contracts declared under
|
|
292
|
+
* `[project.requirements]` in Clarinet.toml (default: true).
|
|
293
|
+
*/
|
|
294
|
+
includeRequirements?: boolean;
|
|
290
295
|
/** Enable debug output */
|
|
291
296
|
debug?: boolean;
|
|
292
297
|
}
|
|
@@ -298,24 +303,6 @@ declare const clarinet: PluginFactory<ClarinetPluginOptions>;
|
|
|
298
303
|
* Utility function to check if a Clarinet project exists
|
|
299
304
|
*/
|
|
300
305
|
declare function hasClarinetProject(path?: string): Promise<boolean>;
|
|
301
|
-
interface ActionsPluginOptions {
|
|
302
|
-
/** Include only specific contracts */
|
|
303
|
-
include?: string[];
|
|
304
|
-
/** Exclude specific contracts */
|
|
305
|
-
exclude?: string[];
|
|
306
|
-
/** Include only specific functions */
|
|
307
|
-
includeFunctions?: string[];
|
|
308
|
-
/** Exclude specific functions */
|
|
309
|
-
excludeFunctions?: string[];
|
|
310
|
-
/** Enable debug output */
|
|
311
|
-
debug?: boolean;
|
|
312
|
-
/** Environment variable name for default sender key (default: "STX_SENDER_KEY") */
|
|
313
|
-
senderKeyEnv?: string;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Actions plugin factory
|
|
317
|
-
*/
|
|
318
|
-
declare const actions: PluginFactory<ActionsPluginOptions>;
|
|
319
306
|
/**
|
|
320
307
|
* React plugin configuration options
|
|
321
308
|
*/
|
|
@@ -361,4 +348,4 @@ declare function filterByOptions<T extends {
|
|
|
361
348
|
* Utility function to create a simple plugin
|
|
362
349
|
*/
|
|
363
350
|
declare function createPlugin(name: string, version: string, implementation: Partial<SecondLayerPlugin>): SecondLayerPlugin;
|
|
364
|
-
export { testing, react, hasClarinetProject, filterByOptions, createPlugin, clarinet,
|
|
351
|
+
export { testing, react, hasClarinetProject, filterByOptions, createPlugin, clarinet, TestingPluginOptions, SecondLayerPlugin, ReactPluginOptions, PluginUtils, PluginOptions, PluginManager, PluginFactory, PluginContext, Logger, GenerateContext, ClarinetPluginOptions, BasePluginOptions };
|
package/dist/plugins/index.js
CHANGED
|
@@ -576,22 +576,38 @@ function matchesContractFilters(name, options) {
|
|
|
576
576
|
function sanitizeContractName(name) {
|
|
577
577
|
return toCamelCase2(name);
|
|
578
578
|
}
|
|
579
|
-
async function
|
|
580
|
-
const { address, contractName } = parseContractId(contractId);
|
|
579
|
+
async function readManifestInfo(manifestPath) {
|
|
581
580
|
try {
|
|
582
581
|
const { promises: fs2 } = await import("node:fs");
|
|
583
582
|
const tomlContent = await fs2.readFile(manifestPath, "utf-8");
|
|
583
|
+
const projectContracts = new Set;
|
|
584
584
|
const contractSectionRegex = /^\[contracts\.([^\]]+)\]/gm;
|
|
585
|
-
const userContracts = new Set;
|
|
586
585
|
let match = contractSectionRegex.exec(tomlContent);
|
|
587
586
|
while (match !== null) {
|
|
588
|
-
|
|
587
|
+
projectContracts.add(match[1]);
|
|
589
588
|
match = contractSectionRegex.exec(tomlContent);
|
|
590
589
|
}
|
|
591
|
-
|
|
592
|
-
|
|
590
|
+
const requirementIds = new Set;
|
|
591
|
+
const requirementRegex = /contract_id\s*=\s*["']([^"']+)["']/g;
|
|
592
|
+
match = requirementRegex.exec(tomlContent);
|
|
593
|
+
while (match !== null) {
|
|
594
|
+
requirementIds.add(match[1]);
|
|
595
|
+
match = requirementRegex.exec(tomlContent);
|
|
593
596
|
}
|
|
594
|
-
|
|
597
|
+
return { projectContracts, requirementIds };
|
|
598
|
+
} catch {
|
|
599
|
+
return null;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function classifyContract(contractId, manifest) {
|
|
603
|
+
const { address, contractName } = parseContractId(contractId);
|
|
604
|
+
if (manifest) {
|
|
605
|
+
if (manifest.projectContracts.has(contractName))
|
|
606
|
+
return "project";
|
|
607
|
+
if (manifest.requirementIds.has(contractId))
|
|
608
|
+
return "requirement";
|
|
609
|
+
return "system";
|
|
610
|
+
}
|
|
595
611
|
const systemContractPatterns = [
|
|
596
612
|
/^pox-\d+$/,
|
|
597
613
|
/^bns$/,
|
|
@@ -599,16 +615,16 @@ async function isUserDefinedContract(contractId, manifestPath) {
|
|
|
599
615
|
/^lockup$/
|
|
600
616
|
];
|
|
601
617
|
if (systemContractPatterns.some((pattern) => pattern.test(contractName))) {
|
|
602
|
-
return
|
|
618
|
+
return "system";
|
|
603
619
|
}
|
|
604
620
|
const systemAddresses = [
|
|
605
621
|
DEFAULT_SENDER_ADDRESS,
|
|
606
622
|
"ST000000000000000000002AMW42H"
|
|
607
623
|
];
|
|
608
624
|
if (systemAddresses.includes(address)) {
|
|
609
|
-
return
|
|
625
|
+
return "system";
|
|
610
626
|
}
|
|
611
|
-
return
|
|
627
|
+
return "project";
|
|
612
628
|
}
|
|
613
629
|
var clarinet = (options = {}) => {
|
|
614
630
|
const manifestPath = options.path || "./Clarinet.toml";
|
|
@@ -621,11 +637,14 @@ var clarinet = (options = {}) => {
|
|
|
621
637
|
simnet = await initSimnet(manifestPath);
|
|
622
638
|
const contractInterfaces = simnet.getContractsInterfaces();
|
|
623
639
|
const contracts = [];
|
|
640
|
+
const manifest = await readManifestInfo(manifestPath);
|
|
641
|
+
const includeRequirements = options.includeRequirements ?? true;
|
|
624
642
|
for (const [contractId, abi] of contractInterfaces) {
|
|
625
643
|
const { contractName } = parseContractId(contractId);
|
|
626
|
-
|
|
644
|
+
const kind = classifyContract(contractId, manifest);
|
|
645
|
+
if (kind === "system" || kind === "requirement" && !includeRequirements) {
|
|
627
646
|
if (options.debug) {
|
|
628
|
-
console.log(`\uD83D\uDEAB Skipping
|
|
647
|
+
console.log(`\uD83D\uDEAB Skipping ${kind} contract: ${contractId}`);
|
|
629
648
|
}
|
|
630
649
|
continue;
|
|
631
650
|
}
|
|
@@ -683,208 +702,16 @@ async function hasClarinetProject(path2 = "./Clarinet.toml") {
|
|
|
683
702
|
return false;
|
|
684
703
|
}
|
|
685
704
|
}
|
|
686
|
-
// src/plugins/actions/generators.ts
|
|
687
|
-
import { toCamelCase as toCamelCase3 } from "@secondlayer/stacks/clarity";
|
|
688
|
-
|
|
689
|
-
// src/utils/generator-helpers.ts
|
|
690
|
-
import {
|
|
691
|
-
generateArgsSignature,
|
|
692
|
-
generateClarityArgs,
|
|
693
|
-
generateMapKeyConversion
|
|
694
|
-
} from "@secondlayer/scaffold";
|
|
695
|
-
|
|
696
|
-
// src/plugins/actions/generators.ts
|
|
697
|
-
function applyFunctionFilters(functions, options) {
|
|
698
|
-
return functions.filter((func) => {
|
|
699
|
-
if (options.includeFunctions && !options.includeFunctions.includes(func.name)) {
|
|
700
|
-
return false;
|
|
701
|
-
}
|
|
702
|
-
if (options.excludeFunctions?.includes(func.name)) {
|
|
703
|
-
return false;
|
|
704
|
-
}
|
|
705
|
-
return true;
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
function generateReadHelpers(contract, options) {
|
|
709
|
-
const { abi } = contract;
|
|
710
|
-
const functions = abi.functions || [];
|
|
711
|
-
const readOnlyFunctions = functions.filter((f) => f.access === "read-only");
|
|
712
|
-
if (readOnlyFunctions.length === 0) {
|
|
713
|
-
return "";
|
|
714
|
-
}
|
|
715
|
-
const filteredFunctions = applyFunctionFilters(readOnlyFunctions, options);
|
|
716
|
-
if (filteredFunctions.length === 0) {
|
|
717
|
-
return "";
|
|
718
|
-
}
|
|
719
|
-
const helpers = filteredFunctions.map((func) => {
|
|
720
|
-
const methodName = toCamelCase3(func.name);
|
|
721
|
-
const argsSignature = generateArgsSignature(func.args);
|
|
722
|
-
const clarityArgs = generateClarityArgs(func.args);
|
|
723
|
-
return `async ${methodName}(${argsSignature}options?: {
|
|
724
|
-
network?: 'mainnet' | 'testnet' | 'devnet';
|
|
725
|
-
senderAddress?: string;
|
|
726
|
-
}) {
|
|
727
|
-
return await fetchCallReadOnlyFunction({
|
|
728
|
-
contractAddress: '${contract.address}',
|
|
729
|
-
contractName: '${contract.contractName}',
|
|
730
|
-
functionName: '${func.name}',
|
|
731
|
-
functionArgs: [${clarityArgs}],
|
|
732
|
-
network: options?.network ?? inferNetworkFromAddress('${contract.address}') ?? 'mainnet',
|
|
733
|
-
senderAddress: options?.senderAddress || '${DEFAULT_SENDER_ADDRESS}'
|
|
734
|
-
});
|
|
735
|
-
}`;
|
|
736
|
-
});
|
|
737
|
-
return `read: {
|
|
738
|
-
${helpers.join(`,
|
|
739
|
-
|
|
740
|
-
`)}
|
|
741
|
-
}`;
|
|
742
|
-
}
|
|
743
|
-
function generateWriteHelpers(contract, options) {
|
|
744
|
-
const { abi } = contract;
|
|
745
|
-
const functions = abi.functions || [];
|
|
746
|
-
const envVarName = options.senderKeyEnv ?? "STX_SENDER_KEY";
|
|
747
|
-
const publicFunctions = functions.filter((f) => f.access === "public");
|
|
748
|
-
if (publicFunctions.length === 0) {
|
|
749
|
-
return "";
|
|
750
|
-
}
|
|
751
|
-
const filteredFunctions = applyFunctionFilters(publicFunctions, options);
|
|
752
|
-
if (filteredFunctions.length === 0) {
|
|
753
|
-
return "";
|
|
754
|
-
}
|
|
755
|
-
const helpers = filteredFunctions.map((func) => {
|
|
756
|
-
const methodName = toCamelCase3(func.name);
|
|
757
|
-
const argsSignature = generateArgsSignature(func.args);
|
|
758
|
-
const clarityArgs = generateClarityArgs(func.args);
|
|
759
|
-
return `async ${methodName}(${argsSignature}senderKey?: string, options?: {
|
|
760
|
-
network?: 'mainnet' | 'testnet' | 'devnet';
|
|
761
|
-
fee?: string | number | undefined;
|
|
762
|
-
nonce?: bigint;
|
|
763
|
-
anchorMode?: 1 | 2 | 3; // AnchorMode: OnChainOnly = 1, OffChainOnly = 2, Any = 3
|
|
764
|
-
postConditions?: PostCondition[];
|
|
765
|
-
validateWithAbi?: boolean;
|
|
766
|
-
}) {
|
|
767
|
-
const resolvedSenderKey = senderKey ?? process.env.${envVarName};
|
|
768
|
-
if (!resolvedSenderKey) {
|
|
769
|
-
throw new Error('senderKey required: pass as argument or set ${envVarName} env var');
|
|
770
|
-
}
|
|
771
|
-
const { network = 'mainnet', ...txOptions } = options ?? {};
|
|
772
|
-
|
|
773
|
-
return await makeContractCall({
|
|
774
|
-
contractAddress: '${contract.address}',
|
|
775
|
-
contractName: '${contract.contractName}',
|
|
776
|
-
functionName: '${func.name}',
|
|
777
|
-
functionArgs: [${clarityArgs}],
|
|
778
|
-
senderKey: resolvedSenderKey,
|
|
779
|
-
network,
|
|
780
|
-
validateWithAbi: true,
|
|
781
|
-
...txOptions
|
|
782
|
-
});
|
|
783
|
-
}`;
|
|
784
|
-
});
|
|
785
|
-
return `write: {
|
|
786
|
-
${helpers.join(`,
|
|
787
|
-
|
|
788
|
-
`)}
|
|
789
|
-
}`;
|
|
790
|
-
}
|
|
791
|
-
async function generateActionHelpers(contract, options) {
|
|
792
|
-
const readHelpers = generateReadHelpers(contract, options);
|
|
793
|
-
const writeHelpers = generateWriteHelpers(contract, options);
|
|
794
|
-
if (!readHelpers && !writeHelpers) {
|
|
795
|
-
return "";
|
|
796
|
-
}
|
|
797
|
-
const helpers = [readHelpers, writeHelpers].filter(Boolean);
|
|
798
|
-
return helpers.join(`,
|
|
799
|
-
|
|
800
|
-
`);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// src/plugins/actions/index.ts
|
|
804
|
-
var actions = (options = {}) => {
|
|
805
|
-
return {
|
|
806
|
-
name: "@secondlayer/cli/plugin-actions",
|
|
807
|
-
version: "1.0.0",
|
|
808
|
-
async generate(context) {
|
|
809
|
-
const { contracts } = context;
|
|
810
|
-
const filteredContracts = contracts.filter((contract) => matchesContractFilters(contract.name, options));
|
|
811
|
-
if (filteredContracts.length === 0) {
|
|
812
|
-
if (options.debug) {
|
|
813
|
-
context.logger.debug("Actions plugin: No contracts to process");
|
|
814
|
-
}
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
if (options.debug) {
|
|
818
|
-
context.logger.debug(`Actions plugin: Generating read/write helpers for ${filteredContracts.length} contracts`);
|
|
819
|
-
}
|
|
820
|
-
const contractHelpers = new Map;
|
|
821
|
-
for (const contract of filteredContracts) {
|
|
822
|
-
const actionsCode = await generateActionHelpers(contract, options);
|
|
823
|
-
if (actionsCode) {
|
|
824
|
-
contractHelpers.set(contract.name, actionsCode);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
if (contractHelpers.size > 0) {
|
|
828
|
-
const existingOutput = context.outputs.get("contracts");
|
|
829
|
-
if (existingOutput) {
|
|
830
|
-
let modifiedContent = addRequiredImports(existingOutput.content);
|
|
831
|
-
for (const [contractName, helpersCode] of contractHelpers) {
|
|
832
|
-
modifiedContent = injectHelpersIntoContract(modifiedContent, contractName, helpersCode);
|
|
833
|
-
}
|
|
834
|
-
context.outputs.set("contracts", {
|
|
835
|
-
...existingOutput,
|
|
836
|
-
content: modifiedContent
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
};
|
|
843
|
-
function addRequiredImports(content) {
|
|
844
|
-
const stacksImportRegex = /import\s+\{([^}]+)\}\s+from\s+['"]@secondlayer\/stacks['"];/;
|
|
845
|
-
const match = content.match(stacksImportRegex);
|
|
846
|
-
if (match) {
|
|
847
|
-
let updatedContent = content;
|
|
848
|
-
if (!updatedContent.includes("fetchCallReadOnlyFunction")) {
|
|
849
|
-
updatedContent = updatedContent.replace(stacksImportRegex, `${match[0]}
|
|
850
|
-
import { fetchCallReadOnlyFunction, makeContractCall } from '@secondlayer/stacks/clarity';`);
|
|
851
|
-
}
|
|
852
|
-
if (!updatedContent.includes("type PostCondition")) {
|
|
853
|
-
updatedContent = updatedContent.replace(stacksImportRegex, `${match[0]}
|
|
854
|
-
import type { PostCondition } from '@secondlayer/stacks';`);
|
|
855
|
-
}
|
|
856
|
-
return updatedContent;
|
|
857
|
-
}
|
|
858
|
-
return content;
|
|
859
|
-
}
|
|
860
|
-
function injectHelpersIntoContract(content, contractName, helpersCode) {
|
|
861
|
-
const contractPattern = new RegExp(`(export const ${contractName} = \\{[\\s\\S]*?)\\n\\} as const;`, "g");
|
|
862
|
-
return content.replace(contractPattern, (_, contractBody) => {
|
|
863
|
-
const cleanBody = contractBody.replace(/,\s*$/, "");
|
|
864
|
-
const indentedHelpersCode = helpersCode.split(`
|
|
865
|
-
`).map((line) => {
|
|
866
|
-
if (line.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*:/)) {
|
|
867
|
-
return ` ${line}`;
|
|
868
|
-
}
|
|
869
|
-
return line;
|
|
870
|
-
}).join(`
|
|
871
|
-
`);
|
|
872
|
-
return `${cleanBody},
|
|
873
|
-
|
|
874
|
-
${indentedHelpersCode}
|
|
875
|
-
} as const;`;
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
705
|
// src/plugins/react/generators/contract.ts
|
|
879
706
|
init_format();
|
|
880
707
|
|
|
881
708
|
// src/utils/case-conversion.ts
|
|
882
|
-
import { toCamelCase as
|
|
709
|
+
import { toCamelCase as toCamelCase3 } from "@secondlayer/stacks/clarity";
|
|
883
710
|
function capitalize(str) {
|
|
884
711
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
885
712
|
}
|
|
886
713
|
function toPascalCase(str) {
|
|
887
|
-
return capitalize(
|
|
714
|
+
return capitalize(toCamelCase3(str));
|
|
888
715
|
}
|
|
889
716
|
|
|
890
717
|
// src/utils/type-mapping.ts
|
|
@@ -898,23 +725,23 @@ import {
|
|
|
898
725
|
function generateHookArgsSignature(args) {
|
|
899
726
|
if (args.length === 0)
|
|
900
727
|
return "";
|
|
901
|
-
const argsList = args.map((arg) => `${
|
|
728
|
+
const argsList = args.map((arg) => `${toCamelCase3(arg.name)}: ${clarityTypeToTS(arg.type)}`).join(", ");
|
|
902
729
|
return `${argsList}`;
|
|
903
730
|
}
|
|
904
731
|
function generateArgsType(args) {
|
|
905
732
|
if (args.length === 0)
|
|
906
733
|
return "void";
|
|
907
|
-
const argsList = args.map((arg) => `${
|
|
734
|
+
const argsList = args.map((arg) => `${toCamelCase3(arg.name)}: ${clarityTypeToTS(arg.type)}`).join("; ");
|
|
908
735
|
return `{ ${argsList} }`;
|
|
909
736
|
}
|
|
910
737
|
function generateArgNames(args) {
|
|
911
738
|
if (args.length === 0)
|
|
912
739
|
return "";
|
|
913
|
-
return args.map((arg) =>
|
|
740
|
+
return args.map((arg) => toCamelCase3(arg.name)).join(", ");
|
|
914
741
|
}
|
|
915
742
|
function generateEnabledCondition(args) {
|
|
916
743
|
return args.map((arg) => {
|
|
917
|
-
const camelName =
|
|
744
|
+
const camelName = toCamelCase3(arg.name);
|
|
918
745
|
const type = clarityTypeToTS(arg.type);
|
|
919
746
|
if (type === "string")
|
|
920
747
|
return `!!${camelName}`;
|
|
@@ -926,7 +753,7 @@ function generateEnabledCondition(args) {
|
|
|
926
753
|
function generateObjectArgs(args) {
|
|
927
754
|
if (args.length === 0)
|
|
928
755
|
return "";
|
|
929
|
-
return args.map((arg) => `${arg.name}: ${
|
|
756
|
+
return args.map((arg) => `${arg.name}: ${toCamelCase3(arg.name)}`).join(", ");
|
|
930
757
|
}
|
|
931
758
|
|
|
932
759
|
// src/plugins/react/generators/contract.ts
|
|
@@ -959,21 +786,21 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
959
786
|
const readOnlyFunctions = functions.filter((f) => f.access === "read-only");
|
|
960
787
|
const publicFunctions = functions.filter((f) => f.access === "public");
|
|
961
788
|
const readHooks = readOnlyFunctions.map((func) => {
|
|
962
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
789
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase3(func.name))}`;
|
|
963
790
|
if (excludeList.includes(hookName)) {
|
|
964
791
|
return null;
|
|
965
792
|
}
|
|
966
793
|
return generateReadHook(func, name);
|
|
967
794
|
}).filter(Boolean);
|
|
968
795
|
const writeHooks = publicFunctions.map((func) => {
|
|
969
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
796
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase3(func.name))}`;
|
|
970
797
|
if (excludeList.includes(hookName)) {
|
|
971
798
|
return null;
|
|
972
799
|
}
|
|
973
800
|
return generateWriteHook(func, name);
|
|
974
801
|
}).filter(Boolean);
|
|
975
802
|
const mapHooks = maps.map((map) => {
|
|
976
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
803
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase3(map.name))}`;
|
|
977
804
|
if (excludeList.includes(hookName)) {
|
|
978
805
|
return null;
|
|
979
806
|
}
|
|
@@ -981,7 +808,7 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
981
808
|
}).filter(Boolean);
|
|
982
809
|
const dataVars = variables.filter((v) => v.access === "variable");
|
|
983
810
|
const varHooks = dataVars.map((variable) => {
|
|
984
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
811
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase3(variable.name))}`;
|
|
985
812
|
if (excludeList.includes(hookName)) {
|
|
986
813
|
return null;
|
|
987
814
|
}
|
|
@@ -989,7 +816,7 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
989
816
|
}).filter(Boolean);
|
|
990
817
|
const constants = variables.filter((v) => v.access === "constant");
|
|
991
818
|
const constantHooks = constants.map((constant) => {
|
|
992
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
819
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase3(constant.name))}`;
|
|
993
820
|
if (excludeList.includes(hookName)) {
|
|
994
821
|
return null;
|
|
995
822
|
}
|
|
@@ -1010,7 +837,7 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
1010
837
|
`);
|
|
1011
838
|
}
|
|
1012
839
|
function generateReadHook(func, contractName) {
|
|
1013
|
-
const hookName = `use${capitalize(contractName)}${capitalize(
|
|
840
|
+
const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase3(func.name))}`;
|
|
1014
841
|
const argsSignature = generateHookArgsSignature(func.args);
|
|
1015
842
|
const enabledParam = func.args.length > 0 ? ", options?: { enabled?: boolean }" : "options?: { enabled?: boolean }";
|
|
1016
843
|
const returnType = clarityTypeToTS(func.outputs);
|
|
@@ -1019,7 +846,7 @@ function generateReadHook(func, contractName) {
|
|
|
1019
846
|
|
|
1020
847
|
return useQuery<${returnType}>({
|
|
1021
848
|
queryKey: ['${func.name}', ${contractName}.address, ${generateArgNames(func.args)}],
|
|
1022
|
-
queryFn: () => ${contractName}.read.${
|
|
849
|
+
queryFn: () => ${contractName}.read.${toCamelCase3(func.name)}(${generateArgNames(func.args) ? `{ ${generateObjectArgs(func.args)} }, ` : ""}{
|
|
1023
850
|
network: config.network,
|
|
1024
851
|
senderAddress: config.senderAddress || '${DEFAULT_SENDER_ADDRESS}'
|
|
1025
852
|
}),
|
|
@@ -1029,7 +856,7 @@ function generateReadHook(func, contractName) {
|
|
|
1029
856
|
}`;
|
|
1030
857
|
}
|
|
1031
858
|
function generateWriteHook(func, contractName) {
|
|
1032
|
-
const hookName = `use${capitalize(contractName)}${capitalize(
|
|
859
|
+
const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase3(func.name))}`;
|
|
1033
860
|
const argsType = generateArgsType(func.args);
|
|
1034
861
|
return `export function ${hookName}() {
|
|
1035
862
|
const config = useSecondLayerConfig()
|
|
@@ -1046,7 +873,7 @@ function generateWriteHook(func, contractName) {
|
|
|
1046
873
|
};
|
|
1047
874
|
}) => {
|
|
1048
875
|
const { args, options = {} } = params
|
|
1049
|
-
const contractCallData = ${contractName}.${
|
|
876
|
+
const contractCallData = ${contractName}.${toCamelCase3(func.name)}(args)
|
|
1050
877
|
const { contractAddress, contractName: name, functionName, functionArgs } = contractCallData
|
|
1051
878
|
const network = config.network || 'mainnet'
|
|
1052
879
|
const contract = \`\${contractAddress}.\${name}\`
|
|
@@ -1071,7 +898,7 @@ function generateWriteHook(func, contractName) {
|
|
|
1071
898
|
}
|
|
1072
899
|
})
|
|
1073
900
|
|
|
1074
|
-
const ${
|
|
901
|
+
const ${toCamelCase3(func.name)} = useCallback(async (
|
|
1075
902
|
args: ${argsType},
|
|
1076
903
|
options?: {
|
|
1077
904
|
postConditions?: PostCondition[];
|
|
@@ -1084,7 +911,7 @@ function generateWriteHook(func, contractName) {
|
|
|
1084
911
|
}, [mutation])
|
|
1085
912
|
|
|
1086
913
|
return {
|
|
1087
|
-
${
|
|
914
|
+
${toCamelCase3(func.name)},
|
|
1088
915
|
// Expose mutation state
|
|
1089
916
|
isPending: mutation.isPending,
|
|
1090
917
|
isError: mutation.isError,
|
|
@@ -1096,7 +923,7 @@ function generateWriteHook(func, contractName) {
|
|
|
1096
923
|
}`;
|
|
1097
924
|
}
|
|
1098
925
|
function generateMapHook(map, contractVarName, _address, _contractName) {
|
|
1099
|
-
const hookName = `use${capitalize(contractVarName)}${capitalize(
|
|
926
|
+
const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase3(map.name))}`;
|
|
1100
927
|
const keyType = clarityTypeToTS(map.key);
|
|
1101
928
|
const valueType = clarityTypeToTS(map.value);
|
|
1102
929
|
return `export function ${hookName}(key: ${keyType}, options?: { enabled?: boolean }) {
|
|
@@ -1105,14 +932,14 @@ function generateMapHook(map, contractVarName, _address, _contractName) {
|
|
|
1105
932
|
return useQuery<${valueType} | null>({
|
|
1106
933
|
queryKey: ['${contractVarName}', '${map.name}', 'map', key, config.network],
|
|
1107
934
|
queryFn: async () => {
|
|
1108
|
-
return ${contractVarName}.maps.${
|
|
935
|
+
return ${contractVarName}.maps.${toCamelCase3(map.name)}.get(key, { network: config.network })
|
|
1109
936
|
},
|
|
1110
937
|
enabled: options?.enabled ?? true
|
|
1111
938
|
})
|
|
1112
939
|
}`;
|
|
1113
940
|
}
|
|
1114
941
|
function generateVarHook(variable, contractVarName, _address, _contractName) {
|
|
1115
|
-
const hookName = `use${capitalize(contractVarName)}${capitalize(
|
|
942
|
+
const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase3(variable.name))}`;
|
|
1116
943
|
const valueType = clarityTypeToTS(variable.type);
|
|
1117
944
|
return `export function ${hookName}(options?: { enabled?: boolean }) {
|
|
1118
945
|
const config = useSecondLayerConfig()
|
|
@@ -1120,14 +947,14 @@ function generateVarHook(variable, contractVarName, _address, _contractName) {
|
|
|
1120
947
|
return useQuery<${valueType}>({
|
|
1121
948
|
queryKey: ['${contractVarName}', '${variable.name}', 'var', config.network],
|
|
1122
949
|
queryFn: async () => {
|
|
1123
|
-
return ${contractVarName}.vars.${
|
|
950
|
+
return ${contractVarName}.vars.${toCamelCase3(variable.name)}.get({ network: config.network })
|
|
1124
951
|
},
|
|
1125
952
|
enabled: options?.enabled ?? true
|
|
1126
953
|
})
|
|
1127
954
|
}`;
|
|
1128
955
|
}
|
|
1129
956
|
function generateConstantHook(constant, contractVarName, _address, _contractName) {
|
|
1130
|
-
const hookName = `use${capitalize(contractVarName)}${capitalize(
|
|
957
|
+
const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase3(constant.name))}`;
|
|
1131
958
|
const valueType = clarityTypeToTS(constant.type);
|
|
1132
959
|
return `export function ${hookName}(options?: { enabled?: boolean }) {
|
|
1133
960
|
const config = useSecondLayerConfig()
|
|
@@ -1135,7 +962,7 @@ function generateConstantHook(constant, contractVarName, _address, _contractName
|
|
|
1135
962
|
return useQuery<${valueType}>({
|
|
1136
963
|
queryKey: ['${contractVarName}', '${constant.name}', 'constant', config.network],
|
|
1137
964
|
queryFn: async () => {
|
|
1138
|
-
return ${contractVarName}.constants.${
|
|
965
|
+
return ${contractVarName}.constants.${toCamelCase3(constant.name)}.get({ network: config.network })
|
|
1139
966
|
},
|
|
1140
967
|
enabled: options?.enabled ?? true,
|
|
1141
968
|
staleTime: Infinity // Constants never change
|
|
@@ -1988,8 +1815,17 @@ var react = (options = {}) => {
|
|
|
1988
1815
|
import {
|
|
1989
1816
|
isAbiTuple
|
|
1990
1817
|
} from "@secondlayer/stacks/clarity";
|
|
1818
|
+
|
|
1819
|
+
// src/utils/generator-helpers.ts
|
|
1820
|
+
import {
|
|
1821
|
+
generateArgsSignature,
|
|
1822
|
+
generateClarityArgs,
|
|
1823
|
+
generateMapKeyConversion
|
|
1824
|
+
} from "@secondlayer/scaffold";
|
|
1825
|
+
|
|
1826
|
+
// src/plugins/testing/generators.ts
|
|
1991
1827
|
function generatePublicFunction(func, contractId) {
|
|
1992
|
-
const methodName =
|
|
1828
|
+
const methodName = toCamelCase3(func.name);
|
|
1993
1829
|
const argsSignature = generateArgsSignature(func.args);
|
|
1994
1830
|
const clarityArgs = generateClarityArgs(func.args);
|
|
1995
1831
|
return `${methodName}: (${argsSignature}caller: string) => {
|
|
@@ -2003,7 +1839,7 @@ function generatePublicFunction(func, contractId) {
|
|
|
2003
1839
|
}`;
|
|
2004
1840
|
}
|
|
2005
1841
|
function generateReadOnlyFunction(func, contractId) {
|
|
2006
|
-
const methodName =
|
|
1842
|
+
const methodName = toCamelCase3(func.name);
|
|
2007
1843
|
const argsSignature = generateArgsSignature(func.args);
|
|
2008
1844
|
const clarityArgs = generateClarityArgs(func.args);
|
|
2009
1845
|
const hasArgs = func.args.length > 0;
|
|
@@ -2018,7 +1854,7 @@ function generateReadOnlyFunction(func, contractId) {
|
|
|
2018
1854
|
}`;
|
|
2019
1855
|
}
|
|
2020
1856
|
function generatePrivateFunction(func, contractId) {
|
|
2021
|
-
const methodName =
|
|
1857
|
+
const methodName = toCamelCase3(func.name);
|
|
2022
1858
|
const argsSignature = generateArgsSignature(func.args);
|
|
2023
1859
|
const clarityArgs = generateClarityArgs(func.args);
|
|
2024
1860
|
return `${methodName}: (${argsSignature}caller: string) => {
|
|
@@ -2032,20 +1868,20 @@ function generatePrivateFunction(func, contractId) {
|
|
|
2032
1868
|
}`;
|
|
2033
1869
|
}
|
|
2034
1870
|
function generateDataVarHelper(variable, contractId) {
|
|
2035
|
-
const methodName =
|
|
1871
|
+
const methodName = toCamelCase3(variable.name);
|
|
2036
1872
|
return `${methodName}: () => {
|
|
2037
1873
|
return simnet.getDataVar('${contractId}', '${variable.name}');
|
|
2038
1874
|
}`;
|
|
2039
1875
|
}
|
|
2040
1876
|
function getMapKeyType(keyType) {
|
|
2041
1877
|
if (isAbiTuple(keyType)) {
|
|
2042
|
-
const fields = keyType.tuple.map((field) => `${
|
|
1878
|
+
const fields = keyType.tuple.map((field) => `${toCamelCase3(field.name)}: ${getTypeForArg({ type: field.type })}`).join("; ");
|
|
2043
1879
|
return `{ ${fields} }`;
|
|
2044
1880
|
}
|
|
2045
1881
|
return getTypeForArg({ type: keyType });
|
|
2046
1882
|
}
|
|
2047
1883
|
function generateMapEntryHelper(map, contractId) {
|
|
2048
|
-
const methodName =
|
|
1884
|
+
const methodName = toCamelCase3(map.name);
|
|
2049
1885
|
const keyType = getMapKeyType(map.key);
|
|
2050
1886
|
const keyConversion = generateMapKeyConversion(map.key);
|
|
2051
1887
|
return `${methodName}: (key: ${keyType}) => {
|
|
@@ -2115,7 +1951,7 @@ function generateContractHelper(contract, options) {
|
|
|
2115
1951
|
}
|
|
2116
1952
|
function generateGetContracts(contracts) {
|
|
2117
1953
|
const contractEntries = contracts.map((contract) => {
|
|
2118
|
-
const camelName =
|
|
1954
|
+
const camelName = toCamelCase3(contract.name);
|
|
2119
1955
|
const pascalName = toPascalCase(contract.name);
|
|
2120
1956
|
return `${camelName}: get${pascalName}(simnet)`;
|
|
2121
1957
|
}).join(`,
|
|
@@ -2231,9 +2067,8 @@ export {
|
|
|
2231
2067
|
filterByOptions,
|
|
2232
2068
|
createPlugin,
|
|
2233
2069
|
clarinet,
|
|
2234
|
-
actions,
|
|
2235
2070
|
PluginManager
|
|
2236
2071
|
};
|
|
2237
2072
|
|
|
2238
|
-
//# debugId=
|
|
2073
|
+
//# debugId=E6E6E78DF371674C64756E2164756E21
|
|
2239
2074
|
//# sourceMappingURL=index.js.map
|