@secondlayer/cli 1.4.0 → 1.5.1
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 +226 -197
- package/dist/cli.js.map +22 -21
- package/dist/index.d.ts +6 -1
- package/dist/index.js +96 -104
- package/dist/index.js.map +13 -12
- package/dist/plugin-manager.d.ts +6 -1
- package/dist/plugin-manager.js +29 -52
- package/dist/plugin-manager.js.map +4 -4
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AbiContract as AbiContract2 } from "@secondlayer/stacks/clarity";
|
|
1
2
|
import { AbiContract } from "@secondlayer/stacks/clarity";
|
|
2
3
|
/** Supported Stacks network identifiers for contract resolution. */
|
|
3
4
|
type NetworkName = "mainnet" | "testnet" | "devnet";
|
|
@@ -96,7 +97,7 @@ interface ContractConfig {
|
|
|
96
97
|
name?: string;
|
|
97
98
|
address?: string | Partial<Record<NetworkName, string>>;
|
|
98
99
|
source?: string;
|
|
99
|
-
abi?:
|
|
100
|
+
abi?: AbiContract2;
|
|
100
101
|
metadata?: Record<string, any>;
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
@@ -259,6 +260,10 @@ declare class PluginManager {
|
|
|
259
260
|
*/
|
|
260
261
|
getExecutionResults(): Map<string, HookResult[]>;
|
|
261
262
|
/**
|
|
263
|
+
* Convert a contract config with an ABI into a ProcessedContract
|
|
264
|
+
*/
|
|
265
|
+
private contractToProcessed;
|
|
266
|
+
/**
|
|
262
267
|
* Augment existing output with additional content
|
|
263
268
|
*/
|
|
264
269
|
private augmentOutput;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
3
18
|
var __export = (target, all) => {
|
|
4
19
|
for (var name in all)
|
|
5
20
|
__defProp(target, name, {
|
|
@@ -67,6 +82,8 @@ var init_format = () => {};
|
|
|
67
82
|
import { promises as fs } from "fs";
|
|
68
83
|
import path from "path";
|
|
69
84
|
import { isValidAddress as _validateStacksAddress } from "@secondlayer/stacks";
|
|
85
|
+
import { getErrorMessage } from "@secondlayer/shared";
|
|
86
|
+
import { toCamelCase } from "@secondlayer/stacks/clarity";
|
|
70
87
|
|
|
71
88
|
// src/utils/contract-id.ts
|
|
72
89
|
function parseContractId(contractId) {
|
|
@@ -132,12 +149,11 @@ class PluginManager {
|
|
|
132
149
|
success: true
|
|
133
150
|
});
|
|
134
151
|
} catch (error) {
|
|
135
|
-
const err = error;
|
|
136
152
|
this.recordHookResult(plugin.name, "transformConfig", {
|
|
137
153
|
success: false,
|
|
138
|
-
error:
|
|
154
|
+
error: error instanceof Error ? error : new Error(getErrorMessage(error))
|
|
139
155
|
});
|
|
140
|
-
throw new Error(`Plugin "${plugin.name}" failed during config transformation: ${
|
|
156
|
+
throw new Error(`Plugin "${plugin.name}" failed during config transformation: ${getErrorMessage(error)}`);
|
|
141
157
|
}
|
|
142
158
|
}
|
|
143
159
|
}
|
|
@@ -151,31 +167,11 @@ class PluginManager {
|
|
|
151
167
|
const processedContracts = [];
|
|
152
168
|
for (let contract of contracts) {
|
|
153
169
|
if (isClarinetContract(contract) && contract.abi) {
|
|
154
|
-
|
|
155
|
-
const parsed = parseContractId(address);
|
|
156
|
-
const processed = {
|
|
157
|
-
name: contract.name || parsed.contractName,
|
|
158
|
-
address: parsed.address,
|
|
159
|
-
contractName: parsed.contractName,
|
|
160
|
-
abi: contract.abi,
|
|
161
|
-
source: "local",
|
|
162
|
-
metadata: { source: "clarinet" }
|
|
163
|
-
};
|
|
164
|
-
processedContracts.push(processed);
|
|
170
|
+
processedContracts.push(this.contractToProcessed(contract, "clarinet"));
|
|
165
171
|
continue;
|
|
166
172
|
}
|
|
167
173
|
if (isDirectFileContract(contract) && contract.abi) {
|
|
168
|
-
|
|
169
|
-
const parsed = parseContractId(address);
|
|
170
|
-
const processed = {
|
|
171
|
-
name: contract.name || parsed.contractName,
|
|
172
|
-
address: parsed.address,
|
|
173
|
-
contractName: parsed.contractName,
|
|
174
|
-
abi: contract.abi,
|
|
175
|
-
source: "local",
|
|
176
|
-
metadata: { source: "direct" }
|
|
177
|
-
};
|
|
178
|
-
processedContracts.push(processed);
|
|
174
|
+
processedContracts.push(this.contractToProcessed(contract, "direct"));
|
|
179
175
|
continue;
|
|
180
176
|
}
|
|
181
177
|
for (const plugin of this.plugins) {
|
|
@@ -187,27 +183,16 @@ class PluginManager {
|
|
|
187
183
|
success: true
|
|
188
184
|
});
|
|
189
185
|
} catch (error) {
|
|
190
|
-
const err = error;
|
|
191
186
|
this.recordHookResult(plugin.name, "transformContract", {
|
|
192
187
|
success: false,
|
|
193
|
-
error:
|
|
188
|
+
error: error instanceof Error ? error : new Error(getErrorMessage(error))
|
|
194
189
|
});
|
|
195
|
-
this.logger.warn(`Plugin "${plugin.name}" failed to transform contract: ${
|
|
190
|
+
this.logger.warn(`Plugin "${plugin.name}" failed to transform contract: ${getErrorMessage(error)}`);
|
|
196
191
|
}
|
|
197
192
|
}
|
|
198
193
|
}
|
|
199
194
|
if (contract.abi) {
|
|
200
|
-
|
|
201
|
-
const parsed = parseContractId(addressStr);
|
|
202
|
-
const processed = {
|
|
203
|
-
name: contract.name || parsed.contractName || "unknown",
|
|
204
|
-
address: parsed.address || "unknown",
|
|
205
|
-
contractName: parsed.contractName || contract.name || "unknown",
|
|
206
|
-
abi: contract.abi,
|
|
207
|
-
source: "api",
|
|
208
|
-
metadata: contract.metadata
|
|
209
|
-
};
|
|
210
|
-
processedContracts.push(processed);
|
|
195
|
+
processedContracts.push(this.contractToProcessed(contract, "api"));
|
|
211
196
|
}
|
|
212
197
|
}
|
|
213
198
|
return processedContracts;
|
|
@@ -223,12 +208,11 @@ class PluginManager {
|
|
|
223
208
|
success: true
|
|
224
209
|
});
|
|
225
210
|
} catch (error) {
|
|
226
|
-
const err = error;
|
|
227
211
|
this.recordHookResult(plugin.name, hookName, {
|
|
228
212
|
success: false,
|
|
229
|
-
error:
|
|
213
|
+
error: error instanceof Error ? error : new Error(getErrorMessage(error))
|
|
230
214
|
});
|
|
231
|
-
this.logger.error(`Plugin "${plugin.name}" failed during ${hookName}: ${
|
|
215
|
+
this.logger.error(`Plugin "${plugin.name}" failed during ${hookName}: ${getErrorMessage(error)}`);
|
|
232
216
|
}
|
|
233
217
|
}
|
|
234
218
|
}
|
|
@@ -268,12 +252,11 @@ class PluginManager {
|
|
|
268
252
|
success: true
|
|
269
253
|
});
|
|
270
254
|
} catch (error) {
|
|
271
|
-
const err = error;
|
|
272
255
|
this.recordHookResult(plugin.name, "transformOutput", {
|
|
273
256
|
success: false,
|
|
274
|
-
error:
|
|
257
|
+
error: error instanceof Error ? error : new Error(getErrorMessage(error))
|
|
275
258
|
});
|
|
276
|
-
this.logger.warn(`Plugin "${plugin.name}" failed to transform output: ${
|
|
259
|
+
this.logger.warn(`Plugin "${plugin.name}" failed to transform output: ${getErrorMessage(error)}`);
|
|
277
260
|
}
|
|
278
261
|
}
|
|
279
262
|
}
|
|
@@ -291,15 +274,26 @@ class PluginManager {
|
|
|
291
274
|
await this.utils.ensureDir(path.dirname(resolvedPath));
|
|
292
275
|
await this.utils.writeFile(resolvedPath, output.content);
|
|
293
276
|
} catch (error) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
throw err;
|
|
277
|
+
this.logger.error(`Failed to write ${output.path}: ${getErrorMessage(error)}`);
|
|
278
|
+
throw error;
|
|
297
279
|
}
|
|
298
280
|
}
|
|
299
281
|
}
|
|
300
282
|
getExecutionResults() {
|
|
301
283
|
return new Map(this.executionContext.results);
|
|
302
284
|
}
|
|
285
|
+
contractToProcessed(contract, source) {
|
|
286
|
+
const address = typeof contract.address === "string" ? contract.address : "";
|
|
287
|
+
const parsed = parseContractId(address);
|
|
288
|
+
return {
|
|
289
|
+
name: contract.name || parsed.contractName || "unknown",
|
|
290
|
+
address: parsed.address || "unknown",
|
|
291
|
+
contractName: parsed.contractName || contract.name || "unknown",
|
|
292
|
+
abi: contract.abi,
|
|
293
|
+
source: source === "api" ? "api" : "local",
|
|
294
|
+
metadata: contract.metadata ?? { source }
|
|
295
|
+
};
|
|
296
|
+
}
|
|
303
297
|
augmentOutput(outputs, outputKey, contractName, content) {
|
|
304
298
|
const existing = outputs.get(outputKey);
|
|
305
299
|
if (!existing) {
|
|
@@ -336,9 +330,7 @@ ${JSON.stringify(content, null, 2)}`;
|
|
|
336
330
|
}
|
|
337
331
|
createUtils() {
|
|
338
332
|
return {
|
|
339
|
-
toCamelCase
|
|
340
|
-
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
341
|
-
},
|
|
333
|
+
toCamelCase,
|
|
342
334
|
toKebabCase: (str) => {
|
|
343
335
|
return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
344
336
|
},
|
|
@@ -377,17 +369,17 @@ ${JSON.stringify(content, null, 2)}`;
|
|
|
377
369
|
}
|
|
378
370
|
// src/plugins/clarinet/index.ts
|
|
379
371
|
import { initSimnet } from "@hirosystems/clarinet-sdk";
|
|
380
|
-
import { toCamelCase as
|
|
372
|
+
import { toCamelCase as toCamelCase6 } from "@secondlayer/stacks/clarity";
|
|
381
373
|
|
|
382
374
|
// src/generators/contract.ts
|
|
383
375
|
init_format();
|
|
384
376
|
import {
|
|
385
|
-
toCamelCase as
|
|
377
|
+
toCamelCase as toCamelCase5
|
|
386
378
|
} from "@secondlayer/stacks/clarity";
|
|
387
379
|
|
|
388
380
|
// src/utils/type-mapping.ts
|
|
389
381
|
import {
|
|
390
|
-
toCamelCase,
|
|
382
|
+
toCamelCase as toCamelCase2,
|
|
391
383
|
isAbiList,
|
|
392
384
|
isAbiTuple,
|
|
393
385
|
isAbiOptional,
|
|
@@ -446,7 +438,7 @@ function clarityTypeToTS(type) {
|
|
|
446
438
|
return `${innerType}[]`;
|
|
447
439
|
}
|
|
448
440
|
if (isAbiTuple(type)) {
|
|
449
|
-
const fields = type.tuple.map((field) => `${
|
|
441
|
+
const fields = type.tuple.map((field) => `${toCamelCase2(field.name)}: ${clarityTypeToTS(field.type)}`).join("; ");
|
|
450
442
|
return `{ ${fields} }`;
|
|
451
443
|
}
|
|
452
444
|
if (isAbiResponse(type)) {
|
|
@@ -462,7 +454,7 @@ function getTypeForArg(arg) {
|
|
|
462
454
|
|
|
463
455
|
// src/utils/clarity-conversion.ts
|
|
464
456
|
import {
|
|
465
|
-
toCamelCase as
|
|
457
|
+
toCamelCase as toCamelCase3,
|
|
466
458
|
isAbiStringAscii as isAbiStringAscii2,
|
|
467
459
|
isAbiStringUtf8 as isAbiStringUtf82,
|
|
468
460
|
isAbiBuffer as isAbiBuffer2,
|
|
@@ -560,7 +552,7 @@ function generateClarityConversion(argName, argType) {
|
|
|
560
552
|
const requiredFields = type.tuple.map((f) => f.name);
|
|
561
553
|
const fieldNames = JSON.stringify(requiredFields);
|
|
562
554
|
const fields = type.tuple.map((field) => {
|
|
563
|
-
const camelFieldName =
|
|
555
|
+
const camelFieldName = toCamelCase3(field.name);
|
|
564
556
|
const fieldConversion = generateClarityConversion(`tupleValue.${camelFieldName}`, { type: field.type });
|
|
565
557
|
return `"${field.name}": ${fieldConversion}`;
|
|
566
558
|
}).join(", ");
|
|
@@ -600,12 +592,12 @@ function generateClarityConversion(argName, argType) {
|
|
|
600
592
|
}
|
|
601
593
|
|
|
602
594
|
// src/utils/generator-helpers.ts
|
|
603
|
-
import { toCamelCase as
|
|
595
|
+
import { toCamelCase as toCamelCase4, isAbiTuple as isAbiTuple3 } from "@secondlayer/stacks/clarity";
|
|
604
596
|
function generateArgsSignature(args) {
|
|
605
597
|
if (args.length === 0)
|
|
606
598
|
return "";
|
|
607
599
|
const argsTypes = args.map((arg) => {
|
|
608
|
-
const camelName =
|
|
600
|
+
const camelName = toCamelCase4(arg.name);
|
|
609
601
|
return `${camelName}: ${getTypeForArg(arg)}`;
|
|
610
602
|
}).join("; ");
|
|
611
603
|
return `args: { ${argsTypes} }, `;
|
|
@@ -614,14 +606,14 @@ function generateClarityArgs(args) {
|
|
|
614
606
|
if (args.length === 0)
|
|
615
607
|
return "";
|
|
616
608
|
return args.map((arg) => {
|
|
617
|
-
const argName = `args.${
|
|
609
|
+
const argName = `args.${toCamelCase4(arg.name)}`;
|
|
618
610
|
return generateClarityConversion(argName, arg);
|
|
619
611
|
}).join(", ");
|
|
620
612
|
}
|
|
621
613
|
function generateMapKeyConversion(keyType) {
|
|
622
614
|
if (isAbiTuple3(keyType)) {
|
|
623
615
|
const fields = keyType.tuple.map((field) => {
|
|
624
|
-
const camelFieldName =
|
|
616
|
+
const camelFieldName = toCamelCase4(field.name);
|
|
625
617
|
const fieldConversion = generateClarityConversion(`key.${camelFieldName}`, { type: field.type });
|
|
626
618
|
return `"${field.name}": ${fieldConversion}`;
|
|
627
619
|
}).join(", ");
|
|
@@ -721,7 +713,7 @@ function generateAbiConstant(name, abi) {
|
|
|
721
713
|
return `export const ${name}Abi = ${abiJson} as const`;
|
|
722
714
|
}
|
|
723
715
|
function generateMethod(func, address, contractName) {
|
|
724
|
-
const methodName =
|
|
716
|
+
const methodName = toCamelCase5(func.name);
|
|
725
717
|
if (func.args.length === 0) {
|
|
726
718
|
return `${methodName}() {
|
|
727
719
|
return {
|
|
@@ -734,7 +726,7 @@ function generateMethod(func, address, contractName) {
|
|
|
734
726
|
}
|
|
735
727
|
if (func.args.length === 1) {
|
|
736
728
|
const originalArgName = func.args[0].name;
|
|
737
|
-
const argName =
|
|
729
|
+
const argName = toCamelCase5(originalArgName);
|
|
738
730
|
const argType = getTypeForArg(func.args[0]);
|
|
739
731
|
const clarityConversion = generateClarityConversion(argName, func.args[0]);
|
|
740
732
|
return `${methodName}(...args: [{ ${argName}: ${argType} }] | [${argType}]) {
|
|
@@ -750,17 +742,17 @@ function generateMethod(func, address, contractName) {
|
|
|
750
742
|
}
|
|
751
743
|
}`;
|
|
752
744
|
}
|
|
753
|
-
const argsList = func.args.map((arg) =>
|
|
745
|
+
const argsList = func.args.map((arg) => toCamelCase5(arg.name)).join(", ");
|
|
754
746
|
const argsTypes = func.args.map((arg) => {
|
|
755
|
-
const camelName =
|
|
747
|
+
const camelName = toCamelCase5(arg.name);
|
|
756
748
|
return `${camelName}: ${getTypeForArg(arg)}`;
|
|
757
749
|
}).join("; ");
|
|
758
750
|
const argsArray = func.args.map((arg) => {
|
|
759
|
-
const argName =
|
|
751
|
+
const argName = toCamelCase5(arg.name);
|
|
760
752
|
return generateClarityConversion(argName, arg);
|
|
761
753
|
}).join(", ");
|
|
762
754
|
const objectAccess = func.args.map((arg) => {
|
|
763
|
-
const camelName =
|
|
755
|
+
const camelName = toCamelCase5(arg.name);
|
|
764
756
|
return `args[0].${camelName}`;
|
|
765
757
|
}).join(", ");
|
|
766
758
|
const positionTypes = func.args.map((arg) => getTypeForArg(arg)).join(", ");
|
|
@@ -782,7 +774,7 @@ function generateMapsObject(maps, address, contractName) {
|
|
|
782
774
|
return "";
|
|
783
775
|
}
|
|
784
776
|
const mapMethods = maps.map((map) => {
|
|
785
|
-
const methodName =
|
|
777
|
+
const methodName = toCamelCase5(map.name);
|
|
786
778
|
const keyType = getTypeForArg({ type: map.key });
|
|
787
779
|
const valueType = getTypeForArg({ type: map.value });
|
|
788
780
|
const keyConversion = generateMapKeyConversion(map.key);
|
|
@@ -843,7 +835,7 @@ function generateVarsObject(variables, address, contractName) {
|
|
|
843
835
|
return "";
|
|
844
836
|
}
|
|
845
837
|
const varMethods = dataVars.map((variable) => {
|
|
846
|
-
const methodName =
|
|
838
|
+
const methodName = toCamelCase5(variable.name);
|
|
847
839
|
const valueType = getTypeForArg({ type: variable.type });
|
|
848
840
|
return `${methodName}: {
|
|
849
841
|
async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
|
|
@@ -888,7 +880,7 @@ function generateConstantsObject(variables, address, contractName) {
|
|
|
888
880
|
return "";
|
|
889
881
|
}
|
|
890
882
|
const constMethods = constants.map((constant) => {
|
|
891
|
-
const methodName =
|
|
883
|
+
const methodName = toCamelCase5(constant.name);
|
|
892
884
|
const valueType = getTypeForArg({ type: constant.type });
|
|
893
885
|
return `${methodName}: {
|
|
894
886
|
async get(options?: { network?: 'mainnet' | 'testnet' | 'devnet' }): Promise<${valueType}> {
|
|
@@ -1080,7 +1072,7 @@ function normalizeAbi(abi) {
|
|
|
1080
1072
|
|
|
1081
1073
|
// src/plugins/clarinet/index.ts
|
|
1082
1074
|
function sanitizeContractName(name) {
|
|
1083
|
-
return
|
|
1075
|
+
return toCamelCase6(name);
|
|
1084
1076
|
}
|
|
1085
1077
|
async function isUserDefinedContract(contractId, manifestPath) {
|
|
1086
1078
|
const { address, contractName } = parseContractId(contractId);
|
|
@@ -1190,7 +1182,7 @@ async function hasClarinetProject(path2 = "./Clarinet.toml") {
|
|
|
1190
1182
|
}
|
|
1191
1183
|
}
|
|
1192
1184
|
// src/plugins/actions/generators.ts
|
|
1193
|
-
import { toCamelCase as
|
|
1185
|
+
import { toCamelCase as toCamelCase7 } from "@secondlayer/stacks/clarity";
|
|
1194
1186
|
function generateReadHelpers(contract, options) {
|
|
1195
1187
|
const { abi } = contract;
|
|
1196
1188
|
const functions = abi.functions || [];
|
|
@@ -1211,7 +1203,7 @@ function generateReadHelpers(contract, options) {
|
|
|
1211
1203
|
return "";
|
|
1212
1204
|
}
|
|
1213
1205
|
const helpers = filteredFunctions.map((func) => {
|
|
1214
|
-
const methodName =
|
|
1206
|
+
const methodName = toCamelCase7(func.name);
|
|
1215
1207
|
const argsSignature = generateArgsSignature(func.args);
|
|
1216
1208
|
const clarityArgs = generateClarityArgs(func.args);
|
|
1217
1209
|
return `async ${methodName}(${argsSignature}options?: {
|
|
@@ -1255,7 +1247,7 @@ function generateWriteHelpers(contract, options) {
|
|
|
1255
1247
|
return "";
|
|
1256
1248
|
}
|
|
1257
1249
|
const helpers = filteredFunctions.map((func) => {
|
|
1258
|
-
const methodName =
|
|
1250
|
+
const methodName = toCamelCase7(func.name);
|
|
1259
1251
|
const argsSignature = generateArgsSignature(func.args);
|
|
1260
1252
|
const clarityArgs = generateClarityArgs(func.args);
|
|
1261
1253
|
return `async ${methodName}(${argsSignature}senderKey?: string, options?: {
|
|
@@ -2193,31 +2185,36 @@ function generateGenericHook(hookName) {
|
|
|
2193
2185
|
// src/plugins/react/generators/contract.ts
|
|
2194
2186
|
init_format();
|
|
2195
2187
|
|
|
2196
|
-
// src/
|
|
2197
|
-
import { toCamelCase as
|
|
2188
|
+
// src/utils/case-conversion.ts
|
|
2189
|
+
import { toCamelCase as toCamelCase8 } from "@secondlayer/stacks/clarity";
|
|
2198
2190
|
function capitalize(str) {
|
|
2199
2191
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
2200
2192
|
}
|
|
2193
|
+
function toPascalCase(str) {
|
|
2194
|
+
return capitalize(toCamelCase8(str));
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
// src/plugins/react/generators/utils.ts
|
|
2201
2198
|
function generateHookArgsSignature(args) {
|
|
2202
2199
|
if (args.length === 0)
|
|
2203
2200
|
return "";
|
|
2204
|
-
const argsList = args.map((arg) => `${
|
|
2201
|
+
const argsList = args.map((arg) => `${toCamelCase8(arg.name)}: ${clarityTypeToTS(arg.type)}`).join(", ");
|
|
2205
2202
|
return `${argsList}`;
|
|
2206
2203
|
}
|
|
2207
2204
|
function generateArgsType(args) {
|
|
2208
2205
|
if (args.length === 0)
|
|
2209
2206
|
return "void";
|
|
2210
|
-
const argsList = args.map((arg) => `${
|
|
2207
|
+
const argsList = args.map((arg) => `${toCamelCase8(arg.name)}: ${clarityTypeToTS(arg.type)}`).join("; ");
|
|
2211
2208
|
return `{ ${argsList} }`;
|
|
2212
2209
|
}
|
|
2213
2210
|
function generateArgNames(args) {
|
|
2214
2211
|
if (args.length === 0)
|
|
2215
2212
|
return "";
|
|
2216
|
-
return args.map((arg) =>
|
|
2213
|
+
return args.map((arg) => toCamelCase8(arg.name)).join(", ");
|
|
2217
2214
|
}
|
|
2218
2215
|
function generateEnabledCondition(args) {
|
|
2219
2216
|
return args.map((arg) => {
|
|
2220
|
-
const camelName =
|
|
2217
|
+
const camelName = toCamelCase8(arg.name);
|
|
2221
2218
|
const type = clarityTypeToTS(arg.type);
|
|
2222
2219
|
if (type === "string")
|
|
2223
2220
|
return `!!${camelName}`;
|
|
@@ -2229,7 +2226,7 @@ function generateEnabledCondition(args) {
|
|
|
2229
2226
|
function generateObjectArgs(args) {
|
|
2230
2227
|
if (args.length === 0)
|
|
2231
2228
|
return "";
|
|
2232
|
-
return args.map((arg) => `${arg.name}: ${
|
|
2229
|
+
return args.map((arg) => `${arg.name}: ${toCamelCase8(arg.name)}`).join(", ");
|
|
2233
2230
|
}
|
|
2234
2231
|
|
|
2235
2232
|
// src/plugins/react/generators/contract.ts
|
|
@@ -2262,21 +2259,21 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
2262
2259
|
const readOnlyFunctions = functions.filter((f) => f.access === "read-only");
|
|
2263
2260
|
const publicFunctions = functions.filter((f) => f.access === "public");
|
|
2264
2261
|
const readHooks = readOnlyFunctions.map((func) => {
|
|
2265
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
2262
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(func.name))}`;
|
|
2266
2263
|
if (excludeList.includes(hookName)) {
|
|
2267
2264
|
return null;
|
|
2268
2265
|
}
|
|
2269
2266
|
return generateReadHook(func, name);
|
|
2270
2267
|
}).filter(Boolean);
|
|
2271
2268
|
const writeHooks = publicFunctions.map((func) => {
|
|
2272
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
2269
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(func.name))}`;
|
|
2273
2270
|
if (excludeList.includes(hookName)) {
|
|
2274
2271
|
return null;
|
|
2275
2272
|
}
|
|
2276
2273
|
return generateWriteHook(func, name);
|
|
2277
2274
|
}).filter(Boolean);
|
|
2278
2275
|
const mapHooks = maps.map((map) => {
|
|
2279
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
2276
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(map.name))}`;
|
|
2280
2277
|
if (excludeList.includes(hookName)) {
|
|
2281
2278
|
return null;
|
|
2282
2279
|
}
|
|
@@ -2284,7 +2281,7 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
2284
2281
|
}).filter(Boolean);
|
|
2285
2282
|
const dataVars = variables.filter((v) => v.access === "variable");
|
|
2286
2283
|
const varHooks = dataVars.map((variable) => {
|
|
2287
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
2284
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(variable.name))}`;
|
|
2288
2285
|
if (excludeList.includes(hookName)) {
|
|
2289
2286
|
return null;
|
|
2290
2287
|
}
|
|
@@ -2292,7 +2289,7 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
2292
2289
|
}).filter(Boolean);
|
|
2293
2290
|
const constants = variables.filter((v) => v.access === "constant");
|
|
2294
2291
|
const constantHooks = constants.map((constant) => {
|
|
2295
|
-
const hookName = `use${capitalize(name)}${capitalize(
|
|
2292
|
+
const hookName = `use${capitalize(name)}${capitalize(toCamelCase8(constant.name))}`;
|
|
2296
2293
|
if (excludeList.includes(hookName)) {
|
|
2297
2294
|
return null;
|
|
2298
2295
|
}
|
|
@@ -2307,7 +2304,7 @@ function generateContractHookMethods(contract, excludeList) {
|
|
|
2307
2304
|
`);
|
|
2308
2305
|
}
|
|
2309
2306
|
function generateReadHook(func, contractName) {
|
|
2310
|
-
const hookName = `use${capitalize(contractName)}${capitalize(
|
|
2307
|
+
const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase8(func.name))}`;
|
|
2311
2308
|
const argsSignature = generateHookArgsSignature(func.args);
|
|
2312
2309
|
const enabledParam = func.args.length > 0 ? ", options?: { enabled?: boolean }" : "options?: { enabled?: boolean }";
|
|
2313
2310
|
const returnType = clarityTypeToTS(func.outputs);
|
|
@@ -2316,7 +2313,7 @@ function generateReadHook(func, contractName) {
|
|
|
2316
2313
|
|
|
2317
2314
|
return useQuery<${returnType}>({
|
|
2318
2315
|
queryKey: ['${func.name}', ${contractName}.address, ${generateArgNames(func.args)}],
|
|
2319
|
-
queryFn: () => ${contractName}.read.${
|
|
2316
|
+
queryFn: () => ${contractName}.read.${toCamelCase8(func.name)}(${generateArgNames(func.args) ? `{ ${generateObjectArgs(func.args)} }, ` : ""}{
|
|
2320
2317
|
network: config.network,
|
|
2321
2318
|
senderAddress: config.senderAddress || 'SP000000000000000000002Q6VF78'
|
|
2322
2319
|
}),
|
|
@@ -2326,7 +2323,7 @@ function generateReadHook(func, contractName) {
|
|
|
2326
2323
|
}`;
|
|
2327
2324
|
}
|
|
2328
2325
|
function generateWriteHook(func, contractName) {
|
|
2329
|
-
const hookName = `use${capitalize(contractName)}${capitalize(
|
|
2326
|
+
const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase8(func.name))}`;
|
|
2330
2327
|
const argsType = generateArgsType(func.args);
|
|
2331
2328
|
return `export function ${hookName}() {
|
|
2332
2329
|
const config = useSecondLayerConfig()
|
|
@@ -2343,7 +2340,7 @@ function generateWriteHook(func, contractName) {
|
|
|
2343
2340
|
};
|
|
2344
2341
|
}) => {
|
|
2345
2342
|
const { args, options = {} } = params
|
|
2346
|
-
const contractCallData = ${contractName}.${
|
|
2343
|
+
const contractCallData = ${contractName}.${toCamelCase8(func.name)}(args)
|
|
2347
2344
|
const { contractAddress, contractName: name, functionName, functionArgs } = contractCallData
|
|
2348
2345
|
const network = config.network || 'mainnet'
|
|
2349
2346
|
const contract = \`\${contractAddress}.\${name}\`
|
|
@@ -2368,7 +2365,7 @@ function generateWriteHook(func, contractName) {
|
|
|
2368
2365
|
}
|
|
2369
2366
|
})
|
|
2370
2367
|
|
|
2371
|
-
const ${
|
|
2368
|
+
const ${toCamelCase8(func.name)} = useCallback(async (
|
|
2372
2369
|
args: ${argsType},
|
|
2373
2370
|
options?: {
|
|
2374
2371
|
postConditions?: PostCondition[];
|
|
@@ -2381,7 +2378,7 @@ function generateWriteHook(func, contractName) {
|
|
|
2381
2378
|
}, [mutation])
|
|
2382
2379
|
|
|
2383
2380
|
return {
|
|
2384
|
-
${
|
|
2381
|
+
${toCamelCase8(func.name)},
|
|
2385
2382
|
// Expose mutation state
|
|
2386
2383
|
isPending: mutation.isPending,
|
|
2387
2384
|
isError: mutation.isError,
|
|
@@ -2393,7 +2390,7 @@ function generateWriteHook(func, contractName) {
|
|
|
2393
2390
|
}`;
|
|
2394
2391
|
}
|
|
2395
2392
|
function generateMapHook(map, contractVarName, _address, _contractName) {
|
|
2396
|
-
const hookName = `use${capitalize(contractVarName)}${capitalize(
|
|
2393
|
+
const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase8(map.name))}`;
|
|
2397
2394
|
const keyType = clarityTypeToTS(map.key);
|
|
2398
2395
|
const valueType = clarityTypeToTS(map.value);
|
|
2399
2396
|
return `export function ${hookName}(key: ${keyType}, options?: { enabled?: boolean }) {
|
|
@@ -2402,14 +2399,14 @@ function generateMapHook(map, contractVarName, _address, _contractName) {
|
|
|
2402
2399
|
return useQuery<${valueType} | null>({
|
|
2403
2400
|
queryKey: ['${contractVarName}', '${map.name}', 'map', key, config.network],
|
|
2404
2401
|
queryFn: async () => {
|
|
2405
|
-
return ${contractVarName}.maps.${
|
|
2402
|
+
return ${contractVarName}.maps.${toCamelCase8(map.name)}.get(key, { network: config.network })
|
|
2406
2403
|
},
|
|
2407
2404
|
enabled: options?.enabled ?? true
|
|
2408
2405
|
})
|
|
2409
2406
|
}`;
|
|
2410
2407
|
}
|
|
2411
2408
|
function generateVarHook(variable, contractVarName, _address, _contractName) {
|
|
2412
|
-
const hookName = `use${capitalize(contractVarName)}${capitalize(
|
|
2409
|
+
const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase8(variable.name))}`;
|
|
2413
2410
|
const valueType = clarityTypeToTS(variable.type);
|
|
2414
2411
|
return `export function ${hookName}(options?: { enabled?: boolean }) {
|
|
2415
2412
|
const config = useSecondLayerConfig()
|
|
@@ -2417,14 +2414,14 @@ function generateVarHook(variable, contractVarName, _address, _contractName) {
|
|
|
2417
2414
|
return useQuery<${valueType}>({
|
|
2418
2415
|
queryKey: ['${contractVarName}', '${variable.name}', 'var', config.network],
|
|
2419
2416
|
queryFn: async () => {
|
|
2420
|
-
return ${contractVarName}.vars.${
|
|
2417
|
+
return ${contractVarName}.vars.${toCamelCase8(variable.name)}.get({ network: config.network })
|
|
2421
2418
|
},
|
|
2422
2419
|
enabled: options?.enabled ?? true
|
|
2423
2420
|
})
|
|
2424
2421
|
}`;
|
|
2425
2422
|
}
|
|
2426
2423
|
function generateConstantHook(constant, contractVarName, _address, _contractName) {
|
|
2427
|
-
const hookName = `use${capitalize(contractVarName)}${capitalize(
|
|
2424
|
+
const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase8(constant.name))}`;
|
|
2428
2425
|
const valueType = clarityTypeToTS(constant.type);
|
|
2429
2426
|
return `export function ${hookName}(options?: { enabled?: boolean }) {
|
|
2430
2427
|
const config = useSecondLayerConfig()
|
|
@@ -2432,7 +2429,7 @@ function generateConstantHook(constant, contractVarName, _address, _contractName
|
|
|
2432
2429
|
return useQuery<${valueType}>({
|
|
2433
2430
|
queryKey: ['${contractVarName}', '${constant.name}', 'constant', config.network],
|
|
2434
2431
|
queryFn: async () => {
|
|
2435
|
-
return ${contractVarName}.constants.${
|
|
2432
|
+
return ${contractVarName}.constants.${toCamelCase8(constant.name)}.get({ network: config.network })
|
|
2436
2433
|
},
|
|
2437
2434
|
enabled: options?.enabled ?? true,
|
|
2438
2435
|
staleTime: Infinity // Constants never change
|
|
@@ -2480,13 +2477,8 @@ var react = (options = {}) => {
|
|
|
2480
2477
|
};
|
|
2481
2478
|
// src/plugins/testing/generators.ts
|
|
2482
2479
|
import {
|
|
2483
|
-
toCamelCase as toCamelCase8,
|
|
2484
2480
|
isAbiTuple as isAbiTuple4
|
|
2485
2481
|
} from "@secondlayer/stacks/clarity";
|
|
2486
|
-
function toPascalCase(str) {
|
|
2487
|
-
const camel = toCamelCase8(str);
|
|
2488
|
-
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
2489
|
-
}
|
|
2490
2482
|
function generatePublicFunction(func, contractId) {
|
|
2491
2483
|
const methodName = toCamelCase8(func.name);
|
|
2492
2484
|
const argsSignature = generateArgsSignature(func.args);
|
|
@@ -2742,5 +2734,5 @@ export {
|
|
|
2742
2734
|
PluginManager
|
|
2743
2735
|
};
|
|
2744
2736
|
|
|
2745
|
-
//# debugId=
|
|
2737
|
+
//# debugId=76F0203451B4697D64756E2164756E21
|
|
2746
2738
|
//# sourceMappingURL=index.js.map
|