@secondlayer/cli 14.3.1 → 15.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 +9 -17
- package/dist/cli.js +1532 -4005
- package/dist/cli.js.map +17 -29
- package/dist/index.d.ts +26 -237
- package/dist/index.js +127 -335
- package/dist/index.js.map +7 -8
- package/package.json +9 -14
- package/dist/core/plugin-manager.d.ts +0 -268
- package/dist/core/plugin-manager.js +0 -396
- package/dist/core/plugin-manager.js.map +0 -13
- package/dist/plugins/index.d.ts +0 -338
- package/dist/plugins/index.js +0 -1755
- package/dist/plugins/index.js.map +0 -26
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { AbiContract as AbiContract2 } from "@secondlayer/stacks/clarity";
|
|
2
|
-
|
|
2
|
+
interface ClarinetOptions {
|
|
3
|
+
/** Path to Clarinet.toml file */
|
|
4
|
+
path?: string;
|
|
5
|
+
/** Include only specific contracts */
|
|
6
|
+
include?: string[];
|
|
7
|
+
/** Exclude specific contracts */
|
|
8
|
+
exclude?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Also generate interfaces for dependency contracts declared under
|
|
11
|
+
* `[project.requirements]` in Clarinet.toml (default: true).
|
|
12
|
+
*/
|
|
13
|
+
includeRequirements?: boolean;
|
|
14
|
+
/** Enable debug output */
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}
|
|
3
17
|
/** Supported Stacks network identifiers for contract resolution. */
|
|
4
18
|
type NetworkName = "mainnet" | "testnet" | "devnet";
|
|
5
19
|
/** Specifies a contract to generate typed interfaces for, either from a deployed address or local Clarity source file. */
|
|
@@ -16,11 +30,15 @@ interface ContractSource {
|
|
|
16
30
|
* Optional name to use in generated code
|
|
17
31
|
*/
|
|
18
32
|
name?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Pre-resolved ABI (from Clarinet simnet or direct input)
|
|
35
|
+
*/
|
|
36
|
+
abi?: AbiContract2;
|
|
19
37
|
}
|
|
20
|
-
/** Configuration for the `@secondlayer/cli` code generator.
|
|
38
|
+
/** Configuration for the `@secondlayer/cli` code generator. */
|
|
21
39
|
interface SecondLayerConfig {
|
|
22
40
|
/**
|
|
23
|
-
* Contracts to generate interfaces for (optional
|
|
41
|
+
* Contracts to generate interfaces for (optional — Clarinet can provide these)
|
|
24
42
|
*/
|
|
25
43
|
contracts?: ContractSource[];
|
|
26
44
|
/**
|
|
@@ -28,9 +46,11 @@ interface SecondLayerConfig {
|
|
|
28
46
|
*/
|
|
29
47
|
out: string;
|
|
30
48
|
/**
|
|
31
|
-
*
|
|
49
|
+
* Load contracts from a local Clarinet project via simnet.
|
|
50
|
+
* `true` uses defaults; pass options for path / include / exclude / requirements.
|
|
51
|
+
* Skips silently when Clarinet.toml is missing.
|
|
32
52
|
*/
|
|
33
|
-
|
|
53
|
+
clarinet?: boolean | ClarinetOptions;
|
|
34
54
|
/**
|
|
35
55
|
* Network to use for fetching contracts
|
|
36
56
|
*/
|
|
@@ -49,239 +69,8 @@ interface SecondLayerConfig {
|
|
|
49
69
|
*/
|
|
50
70
|
defaultAddress?: string;
|
|
51
71
|
}
|
|
52
|
-
interface ResolvedContract {
|
|
53
|
-
name: string;
|
|
54
|
-
address: string;
|
|
55
|
-
contractName: string;
|
|
56
|
-
abi: AbiContract;
|
|
57
|
-
source: "api" | "local";
|
|
58
|
-
}
|
|
59
72
|
type ConfigDefiner = (config: SecondLayerConfig) => SecondLayerConfig;
|
|
60
73
|
/**
|
|
61
|
-
* Core plugin interface that all plugins must implement
|
|
62
|
-
*/
|
|
63
|
-
interface SecondLayerPlugin {
|
|
64
|
-
/** Plugin name (should be unique) */
|
|
65
|
-
name: string;
|
|
66
|
-
/** Plugin version */
|
|
67
|
-
version: string;
|
|
68
|
-
/** Called after config is resolved but before generation starts */
|
|
69
|
-
configResolved?: (config: ResolvedConfig) => void | Promise<void>;
|
|
70
|
-
/** Called before generation starts */
|
|
71
|
-
beforeGenerate?: (context: GenerateContext) => void | Promise<void>;
|
|
72
|
-
/** Called during generation phase - plugins can add their own outputs */
|
|
73
|
-
generate?: (context: GenerateContext) => void | Promise<void>;
|
|
74
|
-
/** Called after all generation is complete */
|
|
75
|
-
afterGenerate?: (context: GenerateContext) => void | Promise<void>;
|
|
76
|
-
/** Transform user config before resolution */
|
|
77
|
-
transformConfig?: (config: UserConfig) => UserConfig | Promise<UserConfig>;
|
|
78
|
-
/** Transform individual contracts during processing */
|
|
79
|
-
transformContract?: (contract: ContractConfig) => ContractConfig | Promise<ContractConfig>;
|
|
80
|
-
/** Transform generated output before writing to disk */
|
|
81
|
-
transformOutput?: (output: string, type: OutputType) => string | Promise<string>;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* User configuration (before plugin transformations)
|
|
85
|
-
*/
|
|
86
|
-
type UserConfig = SecondLayerConfig;
|
|
87
|
-
/**
|
|
88
|
-
* Resolved configuration (after plugin transformations)
|
|
89
|
-
*/
|
|
90
|
-
interface ResolvedConfig extends SecondLayerConfig {
|
|
91
|
-
/** Resolved plugins array */
|
|
92
|
-
plugins: SecondLayerPlugin[];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Contract configuration that can be transformed by plugins
|
|
96
|
-
*/
|
|
97
|
-
interface ContractConfig {
|
|
98
|
-
name?: string;
|
|
99
|
-
address?: string | Partial<Record<NetworkName, string>>;
|
|
100
|
-
source?: string;
|
|
101
|
-
abi?: AbiContract2;
|
|
102
|
-
metadata?: Record<string, any>;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Processed contract with resolved ABI and metadata
|
|
106
|
-
*/
|
|
107
|
-
interface ProcessedContract extends ResolvedContract {
|
|
108
|
-
/** Additional metadata added by plugins */
|
|
109
|
-
metadata?: Record<string, any>;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Generated output from plugins
|
|
113
|
-
*/
|
|
114
|
-
interface GeneratedOutput {
|
|
115
|
-
/** File path where output should be written */
|
|
116
|
-
path: string;
|
|
117
|
-
/** Generated content */
|
|
118
|
-
content: string;
|
|
119
|
-
/** Output type for transformation hooks */
|
|
120
|
-
type?: OutputType;
|
|
121
|
-
/** Whether this output should overwrite existing files */
|
|
122
|
-
overwrite?: boolean;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Types of outputs that can be generated
|
|
126
|
-
*/
|
|
127
|
-
type OutputType = "contracts" | "hooks" | "actions" | "types" | "utils" | "config" | "other";
|
|
128
|
-
/**
|
|
129
|
-
* Base context available to all plugin hooks
|
|
130
|
-
*/
|
|
131
|
-
interface PluginContext {
|
|
132
|
-
/** Resolved configuration */
|
|
133
|
-
config: ResolvedConfig;
|
|
134
|
-
/** Logger for plugin output */
|
|
135
|
-
logger: Logger;
|
|
136
|
-
/** Utility functions for plugins */
|
|
137
|
-
utils: PluginUtils;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Context available during generation phase
|
|
141
|
-
*/
|
|
142
|
-
interface GenerateContext extends PluginContext {
|
|
143
|
-
/** Processed contracts ready for generation */
|
|
144
|
-
contracts: ProcessedContract[];
|
|
145
|
-
/** Map of output keys to generated content */
|
|
146
|
-
outputs: Map<string, GeneratedOutput>;
|
|
147
|
-
/** Function to augment existing outputs */
|
|
148
|
-
augment: (outputKey: string, contractName: string, content: any) => void;
|
|
149
|
-
/** Function to add new outputs */
|
|
150
|
-
addOutput: (key: string, output: GeneratedOutput) => void;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Logger interface for plugin output
|
|
154
|
-
*/
|
|
155
|
-
interface Logger {
|
|
156
|
-
info: (message: string) => void;
|
|
157
|
-
warn: (message: string) => void;
|
|
158
|
-
error: (message: string) => void;
|
|
159
|
-
debug: (message: string) => void;
|
|
160
|
-
success: (message: string) => void;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Utility functions available to plugins
|
|
164
|
-
*/
|
|
165
|
-
interface PluginUtils {
|
|
166
|
-
/** Convert kebab-case to camelCase */
|
|
167
|
-
toCamelCase: (str: string) => string;
|
|
168
|
-
/** Convert camelCase to kebab-case */
|
|
169
|
-
toKebabCase: (str: string) => string;
|
|
170
|
-
/** Validate Stacks address format */
|
|
171
|
-
validateAddress: (address: string) => boolean;
|
|
172
|
-
/** Parse contract identifier (address.contract-name) */
|
|
173
|
-
parseContractId: (contractId: string) => {
|
|
174
|
-
address: string
|
|
175
|
-
contractName: string
|
|
176
|
-
};
|
|
177
|
-
/** Format TypeScript code using prettier */
|
|
178
|
-
formatCode: (code: string) => Promise<string>;
|
|
179
|
-
/** Resolve file path relative to project root */
|
|
180
|
-
resolvePath: (relativePath: string) => string;
|
|
181
|
-
/** Check if file exists */
|
|
182
|
-
fileExists: (path: string) => Promise<boolean>;
|
|
183
|
-
/** Read file content */
|
|
184
|
-
readFile: (path: string) => Promise<string>;
|
|
185
|
-
/** Write file content */
|
|
186
|
-
writeFile: (path: string, content: string) => Promise<void>;
|
|
187
|
-
/** Create directory recursively */
|
|
188
|
-
ensureDir: (path: string) => Promise<void>;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Plugin factory function type for creating plugins with options
|
|
192
|
-
*/
|
|
193
|
-
type PluginFactory<TOptions = any> = (options?: TOptions) => SecondLayerPlugin;
|
|
194
|
-
/**
|
|
195
|
-
* Plugin options base interface
|
|
196
|
-
*/
|
|
197
|
-
interface PluginOptions {
|
|
198
|
-
/** Include only specific contracts/functions */
|
|
199
|
-
include?: string[];
|
|
200
|
-
/** Exclude specific contracts/functions */
|
|
201
|
-
exclude?: string[];
|
|
202
|
-
/** Enable debug output */
|
|
203
|
-
debug?: boolean;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Hook execution result
|
|
207
|
-
*/
|
|
208
|
-
interface HookResult<T = any> {
|
|
209
|
-
/** Whether the hook was successful */
|
|
210
|
-
success: boolean;
|
|
211
|
-
/** Result data from the hook */
|
|
212
|
-
data?: T;
|
|
213
|
-
/** Error if hook failed */
|
|
214
|
-
error?: Error;
|
|
215
|
-
/** Plugin that executed the hook */
|
|
216
|
-
plugin: string;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Core plugin manager that orchestrates plugin execution
|
|
220
|
-
*/
|
|
221
|
-
declare class PluginManager {
|
|
222
|
-
private plugins;
|
|
223
|
-
private logger;
|
|
224
|
-
private utils;
|
|
225
|
-
private executionContext;
|
|
226
|
-
constructor();
|
|
227
|
-
/**
|
|
228
|
-
* Register a plugin
|
|
229
|
-
*/
|
|
230
|
-
register(plugin: SecondLayerPlugin): void;
|
|
231
|
-
/**
|
|
232
|
-
* Get all registered plugins
|
|
233
|
-
*/
|
|
234
|
-
getPlugins(): SecondLayerPlugin[];
|
|
235
|
-
/**
|
|
236
|
-
* Transform user config through all plugins
|
|
237
|
-
*/
|
|
238
|
-
transformConfig(config: UserConfig): Promise<ResolvedConfig>;
|
|
239
|
-
/**
|
|
240
|
-
* Transform contracts through all plugins
|
|
241
|
-
*/
|
|
242
|
-
transformContracts(contracts: ContractConfig[], _config: ResolvedConfig): Promise<ProcessedContract[]>;
|
|
243
|
-
/**
|
|
244
|
-
* Execute lifecycle hooks
|
|
245
|
-
*/
|
|
246
|
-
executeHook(hookName: keyof SecondLayerPlugin, context: any): Promise<void>;
|
|
247
|
-
/**
|
|
248
|
-
* Execute generation phase with full context
|
|
249
|
-
*/
|
|
250
|
-
executeGeneration(contracts: ProcessedContract[], config: ResolvedConfig): Promise<Map<string, GeneratedOutput>>;
|
|
251
|
-
/**
|
|
252
|
-
* Transform outputs through plugins
|
|
253
|
-
*/
|
|
254
|
-
transformOutputs(outputs: Map<string, GeneratedOutput>): Promise<Map<string, GeneratedOutput>>;
|
|
255
|
-
/**
|
|
256
|
-
* Write outputs to disk
|
|
257
|
-
*/
|
|
258
|
-
writeOutputs(outputs: Map<string, GeneratedOutput>): Promise<void>;
|
|
259
|
-
/**
|
|
260
|
-
* Get execution results for debugging
|
|
261
|
-
*/
|
|
262
|
-
getExecutionResults(): Map<string, HookResult[]>;
|
|
263
|
-
/**
|
|
264
|
-
* Convert a contract config with an ABI into a ProcessedContract
|
|
265
|
-
*/
|
|
266
|
-
private contractToProcessed;
|
|
267
|
-
/**
|
|
268
|
-
* Augment existing output with additional content
|
|
269
|
-
*/
|
|
270
|
-
private augmentOutput;
|
|
271
|
-
/**
|
|
272
|
-
* Record hook execution result
|
|
273
|
-
*/
|
|
274
|
-
private recordHookResult;
|
|
275
|
-
/**
|
|
276
|
-
* Create logger instance
|
|
277
|
-
*/
|
|
278
|
-
private createLogger;
|
|
279
|
-
/**
|
|
280
|
-
* Create utils instance
|
|
281
|
-
*/
|
|
282
|
-
private createUtils;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
74
|
* Type-safe helper for creating a `secondlayer.config.ts` configuration.
|
|
286
75
|
* Accepts either a config object or a factory function that receives a base config and returns a modified one.
|
|
287
76
|
*
|
|
@@ -298,4 +87,4 @@ declare class PluginManager {
|
|
|
298
87
|
declare function defineConfig(config: SecondLayerConfig): SecondLayerConfig;
|
|
299
88
|
declare function defineConfig(definer: ConfigDefiner): ConfigDefiner;
|
|
300
89
|
import { AbiContract as AbiContract3, AbiFunction, AbiType } from "@secondlayer/stacks/clarity";
|
|
301
|
-
export { defineConfig,
|
|
90
|
+
export { defineConfig, SecondLayerConfig, NetworkName, ContractSource, ClarinetOptions, AbiType, AbiFunction, AbiContract3 as AbiContract };
|