@grafema/cli 0.1.1-alpha → 0.2.1-beta
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 +10 -0
- package/dist/commands/analyze.d.ts.map +1 -1
- package/dist/commands/analyze.js +69 -11
- package/dist/commands/check.d.ts +6 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +177 -1
- package/dist/commands/coverage.d.ts.map +1 -1
- package/dist/commands/coverage.js +7 -0
- package/dist/commands/doctor/checks.d.ts +55 -0
- package/dist/commands/doctor/checks.d.ts.map +1 -0
- package/dist/commands/doctor/checks.js +534 -0
- package/dist/commands/doctor/output.d.ts +20 -0
- package/dist/commands/doctor/output.d.ts.map +1 -0
- package/dist/commands/doctor/output.js +94 -0
- package/dist/commands/doctor/types.d.ts +42 -0
- package/dist/commands/doctor/types.d.ts.map +1 -0
- package/dist/commands/doctor/types.js +4 -0
- package/dist/commands/doctor.d.ts +17 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +80 -0
- package/dist/commands/explain.d.ts +16 -0
- package/dist/commands/explain.d.ts.map +1 -0
- package/dist/commands/explain.js +145 -0
- package/dist/commands/explore.d.ts +7 -1
- package/dist/commands/explore.d.ts.map +1 -1
- package/dist/commands/explore.js +204 -85
- package/dist/commands/get.d.ts.map +1 -1
- package/dist/commands/get.js +16 -4
- package/dist/commands/impact.d.ts.map +1 -1
- package/dist/commands/impact.js +48 -50
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +93 -15
- package/dist/commands/ls.d.ts +14 -0
- package/dist/commands/ls.d.ts.map +1 -0
- package/dist/commands/ls.js +132 -0
- package/dist/commands/overview.d.ts.map +1 -1
- package/dist/commands/overview.js +15 -2
- package/dist/commands/query.d.ts +98 -0
- package/dist/commands/query.d.ts.map +1 -1
- package/dist/commands/query.js +549 -136
- package/dist/commands/schema.d.ts +13 -0
- package/dist/commands/schema.d.ts.map +1 -0
- package/dist/commands/schema.js +279 -0
- package/dist/commands/server.d.ts.map +1 -1
- package/dist/commands/server.js +13 -6
- package/dist/commands/stats.d.ts.map +1 -1
- package/dist/commands/stats.js +7 -0
- package/dist/commands/trace.d.ts +73 -0
- package/dist/commands/trace.d.ts.map +1 -1
- package/dist/commands/trace.js +500 -5
- package/dist/commands/types.d.ts +12 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +79 -0
- package/dist/utils/formatNode.d.ts +13 -0
- package/dist/utils/formatNode.d.ts.map +1 -1
- package/dist/utils/formatNode.js +35 -2
- package/package.json +3 -3
- package/src/cli.ts +10 -0
- package/src/commands/analyze.ts +84 -9
- package/src/commands/check.ts +201 -0
- package/src/commands/coverage.ts +7 -0
- package/src/commands/doctor/checks.ts +612 -0
- package/src/commands/doctor/output.ts +115 -0
- package/src/commands/doctor/types.ts +45 -0
- package/src/commands/doctor.ts +106 -0
- package/src/commands/explain.ts +173 -0
- package/src/commands/explore.tsx +247 -97
- package/src/commands/get.ts +20 -6
- package/src/commands/impact.ts +55 -61
- package/src/commands/init.ts +101 -14
- package/src/commands/ls.ts +166 -0
- package/src/commands/overview.ts +15 -2
- package/src/commands/query.ts +643 -149
- package/src/commands/schema.ts +345 -0
- package/src/commands/server.ts +13 -6
- package/src/commands/stats.ts +7 -0
- package/src/commands/trace.ts +647 -6
- package/src/commands/types.ts +94 -0
- package/src/utils/formatNode.ts +42 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema command - Export code schemas
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* grafema schema export --interface ConfigSchema
|
|
6
|
+
* grafema schema export --interface ConfigSchema --format yaml
|
|
7
|
+
* grafema schema export --interface ConfigSchema --file src/config/types.ts
|
|
8
|
+
* grafema schema export --graph
|
|
9
|
+
* grafema schema export --graph --format yaml
|
|
10
|
+
*/
|
|
11
|
+
import { Command } from 'commander';
|
|
12
|
+
export declare const schemaCommand: Command;
|
|
13
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/commands/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2UpC,eAAO,MAAM,aAAa,SAEK,CAAC"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema command - Export code schemas
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* grafema schema export --interface ConfigSchema
|
|
6
|
+
* grafema schema export --interface ConfigSchema --format yaml
|
|
7
|
+
* grafema schema export --interface ConfigSchema --file src/config/types.ts
|
|
8
|
+
* grafema schema export --graph
|
|
9
|
+
* grafema schema export --graph --format yaml
|
|
10
|
+
*/
|
|
11
|
+
import { Command } from 'commander';
|
|
12
|
+
import { resolve, join, relative } from 'path';
|
|
13
|
+
import { existsSync, writeFileSync } from 'fs';
|
|
14
|
+
import { RFDBServerBackend, InterfaceSchemaExtractor, GraphSchemaExtractor, } from '@grafema/core';
|
|
15
|
+
import { exitWithError } from '../utils/errorFormatter.js';
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Interface Schema Formatters
|
|
18
|
+
// ============================================================================
|
|
19
|
+
function formatInterfaceJson(schema) {
|
|
20
|
+
return JSON.stringify(schema, null, 2);
|
|
21
|
+
}
|
|
22
|
+
function formatInterfaceYaml(schema) {
|
|
23
|
+
const lines = [];
|
|
24
|
+
lines.push(`$schema: ${schema.$schema}`);
|
|
25
|
+
lines.push(`name: ${schema.name}`);
|
|
26
|
+
lines.push('source:');
|
|
27
|
+
lines.push(` file: ${schema.source.file}`);
|
|
28
|
+
lines.push(` line: ${schema.source.line}`);
|
|
29
|
+
lines.push(` column: ${schema.source.column}`);
|
|
30
|
+
if (schema.typeParameters && schema.typeParameters.length > 0) {
|
|
31
|
+
lines.push('typeParameters:');
|
|
32
|
+
for (const param of schema.typeParameters) {
|
|
33
|
+
lines.push(` - "${param}"`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lines.push('properties:');
|
|
37
|
+
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
38
|
+
lines.push(` ${name}:`);
|
|
39
|
+
lines.push(` type: "${prop.type}"`);
|
|
40
|
+
lines.push(` required: ${prop.required}`);
|
|
41
|
+
lines.push(` readonly: ${prop.readonly}`);
|
|
42
|
+
}
|
|
43
|
+
if (schema.extends.length > 0) {
|
|
44
|
+
lines.push('extends:');
|
|
45
|
+
for (const ext of schema.extends) {
|
|
46
|
+
lines.push(` - ${ext}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
lines.push('extends: []');
|
|
51
|
+
}
|
|
52
|
+
lines.push(`checksum: ${schema.checksum}`);
|
|
53
|
+
return lines.join('\n');
|
|
54
|
+
}
|
|
55
|
+
function formatInterfaceMarkdown(schema, projectPath) {
|
|
56
|
+
const lines = [];
|
|
57
|
+
const relPath = relative(projectPath, schema.source.file);
|
|
58
|
+
lines.push(`# Interface: ${schema.name}`);
|
|
59
|
+
lines.push('');
|
|
60
|
+
if (schema.typeParameters && schema.typeParameters.length > 0) {
|
|
61
|
+
lines.push(`**Type Parameters:** \`<${schema.typeParameters.join(', ')}>\``);
|
|
62
|
+
lines.push('');
|
|
63
|
+
}
|
|
64
|
+
lines.push(`**Source:** \`${relPath}:${schema.source.line}\``);
|
|
65
|
+
lines.push('');
|
|
66
|
+
if (schema.extends.length > 0) {
|
|
67
|
+
lines.push(`**Extends:** ${schema.extends.map(e => `\`${e}\``).join(', ')}`);
|
|
68
|
+
lines.push('');
|
|
69
|
+
}
|
|
70
|
+
lines.push('## Properties');
|
|
71
|
+
lines.push('');
|
|
72
|
+
lines.push('| Name | Type | Required | Readonly |');
|
|
73
|
+
lines.push('|------|------|----------|----------|');
|
|
74
|
+
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
75
|
+
const required = prop.required ? 'Yes' : 'No';
|
|
76
|
+
const readonly = prop.readonly ? 'Yes' : 'No';
|
|
77
|
+
lines.push(`| \`${name}\` | \`${prop.type}\` | ${required} | ${readonly} |`);
|
|
78
|
+
}
|
|
79
|
+
lines.push('');
|
|
80
|
+
lines.push('---');
|
|
81
|
+
lines.push('');
|
|
82
|
+
lines.push(`*Checksum: \`${schema.checksum}\`*`);
|
|
83
|
+
return lines.join('\n');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if schema has method properties (type='function')
|
|
87
|
+
* Used to show Phase 1 limitation warning
|
|
88
|
+
*/
|
|
89
|
+
function hasMethodProperties(schema) {
|
|
90
|
+
return Object.values(schema.properties).some(p => p.type === 'function');
|
|
91
|
+
}
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// Graph Schema Formatters
|
|
94
|
+
// ============================================================================
|
|
95
|
+
function formatGraphJson(schema) {
|
|
96
|
+
return JSON.stringify(schema, null, 2);
|
|
97
|
+
}
|
|
98
|
+
function formatGraphYaml(schema) {
|
|
99
|
+
const lines = [];
|
|
100
|
+
lines.push(`$schema: ${schema.$schema}`);
|
|
101
|
+
lines.push(`extractedAt: ${schema.extractedAt}`);
|
|
102
|
+
lines.push('');
|
|
103
|
+
lines.push('statistics:');
|
|
104
|
+
lines.push(` totalNodes: ${schema.statistics.totalNodes}`);
|
|
105
|
+
lines.push(` totalEdges: ${schema.statistics.totalEdges}`);
|
|
106
|
+
lines.push(` nodeTypeCount: ${schema.statistics.nodeTypeCount}`);
|
|
107
|
+
lines.push(` edgeTypeCount: ${schema.statistics.edgeTypeCount}`);
|
|
108
|
+
lines.push('');
|
|
109
|
+
lines.push('nodeTypes:');
|
|
110
|
+
for (const [type, info] of Object.entries(schema.nodeTypes)) {
|
|
111
|
+
if (info.count > 0) {
|
|
112
|
+
lines.push(` ${type}:`);
|
|
113
|
+
lines.push(` category: ${info.category}`);
|
|
114
|
+
if (info.namespace) {
|
|
115
|
+
lines.push(` namespace: ${info.namespace}`);
|
|
116
|
+
}
|
|
117
|
+
lines.push(` count: ${info.count}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
lines.push('');
|
|
121
|
+
lines.push('edgeTypes:');
|
|
122
|
+
for (const [type, info] of Object.entries(schema.edgeTypes)) {
|
|
123
|
+
if (info.count > 0) {
|
|
124
|
+
lines.push(` ${type}:`);
|
|
125
|
+
lines.push(` count: ${info.count}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
lines.push('');
|
|
129
|
+
lines.push(`checksum: ${schema.checksum}`);
|
|
130
|
+
return lines.join('\n');
|
|
131
|
+
}
|
|
132
|
+
function formatGraphMarkdown(schema) {
|
|
133
|
+
const lines = [];
|
|
134
|
+
lines.push('# Graph Schema');
|
|
135
|
+
lines.push('');
|
|
136
|
+
lines.push(`**Extracted:** ${schema.extractedAt}`);
|
|
137
|
+
lines.push('');
|
|
138
|
+
lines.push('## Statistics');
|
|
139
|
+
lines.push('');
|
|
140
|
+
lines.push(`- Total Nodes: ${schema.statistics.totalNodes}`);
|
|
141
|
+
lines.push(`- Total Edges: ${schema.statistics.totalEdges}`);
|
|
142
|
+
lines.push(`- Node Types: ${schema.statistics.nodeTypeCount}`);
|
|
143
|
+
lines.push(`- Edge Types: ${schema.statistics.edgeTypeCount}`);
|
|
144
|
+
lines.push('');
|
|
145
|
+
lines.push('## Node Types');
|
|
146
|
+
lines.push('');
|
|
147
|
+
lines.push('| Type | Category | Count |');
|
|
148
|
+
lines.push('|------|----------|-------|');
|
|
149
|
+
for (const [type, info] of Object.entries(schema.nodeTypes)) {
|
|
150
|
+
if (info.count > 0) {
|
|
151
|
+
const cat = info.namespace ? `${info.category} (${info.namespace})` : info.category;
|
|
152
|
+
lines.push(`| \`${type}\` | ${cat} | ${info.count} |`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
lines.push('');
|
|
156
|
+
lines.push('## Edge Types');
|
|
157
|
+
lines.push('');
|
|
158
|
+
lines.push('| Type | Count |');
|
|
159
|
+
lines.push('|------|-------|');
|
|
160
|
+
for (const [type, info] of Object.entries(schema.edgeTypes)) {
|
|
161
|
+
if (info.count > 0) {
|
|
162
|
+
lines.push(`| \`${type}\` | ${info.count} |`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
lines.push('');
|
|
166
|
+
lines.push('---');
|
|
167
|
+
lines.push('');
|
|
168
|
+
lines.push(`*Checksum: \`${schema.checksum}\`*`);
|
|
169
|
+
return lines.join('\n');
|
|
170
|
+
}
|
|
171
|
+
// ============================================================================
|
|
172
|
+
// Command
|
|
173
|
+
// ============================================================================
|
|
174
|
+
const exportSubcommand = new Command('export')
|
|
175
|
+
.description('Export interface or graph schema')
|
|
176
|
+
.option('--interface <name>', 'Interface name to export')
|
|
177
|
+
.option('--graph', 'Export graph node/edge type schema')
|
|
178
|
+
.option('--all', 'Include all defined types, not just used ones (with --graph)')
|
|
179
|
+
.option('--file <path>', 'File path filter (for multiple interfaces with same name)')
|
|
180
|
+
.option('-f, --format <type>', 'Output format: json, yaml, markdown', 'json')
|
|
181
|
+
.option('-p, --project <path>', 'Project path', '.')
|
|
182
|
+
.option('-o, --output <file>', 'Output file (default: stdout)')
|
|
183
|
+
.action(async (options) => {
|
|
184
|
+
// Validate: must have either --interface or --graph
|
|
185
|
+
if (!options.interface && !options.graph) {
|
|
186
|
+
exitWithError('Must specify either --interface <name> or --graph', [
|
|
187
|
+
'Examples:',
|
|
188
|
+
' grafema schema export --interface ConfigSchema',
|
|
189
|
+
' grafema schema export --graph',
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
if (options.interface && options.graph) {
|
|
193
|
+
exitWithError('Cannot specify both --interface and --graph', [
|
|
194
|
+
'Use one at a time.',
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
const projectPath = resolve(options.project);
|
|
198
|
+
const grafemaDir = join(projectPath, '.grafema');
|
|
199
|
+
const dbPath = join(grafemaDir, 'graph.rfdb');
|
|
200
|
+
if (!existsSync(dbPath)) {
|
|
201
|
+
exitWithError('No graph database found', ['Run: grafema analyze']);
|
|
202
|
+
}
|
|
203
|
+
const backend = new RFDBServerBackend({ dbPath });
|
|
204
|
+
await backend.connect();
|
|
205
|
+
try {
|
|
206
|
+
if (options.graph) {
|
|
207
|
+
// Graph schema export
|
|
208
|
+
const extractor = new GraphSchemaExtractor(backend);
|
|
209
|
+
const schema = await extractor.extract({ includeAll: options.all });
|
|
210
|
+
let output;
|
|
211
|
+
switch (options.format) {
|
|
212
|
+
case 'yaml':
|
|
213
|
+
output = formatGraphYaml(schema);
|
|
214
|
+
break;
|
|
215
|
+
case 'markdown':
|
|
216
|
+
output = formatGraphMarkdown(schema);
|
|
217
|
+
break;
|
|
218
|
+
case 'json':
|
|
219
|
+
default:
|
|
220
|
+
output = formatGraphJson(schema);
|
|
221
|
+
}
|
|
222
|
+
if (options.output) {
|
|
223
|
+
writeFileSync(resolve(options.output), output + '\n');
|
|
224
|
+
console.log(`Graph schema written to ${options.output}`);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
console.log(output);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
// Interface schema export
|
|
232
|
+
const extractor = new InterfaceSchemaExtractor(backend);
|
|
233
|
+
const schema = await extractor.extract(options.interface, {
|
|
234
|
+
file: options.file,
|
|
235
|
+
});
|
|
236
|
+
if (!schema) {
|
|
237
|
+
exitWithError(`Interface not found: ${options.interface}`, [
|
|
238
|
+
'Use "grafema query interface <name>" to search',
|
|
239
|
+
]);
|
|
240
|
+
}
|
|
241
|
+
// Phase 1 limitation warning for methods
|
|
242
|
+
if (hasMethodProperties(schema)) {
|
|
243
|
+
console.warn('Note: Method signatures are shown as "function" type. ' +
|
|
244
|
+
'Full signatures planned for v2.');
|
|
245
|
+
}
|
|
246
|
+
let output;
|
|
247
|
+
switch (options.format) {
|
|
248
|
+
case 'yaml':
|
|
249
|
+
output = formatInterfaceYaml(schema);
|
|
250
|
+
break;
|
|
251
|
+
case 'markdown':
|
|
252
|
+
output = formatInterfaceMarkdown(schema, projectPath);
|
|
253
|
+
break;
|
|
254
|
+
case 'json':
|
|
255
|
+
default:
|
|
256
|
+
output = formatInterfaceJson(schema);
|
|
257
|
+
}
|
|
258
|
+
if (options.output) {
|
|
259
|
+
writeFileSync(resolve(options.output), output + '\n');
|
|
260
|
+
console.log(`Schema written to ${options.output}`);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
console.log(output);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (error instanceof Error) {
|
|
269
|
+
exitWithError(error.message);
|
|
270
|
+
}
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
await backend.close();
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
export const schemaCommand = new Command('schema')
|
|
278
|
+
.description('Extract and manage code schemas')
|
|
279
|
+
.addCommand(exportSubcommand);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+FpC,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+FpC,eAAO,MAAM,aAAa,SAQxB,CAAC"}
|
package/dist/commands/server.js
CHANGED
|
@@ -19,8 +19,8 @@ const __dirname = dirname(__filename);
|
|
|
19
19
|
/**
|
|
20
20
|
* Find RFDB server binary in order of preference:
|
|
21
21
|
* 1. @grafema/rfdb npm package
|
|
22
|
-
* 2.
|
|
23
|
-
* 3.
|
|
22
|
+
* 2. packages/rfdb-server/target/release (monorepo development)
|
|
23
|
+
* 3. packages/rfdb-server/target/debug
|
|
24
24
|
*/
|
|
25
25
|
function findServerBinary() {
|
|
26
26
|
// 1. Check @grafema/rfdb npm package
|
|
@@ -47,15 +47,15 @@ function findServerBinary() {
|
|
|
47
47
|
catch {
|
|
48
48
|
// @grafema/rfdb not installed
|
|
49
49
|
}
|
|
50
|
-
// 2. Check
|
|
50
|
+
// 2. Check packages/rfdb-server in monorepo
|
|
51
51
|
// From packages/cli/dist/commands -> project root is 4 levels up
|
|
52
52
|
const projectRoot = join(__dirname, '../../../..');
|
|
53
|
-
const releaseBinary = join(projectRoot, '
|
|
53
|
+
const releaseBinary = join(projectRoot, 'packages/rfdb-server/target/release/rfdb-server');
|
|
54
54
|
if (existsSync(releaseBinary)) {
|
|
55
55
|
return releaseBinary;
|
|
56
56
|
}
|
|
57
57
|
// 3. Check debug build
|
|
58
|
-
const debugBinary = join(projectRoot, '
|
|
58
|
+
const debugBinary = join(projectRoot, 'packages/rfdb-server/target/debug/rfdb-server');
|
|
59
59
|
if (existsSync(debugBinary)) {
|
|
60
60
|
return debugBinary;
|
|
61
61
|
}
|
|
@@ -94,7 +94,14 @@ function getProjectPaths(projectPath) {
|
|
|
94
94
|
}
|
|
95
95
|
// Create main server command with subcommands
|
|
96
96
|
export const serverCommand = new Command('server')
|
|
97
|
-
.description('Manage RFDB server lifecycle')
|
|
97
|
+
.description('Manage RFDB server lifecycle')
|
|
98
|
+
.addHelpText('after', `
|
|
99
|
+
Examples:
|
|
100
|
+
grafema server start Start the RFDB server (detached)
|
|
101
|
+
grafema server stop Stop the running server
|
|
102
|
+
grafema server status Check if server is running
|
|
103
|
+
grafema server status --json Server status as JSON
|
|
104
|
+
`);
|
|
98
105
|
// grafema server start
|
|
99
106
|
serverCommand
|
|
100
107
|
.command('start')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,eAAO,MAAM,YAAY,SAsDrB,CAAC"}
|
package/dist/commands/stats.js
CHANGED
|
@@ -11,6 +11,13 @@ export const statsCommand = new Command('stats')
|
|
|
11
11
|
.option('-p, --project <path>', 'Project path', '.')
|
|
12
12
|
.option('-j, --json', 'Output as JSON')
|
|
13
13
|
.option('-t, --types', 'Show breakdown by type')
|
|
14
|
+
.addHelpText('after', `
|
|
15
|
+
Examples:
|
|
16
|
+
grafema stats Show basic graph statistics
|
|
17
|
+
grafema stats --types Show breakdown by node/edge types
|
|
18
|
+
grafema stats --json Output statistics as JSON
|
|
19
|
+
grafema stats -p ./app Statistics for specific project
|
|
20
|
+
`)
|
|
14
21
|
.action(async (options) => {
|
|
15
22
|
const projectPath = resolve(options.project);
|
|
16
23
|
const grafemaDir = join(projectPath, '.grafema');
|
package/dist/commands/trace.d.ts
CHANGED
|
@@ -4,7 +4,80 @@
|
|
|
4
4
|
* Usage:
|
|
5
5
|
* grafema trace "userId from authenticate"
|
|
6
6
|
* grafema trace "config"
|
|
7
|
+
* grafema trace --to "addNode#0.type" (sink-based trace)
|
|
7
8
|
*/
|
|
8
9
|
import { Command } from 'commander';
|
|
10
|
+
import { RFDBServerBackend, type ValueSource } from '@grafema/core';
|
|
11
|
+
/**
|
|
12
|
+
* Parsed sink specification from "fn#0.property.path" format
|
|
13
|
+
*/
|
|
14
|
+
export interface SinkSpec {
|
|
15
|
+
functionName: string;
|
|
16
|
+
argIndex: number;
|
|
17
|
+
propertyPath: string[];
|
|
18
|
+
raw: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Information about a call site
|
|
22
|
+
*/
|
|
23
|
+
export interface CallSiteInfo {
|
|
24
|
+
id: string;
|
|
25
|
+
calleeFunction: string;
|
|
26
|
+
file: string;
|
|
27
|
+
line: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Result of sink resolution
|
|
31
|
+
*/
|
|
32
|
+
export interface SinkResolutionResult {
|
|
33
|
+
sink: SinkSpec;
|
|
34
|
+
resolvedCallSites: CallSiteInfo[];
|
|
35
|
+
possibleValues: Array<{
|
|
36
|
+
value: unknown;
|
|
37
|
+
sources: ValueSource[];
|
|
38
|
+
}>;
|
|
39
|
+
statistics: {
|
|
40
|
+
callSites: number;
|
|
41
|
+
totalSources: number;
|
|
42
|
+
uniqueValues: number;
|
|
43
|
+
unknownElements: boolean;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
9
46
|
export declare const traceCommand: Command;
|
|
47
|
+
/**
|
|
48
|
+
* Parse sink specification string into structured format
|
|
49
|
+
*
|
|
50
|
+
* Format: "functionName#argIndex.property.path"
|
|
51
|
+
* Examples:
|
|
52
|
+
* - "addNode#0.type" -> {functionName: "addNode", argIndex: 0, propertyPath: ["type"]}
|
|
53
|
+
* - "fn#0" -> {functionName: "fn", argIndex: 0, propertyPath: []}
|
|
54
|
+
* - "add_node_v2#1.config.options" -> {functionName: "add_node_v2", argIndex: 1, propertyPath: ["config", "options"]}
|
|
55
|
+
*
|
|
56
|
+
* @throws Error if spec is invalid
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseSinkSpec(spec: string): SinkSpec;
|
|
59
|
+
/**
|
|
60
|
+
* Find all call sites for a function by name
|
|
61
|
+
*
|
|
62
|
+
* Handles both:
|
|
63
|
+
* - Direct calls: fn() where name === targetFunctionName
|
|
64
|
+
* - Method calls: obj.fn() where method attribute === targetFunctionName
|
|
65
|
+
*/
|
|
66
|
+
export declare function findCallSites(backend: RFDBServerBackend, targetFunctionName: string): Promise<CallSiteInfo[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Extract the argument node ID at a specific index from a call site
|
|
69
|
+
*
|
|
70
|
+
* Follows PASSES_ARGUMENT edges and matches by argIndex metadata
|
|
71
|
+
*
|
|
72
|
+
* @returns Node ID of the argument, or null if not found
|
|
73
|
+
*/
|
|
74
|
+
export declare function extractArgument(backend: RFDBServerBackend, callSiteId: string, argIndex: number): Promise<string | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Resolve a sink specification to all possible values
|
|
77
|
+
*
|
|
78
|
+
* This is the main entry point for sink-based trace.
|
|
79
|
+
* It finds all call sites, extracts the specified argument,
|
|
80
|
+
* optionally follows property path, and traces to literal values.
|
|
81
|
+
*/
|
|
82
|
+
export declare function resolveSink(backend: RFDBServerBackend, sink: SinkSpec): Promise<SinkResolutionResult>;
|
|
10
83
|
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/commands/trace.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/commands/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,iBAAiB,EAAgC,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAgBlG;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,QAAQ,CAAC;IACf,iBAAiB,EAAE,YAAY,EAAE,CAAC;IAClC,cAAc,EAAE,KAAK,CAAC;QACpB,KAAK,EAAE,OAAO,CAAC;QACf,OAAO,EAAE,WAAW,EAAE,CAAC;KACxB,CAAC,CAAC;IACH,UAAU,EAAE;QACV,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,OAAO,CAAC;KAC1B,CAAC;CACH;AAiBD,eAAO,MAAM,YAAY,SAqHrB,CAAC;AAsOL;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAiDpD;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,iBAAiB,EAC1B,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,YAAY,EAAE,CAAC,CAoBzB;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,iBAAiB,EAC1B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYxB;AAyED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,oBAAoB,CAAC,CAuE/B"}
|