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