@secondlayer/cli 14.0.3 → 14.1.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/README.md +2 -1
- package/dist/cli.js +607 -604
- package/dist/cli.js.map +10 -10
- package/dist/plugins/index.d.ts +1 -14
- package/dist/plugins/index.js +2 -234
- package/dist/plugins/index.js.map +7 -10
- package/package.json +13 -5
package/dist/plugins/index.d.ts
CHANGED
|
@@ -317,19 +317,6 @@ interface ReactPluginOptions extends PluginOptions {
|
|
|
317
317
|
* React plugin factory
|
|
318
318
|
*/
|
|
319
319
|
declare const react: PluginFactory<ReactPluginOptions>;
|
|
320
|
-
interface TestingPluginOptions {
|
|
321
|
-
/** Include only specific contracts */
|
|
322
|
-
include?: string[];
|
|
323
|
-
/** Exclude specific contracts */
|
|
324
|
-
exclude?: string[];
|
|
325
|
-
/** Output path for generated testing helpers (default: ./src/generated/testing.ts) */
|
|
326
|
-
out?: string;
|
|
327
|
-
/** Include private function helpers (default: false) */
|
|
328
|
-
includePrivate?: boolean;
|
|
329
|
-
/** Enable debug output */
|
|
330
|
-
debug?: boolean;
|
|
331
|
-
}
|
|
332
|
-
declare const testing: PluginFactory<TestingPluginOptions>;
|
|
333
320
|
interface BasePluginOptions {
|
|
334
321
|
/** Include only specific contracts/functions */
|
|
335
322
|
include?: string[];
|
|
@@ -348,4 +335,4 @@ declare function filterByOptions<T extends {
|
|
|
348
335
|
* Utility function to create a simple plugin
|
|
349
336
|
*/
|
|
350
337
|
declare function createPlugin(name: string, version: string, implementation: Partial<SecondLayerPlugin>): SecondLayerPlugin;
|
|
351
|
-
export {
|
|
338
|
+
export { react, hasClarinetProject, filterByOptions, createPlugin, clarinet, SecondLayerPlugin, ReactPluginOptions, PluginUtils, PluginOptions, PluginManager, PluginFactory, PluginContext, Logger, GenerateContext, ClarinetPluginOptions, BasePluginOptions };
|
package/dist/plugins/index.js
CHANGED
|
@@ -413,9 +413,9 @@ init_plugin_manager();
|
|
|
413
413
|
|
|
414
414
|
// src/plugins/clarinet/index.ts
|
|
415
415
|
init_contract();
|
|
416
|
-
import { initSimnet } from "@hirosystems/clarinet-sdk";
|
|
417
416
|
import { toCamelCase as toCamelCase2 } from "@secondlayer/stacks/clarity";
|
|
418
417
|
import { normalizeAbi } from "@secondlayer/stacks/clarity";
|
|
418
|
+
import { initSimnet } from "@stacks/clarinet-sdk";
|
|
419
419
|
|
|
420
420
|
// src/utils/constants.ts
|
|
421
421
|
var DEFAULT_SENDER_ADDRESS = "SP000000000000000000002Q6VF78";
|
|
@@ -1723,237 +1723,6 @@ var react = (options = {}) => {
|
|
|
1723
1723
|
}
|
|
1724
1724
|
};
|
|
1725
1725
|
};
|
|
1726
|
-
// src/plugins/testing/generators.ts
|
|
1727
|
-
init_case_conversion();
|
|
1728
|
-
import {
|
|
1729
|
-
isAbiTuple
|
|
1730
|
-
} from "@secondlayer/stacks/clarity";
|
|
1731
|
-
|
|
1732
|
-
// src/utils/generator-helpers.ts
|
|
1733
|
-
import {
|
|
1734
|
-
generateArgsSignature,
|
|
1735
|
-
generateClarityArgs,
|
|
1736
|
-
generateMapKeyConversion
|
|
1737
|
-
} from "@secondlayer/scaffold";
|
|
1738
|
-
|
|
1739
|
-
// src/plugins/testing/generators.ts
|
|
1740
|
-
function generatePublicFunction(func, contractId) {
|
|
1741
|
-
const methodName = toCamelCase3(func.name);
|
|
1742
|
-
const argsSignature = generateArgsSignature(func.args);
|
|
1743
|
-
const clarityArgs = generateClarityArgs(func.args);
|
|
1744
|
-
return `${methodName}: (${argsSignature}caller: string) => {
|
|
1745
|
-
const callerAddr = accounts.get(caller) ?? caller;
|
|
1746
|
-
return simnet.callPublicFn(
|
|
1747
|
-
'${contractId}',
|
|
1748
|
-
'${func.name}',
|
|
1749
|
-
[${clarityArgs}],
|
|
1750
|
-
callerAddr
|
|
1751
|
-
);
|
|
1752
|
-
}`;
|
|
1753
|
-
}
|
|
1754
|
-
function generateReadOnlyFunction(func, contractId) {
|
|
1755
|
-
const methodName = toCamelCase3(func.name);
|
|
1756
|
-
const argsSignature = generateArgsSignature(func.args);
|
|
1757
|
-
const clarityArgs = generateClarityArgs(func.args);
|
|
1758
|
-
const hasArgs = func.args.length > 0;
|
|
1759
|
-
const argsParam = hasArgs ? argsSignature : "";
|
|
1760
|
-
return `${methodName}: (${argsParam}) => {
|
|
1761
|
-
return simnet.callReadOnlyFn(
|
|
1762
|
-
'${contractId}',
|
|
1763
|
-
'${func.name}',
|
|
1764
|
-
[${clarityArgs}],
|
|
1765
|
-
accounts.get('deployer')!
|
|
1766
|
-
);
|
|
1767
|
-
}`;
|
|
1768
|
-
}
|
|
1769
|
-
function generatePrivateFunction(func, contractId) {
|
|
1770
|
-
const methodName = toCamelCase3(func.name);
|
|
1771
|
-
const argsSignature = generateArgsSignature(func.args);
|
|
1772
|
-
const clarityArgs = generateClarityArgs(func.args);
|
|
1773
|
-
return `${methodName}: (${argsSignature}caller: string) => {
|
|
1774
|
-
const callerAddr = accounts.get(caller) ?? caller;
|
|
1775
|
-
return simnet.callPrivateFn(
|
|
1776
|
-
'${contractId}',
|
|
1777
|
-
'${func.name}',
|
|
1778
|
-
[${clarityArgs}],
|
|
1779
|
-
callerAddr
|
|
1780
|
-
);
|
|
1781
|
-
}`;
|
|
1782
|
-
}
|
|
1783
|
-
function generateDataVarHelper(variable, contractId) {
|
|
1784
|
-
const methodName = toCamelCase3(variable.name);
|
|
1785
|
-
return `${methodName}: () => {
|
|
1786
|
-
return simnet.getDataVar('${contractId}', '${variable.name}');
|
|
1787
|
-
}`;
|
|
1788
|
-
}
|
|
1789
|
-
function getMapKeyType(keyType) {
|
|
1790
|
-
if (isAbiTuple(keyType)) {
|
|
1791
|
-
const fields = keyType.tuple.map((field) => `${toCamelCase3(field.name)}: ${getTypeForArg({ type: field.type })}`).join("; ");
|
|
1792
|
-
return `{ ${fields} }`;
|
|
1793
|
-
}
|
|
1794
|
-
return getTypeForArg({ type: keyType });
|
|
1795
|
-
}
|
|
1796
|
-
function generateMapEntryHelper(map, contractId) {
|
|
1797
|
-
const methodName = toCamelCase3(map.name);
|
|
1798
|
-
const keyType = getMapKeyType(map.key);
|
|
1799
|
-
const keyConversion = generateMapKeyConversion(map.key);
|
|
1800
|
-
return `${methodName}: (key: ${keyType}) => {
|
|
1801
|
-
return simnet.getMapEntry(
|
|
1802
|
-
'${contractId}',
|
|
1803
|
-
'${map.name}',
|
|
1804
|
-
${keyConversion}
|
|
1805
|
-
);
|
|
1806
|
-
}`;
|
|
1807
|
-
}
|
|
1808
|
-
function generateVarsObject(variables, contractId) {
|
|
1809
|
-
const dataVars = variables.filter((v) => v.access === "variable");
|
|
1810
|
-
if (dataVars.length === 0) {
|
|
1811
|
-
return "";
|
|
1812
|
-
}
|
|
1813
|
-
const varHelpers = dataVars.map((v) => generateDataVarHelper(v, contractId));
|
|
1814
|
-
return `vars: {
|
|
1815
|
-
${varHelpers.join(`,
|
|
1816
|
-
|
|
1817
|
-
`)}
|
|
1818
|
-
}`;
|
|
1819
|
-
}
|
|
1820
|
-
function generateMapsObject(maps, contractId) {
|
|
1821
|
-
if (maps.length === 0) {
|
|
1822
|
-
return "";
|
|
1823
|
-
}
|
|
1824
|
-
const mapHelpers = maps.map((m) => generateMapEntryHelper(m, contractId));
|
|
1825
|
-
return `maps: {
|
|
1826
|
-
${mapHelpers.join(`,
|
|
1827
|
-
|
|
1828
|
-
`)}
|
|
1829
|
-
}`;
|
|
1830
|
-
}
|
|
1831
|
-
function generateContractHelper(contract, options) {
|
|
1832
|
-
const { abi, name, address } = contract;
|
|
1833
|
-
const functions = abi.functions || [];
|
|
1834
|
-
const variables = abi.variables || [];
|
|
1835
|
-
const maps = abi.maps || [];
|
|
1836
|
-
const pascalName = toPascalCase(name);
|
|
1837
|
-
const publicFns = functions.filter((f) => f.access === "public");
|
|
1838
|
-
const readOnlyFns = functions.filter((f) => f.access === "read-only");
|
|
1839
|
-
const privateFns = options.includePrivate ? functions.filter((f) => f.access === "private") : [];
|
|
1840
|
-
const publicHelpers = publicFns.map((f) => generatePublicFunction(f, address));
|
|
1841
|
-
const readOnlyHelpers = readOnlyFns.map((f) => generateReadOnlyFunction(f, address));
|
|
1842
|
-
const privateHelpers = privateFns.map((f) => generatePrivateFunction(f, address));
|
|
1843
|
-
const varsObject = generateVarsObject(variables, address);
|
|
1844
|
-
const mapsObject = generateMapsObject(maps, address);
|
|
1845
|
-
const allHelpers = [...publicHelpers, ...readOnlyHelpers, ...privateHelpers];
|
|
1846
|
-
if (varsObject) {
|
|
1847
|
-
allHelpers.push(varsObject);
|
|
1848
|
-
}
|
|
1849
|
-
if (mapsObject) {
|
|
1850
|
-
allHelpers.push(mapsObject);
|
|
1851
|
-
}
|
|
1852
|
-
if (allHelpers.length === 0) {
|
|
1853
|
-
return "";
|
|
1854
|
-
}
|
|
1855
|
-
return `export function get${pascalName}(simnet: Simnet) {
|
|
1856
|
-
const accounts = simnet.getAccounts();
|
|
1857
|
-
|
|
1858
|
-
return {
|
|
1859
|
-
${allHelpers.join(`,
|
|
1860
|
-
|
|
1861
|
-
`)}
|
|
1862
|
-
};
|
|
1863
|
-
}`;
|
|
1864
|
-
}
|
|
1865
|
-
function generateGetContracts(contracts) {
|
|
1866
|
-
const contractEntries = contracts.map((contract) => {
|
|
1867
|
-
const camelName = toCamelCase3(contract.name);
|
|
1868
|
-
const pascalName = toPascalCase(contract.name);
|
|
1869
|
-
return `${camelName}: get${pascalName}(simnet)`;
|
|
1870
|
-
}).join(`,
|
|
1871
|
-
`);
|
|
1872
|
-
return `export function getContracts(simnet: Simnet) {
|
|
1873
|
-
const accounts = simnet.getAccounts();
|
|
1874
|
-
|
|
1875
|
-
return {
|
|
1876
|
-
accounts,
|
|
1877
|
-
${contractEntries}
|
|
1878
|
-
};
|
|
1879
|
-
}`;
|
|
1880
|
-
}
|
|
1881
|
-
function generateTypeExports(contracts) {
|
|
1882
|
-
const typeExports = contracts.map((contract) => {
|
|
1883
|
-
const pascalName = toPascalCase(contract.name);
|
|
1884
|
-
return `export type ${pascalName}Helpers = ReturnType<typeof get${pascalName}>;`;
|
|
1885
|
-
}).join(`
|
|
1886
|
-
`);
|
|
1887
|
-
return `${typeExports}
|
|
1888
|
-
export type Contracts = ReturnType<typeof getContracts>;`;
|
|
1889
|
-
}
|
|
1890
|
-
async function generateTestingHelpers(contracts, options) {
|
|
1891
|
-
const contractHelpers = contracts.map((contract) => generateContractHelper(contract, options)).filter(Boolean);
|
|
1892
|
-
if (contractHelpers.length === 0) {
|
|
1893
|
-
return `// No contracts with functions to generate helpers for
|
|
1894
|
-
export {};`;
|
|
1895
|
-
}
|
|
1896
|
-
const getContractsCode = generateGetContracts(contracts);
|
|
1897
|
-
const typeExports = generateTypeExports(contracts);
|
|
1898
|
-
return `/**
|
|
1899
|
-
* Generated by @secondlayer/cli testing plugin
|
|
1900
|
-
* Type-safe helpers for Clarinet SDK unit tests
|
|
1901
|
-
*/
|
|
1902
|
-
|
|
1903
|
-
import { type Simnet, Cl } from '@hirosystems/clarinet-sdk';
|
|
1904
|
-
|
|
1905
|
-
// ============================================
|
|
1906
|
-
// Per-contract factory functions
|
|
1907
|
-
// ============================================
|
|
1908
|
-
|
|
1909
|
-
${contractHelpers.join(`
|
|
1910
|
-
|
|
1911
|
-
`)}
|
|
1912
|
-
|
|
1913
|
-
// ============================================
|
|
1914
|
-
// Convenience: all contracts at once
|
|
1915
|
-
// ============================================
|
|
1916
|
-
|
|
1917
|
-
${getContractsCode}
|
|
1918
|
-
|
|
1919
|
-
// ============================================
|
|
1920
|
-
// Type exports
|
|
1921
|
-
// ============================================
|
|
1922
|
-
|
|
1923
|
-
${typeExports}
|
|
1924
|
-
`;
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
// src/plugins/testing/index.ts
|
|
1928
|
-
var testing = (options = {}) => {
|
|
1929
|
-
return {
|
|
1930
|
-
name: "@secondlayer/cli/plugin-testing",
|
|
1931
|
-
version: "1.0.0",
|
|
1932
|
-
async generate(context) {
|
|
1933
|
-
const { contracts } = context;
|
|
1934
|
-
const filteredContracts = contracts.filter((contract) => matchesContractFilters(contract.name, options));
|
|
1935
|
-
if (filteredContracts.length === 0) {
|
|
1936
|
-
if (options.debug) {
|
|
1937
|
-
context.logger.debug("Testing plugin: No contracts to process");
|
|
1938
|
-
}
|
|
1939
|
-
return;
|
|
1940
|
-
}
|
|
1941
|
-
if (options.debug) {
|
|
1942
|
-
context.logger.debug(`Testing plugin: Generating helpers for ${filteredContracts.length} contracts`);
|
|
1943
|
-
}
|
|
1944
|
-
const testingCode = await generateTestingHelpers(filteredContracts, options);
|
|
1945
|
-
const outputPath = options.out || "./src/generated/testing.ts";
|
|
1946
|
-
context.addOutput("testing", {
|
|
1947
|
-
path: outputPath,
|
|
1948
|
-
content: testingCode,
|
|
1949
|
-
type: "utils"
|
|
1950
|
-
});
|
|
1951
|
-
if (options.debug) {
|
|
1952
|
-
context.logger.debug(`Testing plugin: Generated helpers for ${filteredContracts.length} contracts`);
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
};
|
|
1956
|
-
};
|
|
1957
1726
|
|
|
1958
1727
|
// src/plugins/index.ts
|
|
1959
1728
|
function filterByOptions(items, options = {}) {
|
|
@@ -1974,7 +1743,6 @@ function createPlugin(name, version, implementation) {
|
|
|
1974
1743
|
};
|
|
1975
1744
|
}
|
|
1976
1745
|
export {
|
|
1977
|
-
testing,
|
|
1978
1746
|
react,
|
|
1979
1747
|
hasClarinetProject,
|
|
1980
1748
|
filterByOptions,
|
|
@@ -1983,5 +1751,5 @@ export {
|
|
|
1983
1751
|
PluginManager
|
|
1984
1752
|
};
|
|
1985
1753
|
|
|
1986
|
-
//# debugId=
|
|
1754
|
+
//# debugId=3858A2BEFB777D7764756E2164756E21
|
|
1987
1755
|
//# sourceMappingURL=index.js.map
|