@secondlayer/cli 3.3.0 → 3.3.2

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.
@@ -0,0 +1,364 @@
1
+ import { AbiContract as AbiContract2 } from "@secondlayer/stacks/clarity";
2
+ import { AbiContract } from "@secondlayer/stacks/clarity";
3
+ /** Supported Stacks network identifiers for contract resolution. */
4
+ type NetworkName = "mainnet" | "testnet" | "devnet";
5
+ /** Specifies a contract to generate typed interfaces for, either from a deployed address or local Clarity source file. */
6
+ interface ContractSource {
7
+ /**
8
+ * Contract identifier (address.name) for deployed contracts
9
+ */
10
+ address?: string | Partial<Record<NetworkName, string>>;
11
+ /**
12
+ * Path to local Clarity file
13
+ */
14
+ source?: string;
15
+ /**
16
+ * Optional name to use in generated code
17
+ */
18
+ name?: string;
19
+ }
20
+ /** Configuration for the `@secondlayer/cli` code generator. Defines which contracts to process, output paths, network settings, and plugins. */
21
+ interface SecondLayerConfig {
22
+ /**
23
+ * Contracts to generate interfaces for (optional - plugins can provide these)
24
+ */
25
+ contracts?: ContractSource[];
26
+ /**
27
+ * Output file path
28
+ */
29
+ out: string;
30
+ /**
31
+ * Plugins to use for generation
32
+ */
33
+ plugins?: any[];
34
+ /**
35
+ * Network to use for fetching contracts
36
+ */
37
+ network?: NetworkName;
38
+ /**
39
+ * API key for Stacks API (if required)
40
+ */
41
+ apiKey?: string;
42
+ /**
43
+ * Base URL for Stacks API (optional override)
44
+ */
45
+ apiUrl?: string;
46
+ /**
47
+ * Default deployer address for local contracts without explicit addresses
48
+ * Defaults to ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM (devnet default)
49
+ */
50
+ defaultAddress?: string;
51
+ }
52
+ interface ResolvedContract {
53
+ name: string;
54
+ address: string;
55
+ contractName: string;
56
+ abi: AbiContract;
57
+ source: "api" | "local";
58
+ }
59
+ /**
60
+ * Core plugin interface that all plugins must implement
61
+ */
62
+ interface SecondLayerPlugin {
63
+ /** Plugin name (should be unique) */
64
+ name: string;
65
+ /** Plugin version */
66
+ version: string;
67
+ /** Called after config is resolved but before generation starts */
68
+ configResolved?: (config: ResolvedConfig) => void | Promise<void>;
69
+ /** Called before generation starts */
70
+ beforeGenerate?: (context: GenerateContext) => void | Promise<void>;
71
+ /** Called during generation phase - plugins can add their own outputs */
72
+ generate?: (context: GenerateContext) => void | Promise<void>;
73
+ /** Called after all generation is complete */
74
+ afterGenerate?: (context: GenerateContext) => void | Promise<void>;
75
+ /** Transform user config before resolution */
76
+ transformConfig?: (config: UserConfig) => UserConfig | Promise<UserConfig>;
77
+ /** Transform individual contracts during processing */
78
+ transformContract?: (contract: ContractConfig) => ContractConfig | Promise<ContractConfig>;
79
+ /** Transform generated output before writing to disk */
80
+ transformOutput?: (output: string, type: OutputType) => string | Promise<string>;
81
+ }
82
+ /**
83
+ * User configuration (before plugin transformations)
84
+ */
85
+ type UserConfig = SecondLayerConfig;
86
+ /**
87
+ * Resolved configuration (after plugin transformations)
88
+ */
89
+ interface ResolvedConfig extends SecondLayerConfig {
90
+ /** Resolved plugins array */
91
+ plugins: SecondLayerPlugin[];
92
+ }
93
+ /**
94
+ * Contract configuration that can be transformed by plugins
95
+ */
96
+ interface ContractConfig {
97
+ name?: string;
98
+ address?: string | Partial<Record<NetworkName, string>>;
99
+ source?: string;
100
+ abi?: AbiContract2;
101
+ metadata?: Record<string, any>;
102
+ }
103
+ /**
104
+ * Processed contract with resolved ABI and metadata
105
+ */
106
+ interface ProcessedContract extends ResolvedContract {
107
+ /** Additional metadata added by plugins */
108
+ metadata?: Record<string, any>;
109
+ }
110
+ /**
111
+ * Generated output from plugins
112
+ */
113
+ interface GeneratedOutput {
114
+ /** File path where output should be written */
115
+ path: string;
116
+ /** Generated content */
117
+ content: string;
118
+ /** Output type for transformation hooks */
119
+ type?: OutputType;
120
+ /** Whether this output should overwrite existing files */
121
+ overwrite?: boolean;
122
+ }
123
+ /**
124
+ * Types of outputs that can be generated
125
+ */
126
+ type OutputType = "contracts" | "hooks" | "actions" | "types" | "utils" | "config" | "other";
127
+ /**
128
+ * Base context available to all plugin hooks
129
+ */
130
+ interface PluginContext {
131
+ /** Resolved configuration */
132
+ config: ResolvedConfig;
133
+ /** Logger for plugin output */
134
+ logger: Logger;
135
+ /** Utility functions for plugins */
136
+ utils: PluginUtils;
137
+ }
138
+ /**
139
+ * Context available during generation phase
140
+ */
141
+ interface GenerateContext extends PluginContext {
142
+ /** Processed contracts ready for generation */
143
+ contracts: ProcessedContract[];
144
+ /** Map of output keys to generated content */
145
+ outputs: Map<string, GeneratedOutput>;
146
+ /** Function to augment existing outputs */
147
+ augment: (outputKey: string, contractName: string, content: any) => void;
148
+ /** Function to add new outputs */
149
+ addOutput: (key: string, output: GeneratedOutput) => void;
150
+ }
151
+ /**
152
+ * Logger interface for plugin output
153
+ */
154
+ interface Logger {
155
+ info: (message: string) => void;
156
+ warn: (message: string) => void;
157
+ error: (message: string) => void;
158
+ debug: (message: string) => void;
159
+ success: (message: string) => void;
160
+ }
161
+ /**
162
+ * Utility functions available to plugins
163
+ */
164
+ interface PluginUtils {
165
+ /** Convert kebab-case to camelCase */
166
+ toCamelCase: (str: string) => string;
167
+ /** Convert camelCase to kebab-case */
168
+ toKebabCase: (str: string) => string;
169
+ /** Validate Stacks address format */
170
+ validateAddress: (address: string) => boolean;
171
+ /** Parse contract identifier (address.contract-name) */
172
+ parseContractId: (contractId: string) => {
173
+ address: string
174
+ contractName: string
175
+ };
176
+ /** Format TypeScript code using prettier */
177
+ formatCode: (code: string) => Promise<string>;
178
+ /** Resolve file path relative to project root */
179
+ resolvePath: (relativePath: string) => string;
180
+ /** Check if file exists */
181
+ fileExists: (path: string) => Promise<boolean>;
182
+ /** Read file content */
183
+ readFile: (path: string) => Promise<string>;
184
+ /** Write file content */
185
+ writeFile: (path: string, content: string) => Promise<void>;
186
+ /** Create directory recursively */
187
+ ensureDir: (path: string) => Promise<void>;
188
+ }
189
+ /**
190
+ * Plugin factory function type for creating plugins with options
191
+ */
192
+ type PluginFactory<TOptions = any> = (options?: TOptions) => SecondLayerPlugin;
193
+ /**
194
+ * Plugin options base interface
195
+ */
196
+ interface PluginOptions {
197
+ /** Include only specific contracts/functions */
198
+ include?: string[];
199
+ /** Exclude specific contracts/functions */
200
+ exclude?: string[];
201
+ /** Enable debug output */
202
+ debug?: boolean;
203
+ }
204
+ /**
205
+ * Hook execution result
206
+ */
207
+ interface HookResult<T = any> {
208
+ /** Whether the hook was successful */
209
+ success: boolean;
210
+ /** Result data from the hook */
211
+ data?: T;
212
+ /** Error if hook failed */
213
+ error?: Error;
214
+ /** Plugin that executed the hook */
215
+ plugin: string;
216
+ }
217
+ /**
218
+ * Core plugin manager that orchestrates plugin execution
219
+ */
220
+ declare class PluginManager {
221
+ private plugins;
222
+ private logger;
223
+ private utils;
224
+ private executionContext;
225
+ constructor();
226
+ /**
227
+ * Register a plugin
228
+ */
229
+ register(plugin: SecondLayerPlugin): void;
230
+ /**
231
+ * Get all registered plugins
232
+ */
233
+ getPlugins(): SecondLayerPlugin[];
234
+ /**
235
+ * Transform user config through all plugins
236
+ */
237
+ transformConfig(config: UserConfig): Promise<ResolvedConfig>;
238
+ /**
239
+ * Transform contracts through all plugins
240
+ */
241
+ transformContracts(contracts: ContractConfig[], _config: ResolvedConfig): Promise<ProcessedContract[]>;
242
+ /**
243
+ * Execute lifecycle hooks
244
+ */
245
+ executeHook(hookName: keyof SecondLayerPlugin, context: any): Promise<void>;
246
+ /**
247
+ * Execute generation phase with full context
248
+ */
249
+ executeGeneration(contracts: ProcessedContract[], config: ResolvedConfig): Promise<Map<string, GeneratedOutput>>;
250
+ /**
251
+ * Transform outputs through plugins
252
+ */
253
+ transformOutputs(outputs: Map<string, GeneratedOutput>): Promise<Map<string, GeneratedOutput>>;
254
+ /**
255
+ * Write outputs to disk
256
+ */
257
+ writeOutputs(outputs: Map<string, GeneratedOutput>): Promise<void>;
258
+ /**
259
+ * Get execution results for debugging
260
+ */
261
+ getExecutionResults(): Map<string, HookResult[]>;
262
+ /**
263
+ * Convert a contract config with an ABI into a ProcessedContract
264
+ */
265
+ private contractToProcessed;
266
+ /**
267
+ * Augment existing output with additional content
268
+ */
269
+ private augmentOutput;
270
+ /**
271
+ * Record hook execution result
272
+ */
273
+ private recordHookResult;
274
+ /**
275
+ * Create logger instance
276
+ */
277
+ private createLogger;
278
+ /**
279
+ * Create utils instance
280
+ */
281
+ private createUtils;
282
+ }
283
+ interface ClarinetPluginOptions {
284
+ /** Path to Clarinet.toml file */
285
+ path?: string;
286
+ /** Include only specific contracts */
287
+ include?: string[];
288
+ /** Exclude specific contracts */
289
+ exclude?: string[];
290
+ /** Enable debug output */
291
+ debug?: boolean;
292
+ }
293
+ /**
294
+ * Clarinet plugin factory
295
+ */
296
+ declare const clarinet: PluginFactory<ClarinetPluginOptions>;
297
+ /**
298
+ * Utility function to check if a Clarinet project exists
299
+ */
300
+ 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
+ /**
320
+ * React plugin configuration options
321
+ */
322
+ interface ReactPluginOptions extends PluginOptions {
323
+ /**
324
+ * Hooks to exclude from generation (both generic and contract-specific)
325
+ * By default, all hooks are generated
326
+ */
327
+ exclude?: string[];
328
+ }
329
+ /**
330
+ * React plugin factory
331
+ */
332
+ declare const react: PluginFactory<ReactPluginOptions>;
333
+ interface TestingPluginOptions {
334
+ /** Include only specific contracts */
335
+ include?: string[];
336
+ /** Exclude specific contracts */
337
+ exclude?: string[];
338
+ /** Output path for generated testing helpers (default: ./src/generated/testing.ts) */
339
+ out?: string;
340
+ /** Include private function helpers (default: false) */
341
+ includePrivate?: boolean;
342
+ /** Enable debug output */
343
+ debug?: boolean;
344
+ }
345
+ declare const testing: PluginFactory<TestingPluginOptions>;
346
+ interface BasePluginOptions {
347
+ /** Include only specific contracts/functions */
348
+ include?: string[];
349
+ /** Exclude specific contracts/functions */
350
+ exclude?: string[];
351
+ /** Enable debug output */
352
+ debug?: boolean;
353
+ }
354
+ /**
355
+ * Utility function to filter contracts/functions based on include/exclude options
356
+ */
357
+ declare function filterByOptions<T extends {
358
+ name: string
359
+ }>(items: T[], options?: BasePluginOptions): T[];
360
+ /**
361
+ * Utility function to create a simple plugin
362
+ */
363
+ declare function createPlugin(name: string, version: string, implementation: Partial<SecondLayerPlugin>): SecondLayerPlugin;
364
+ export { testing, react, hasClarinetProject, filterByOptions, createPlugin, clarinet, actions, TestingPluginOptions, SecondLayerPlugin, ReactPluginOptions, PluginUtils, PluginOptions, PluginManager, PluginFactory, PluginContext, Logger, GenerateContext, ClarinetPluginOptions, BasePluginOptions, ActionsPluginOptions };