@nexiq/extension-sdk 1.0.3 → 1.0.4

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.
@@ -1,390 +0,0 @@
1
- import {
2
- type DatabaseData,
3
- type EffectInfo,
4
- type ReactDependency,
5
- } from "@nexiq/shared";
6
- import {
7
- type GraphComboData,
8
- type GraphArrowData,
9
- type GraphNodeData,
10
- type GraphViewResult,
11
- type GraphViewTask,
12
- } from "../index.js";
13
-
14
- export const componentTask: GraphViewTask = {
15
- id: "component-structure",
16
- priority: 10,
17
- run: (
18
- data: DatabaseData,
19
- result: GraphViewResult,
20
- batch?: Partial<DatabaseData>,
21
- ): GraphViewResult => {
22
- const combos: GraphComboData[] = [...result.combos];
23
- const nodes: GraphNodeData[] = [...result.nodes];
24
- const edges: GraphArrowData[] = [...result.edges];
25
- const typeData = { ...result.typeData };
26
-
27
- const scopes = batch?.scopes || data.scopes || [];
28
- const symbols = batch?.symbols || data.symbols || [];
29
- const relations = batch?.relations || data.relations || [];
30
- const renders = batch?.renders || data.renders || [];
31
- const files = data.files || [];
32
-
33
- const fileMap = new Map(files.map((f) => [f.id, f.path]));
34
-
35
- // Identify automatic JSX symbols and their entities to skip them and their scopes
36
- const automaticJsxEntities = new Set<string>();
37
- for (const symbol of symbols) {
38
- if (symbol.name.startsWith("jsx@")) {
39
- automaticJsxEntities.add(symbol.entity_id);
40
- }
41
- }
42
-
43
- // Build Export Map: Map<filePath, Map<exportName, symbolId>>
44
- const exportMap = new Map<string, Map<string | null, string>>();
45
- for (const exp of data.exports) {
46
- const scope = data.scopes.find((s) => s.id === exp.scope_id);
47
- if (!scope) continue;
48
- const filePath = fileMap.get(scope.file_id);
49
- if (!filePath) continue;
50
-
51
- if (!exportMap.has(filePath)) {
52
- exportMap.set(filePath, new Map());
53
- }
54
- if (exp.symbol_id) {
55
- exportMap
56
- .get(filePath)!
57
- .set(exp.is_default ? "default" : exp.name, exp.symbol_id);
58
- }
59
- }
60
-
61
- // Build Redirection Map: Map<importSymbolId, actualSymbolId>
62
- const redirectionMap = new Map<string, string>();
63
- for (const symbol of data.symbols) {
64
- const entity = data.entities.find((e) => e.id === symbol.entity_id);
65
- if (entity?.kind === "import" && entity.data_json) {
66
- try {
67
- const impData = JSON.parse(entity.data_json);
68
- const sourcePath = impData.source;
69
- const importedName =
70
- impData.type === "default" ? "default" : impData.importedName;
71
-
72
- const targetSymbolId = exportMap.get(sourcePath)?.get(importedName);
73
- if (targetSymbolId) {
74
- redirectionMap.set(symbol.id, targetSymbolId);
75
- }
76
- } catch {
77
- // ignore
78
- }
79
- }
80
- }
81
-
82
- // 1. Map Scopes to Combos
83
- for (const scope of scopes) {
84
- if (scope.kind === "module") continue;
85
- if (combos.some((c) => c.id === scope.id)) continue;
86
-
87
- // Skip scopes belonging to automatic JSX elements
88
- if (scope.entity_id && automaticJsxEntities.has(scope.entity_id))
89
- continue;
90
-
91
- const parentScope = data.scopes.find((s) => s.id === scope.parent_id);
92
- const parentComboId =
93
- parentScope && parentScope.kind !== "module"
94
- ? scope.parent_id
95
- : undefined;
96
-
97
- combos.push({
98
- id: scope.id,
99
- name: scope.kind,
100
- label: { text: scope.kind },
101
- combo: parentComboId || undefined,
102
- type: "scope",
103
- collapsed: true,
104
- });
105
- }
106
-
107
- // 2. Map Symbols to Nodes/Labels
108
- for (const symbol of symbols) {
109
- if (
110
- nodes.some((n) => n.id === symbol.id) ||
111
- combos.some((c) => c.id === symbol.id)
112
- )
113
- continue;
114
-
115
- // Skip automatic JSX symbols to avoid clutter
116
- if (symbol.name.startsWith("jsx@")) continue;
117
-
118
- const entity = data.entities.find((e) => e.id === symbol.entity_id);
119
- if (!entity) continue;
120
-
121
- // Skip imports
122
- if (entity.kind === "import") continue;
123
-
124
- // Skip state setters (index 1 of the state array) to avoid showing both state and setter as separate nodes
125
- if (entity.kind === "state" && symbol.path) {
126
- try {
127
- const pathArr = JSON.parse(symbol.path);
128
- if (
129
- Array.isArray(pathArr) &&
130
- pathArr.length > 0 &&
131
- pathArr[0] !== "0"
132
- ) {
133
- continue;
134
- }
135
- } catch {
136
- // ignore
137
- }
138
- }
139
-
140
- const scope = data.scopes.find((s) => s.id === symbol.scope_id);
141
- const file = scope ? fileMap.get(scope.file_id) : undefined;
142
-
143
- // Check if this symbol's entity has an associated scope (e.g. the body)
144
- const blockScope = data.scopes.find((s) => s.entity_id === entity.id);
145
-
146
- if (blockScope) {
147
- // This symbol represents a scope (e.g. function body)
148
- // We update the combo created for this scope
149
- const combo = combos.find((c) => c.id === blockScope.id);
150
- if (combo) {
151
- combo.label = { text: symbol.name };
152
- combo.displayName = symbol.name;
153
- combo.type = entity.kind;
154
- combo.fileName = file;
155
- combo.loc = { line: entity.line || 0, column: entity.column || 0 };
156
-
157
- // Handle effects for this component/hook
158
- if (entity.data_json) {
159
- try {
160
- const metadata = JSON.parse(entity.data_json);
161
- if (metadata.effects) {
162
- for (const effect of Object.values(
163
- metadata.effects as Record<string, EffectInfo>,
164
- )) {
165
- const effectName = (effect as EffectInfo).name || "useEffect";
166
- nodes.push({
167
- id: effect.id,
168
- name: effectName,
169
- label: { text: effectName },
170
- combo: blockScope.id,
171
- type: "effect",
172
- fileName: file,
173
- loc: { line: effect.loc.line, column: effect.loc.column },
174
- displayName: effectName,
175
- });
176
-
177
- if (effect.reactDeps) {
178
- for (const dep of effect.reactDeps as ReactDependency[]) {
179
- const targetId = redirectionMap.get(dep.id) || dep.id;
180
- if (targetId) {
181
- edges.push({
182
- id: `${targetId}-${effect.id}-effect-dep`,
183
- source: targetId,
184
- target: effect.id,
185
- label: "dependency",
186
- });
187
- }
188
- }
189
- }
190
- }
191
- }
192
- } catch {
193
- // ignore
194
- }
195
- }
196
- }
197
- } else {
198
- // Handle destructuring paths to group variables and reduce clutter
199
- let parentComboId =
200
- scope && scope.kind !== "module" ? symbol.scope_id : undefined;
201
-
202
- if (symbol.path && entity.kind !== "state") {
203
- try {
204
- const pathArr = JSON.parse(symbol.path);
205
- if (Array.isArray(pathArr) && pathArr.length >= 1) {
206
- // 1. Create a "source" combo for the entity (e.g., the hook call or variable)
207
- const sourceComboId = `${symbol.scope_id}:source:${symbol.entity_id}`;
208
- if (!combos.some((c) => c.id === sourceComboId)) {
209
- let sourceLabel = entity.name || entity.kind;
210
- if (entity.kind === "hook" && entity.data_json) {
211
- try {
212
- const meta = JSON.parse(entity.data_json);
213
- if (meta.call?.name) sourceLabel = meta.call.name;
214
- } catch {
215
- // ignore
216
- }
217
- }
218
-
219
- combos.push({
220
- id: sourceComboId,
221
- name: sourceLabel,
222
- label: { text: sourceLabel },
223
- combo: parentComboId,
224
- type: "source-group",
225
- collapsed: true,
226
- });
227
- }
228
- parentComboId = sourceComboId;
229
-
230
- // 2. Create intermediate combos for each segment of the path except the last one
231
- for (let i = 0; i < pathArr.length - 1; i++) {
232
- const segment = pathArr[i];
233
- // Use a stable ID for the path combo nested under the source combo
234
- const segmentId = `${sourceComboId}:path:${pathArr
235
- .slice(0, i + 1)
236
- .join("/")}`;
237
-
238
- if (!combos.some((c) => c.id === segmentId)) {
239
- combos.push({
240
- id: segmentId,
241
- name: segment.toString(),
242
- label: { text: segment.toString() },
243
- combo: parentComboId,
244
- type: "path-group",
245
- collapsed: true,
246
- });
247
- }
248
- parentComboId = segmentId;
249
- }
250
- }
251
- } catch {
252
- // ignore invalid path JSON
253
- }
254
- }
255
-
256
- const labelText = symbol.name;
257
-
258
- // Handle reactDeps and special labeling for hooks
259
- if (entity.data_json) {
260
- try {
261
- const metadata = JSON.parse(entity.data_json);
262
-
263
- if (metadata.reactDeps) {
264
- for (const dep of metadata.reactDeps as {
265
- id: string;
266
- name: string;
267
- }[]) {
268
- const targetId = redirectionMap.get(dep.id) || dep.id;
269
- if (targetId) {
270
- edges.push({
271
- id: `${targetId}-${symbol.id}-react-dep`,
272
- source: targetId,
273
- target: symbol.id,
274
- label: "dependency",
275
- });
276
- }
277
- }
278
- }
279
- } catch {
280
- // ignore
281
- }
282
- }
283
-
284
- nodes.push({
285
- id: symbol.id,
286
- name: symbol.name,
287
- label: { text: labelText },
288
- combo: parentComboId,
289
- type: entity.kind,
290
- fileName: file,
291
- loc: { line: entity.line || 0, column: entity.column || 0 },
292
- displayName: symbol.name,
293
- });
294
- }
295
- }
296
-
297
- // 3. Handle Renders (JSX)
298
- for (const render of renders) {
299
- if (
300
- nodes.some((n) => n.id === render.id) ||
301
- combos.some((c) => c.id === render.id)
302
- )
303
- continue;
304
-
305
- const file = fileMap.get(render.file_id);
306
- const parentScope = data.scopes.find(
307
- (s) => s.entity_id === render.parent_entity_id,
308
- );
309
-
310
- const parentCombo = parentScope?.id;
311
-
312
- // Create a "render" group combo within the parent combo if not exists
313
- let finalParentCombo = render.parent_render_id ?? parentCombo;
314
- if (parentCombo && !render.parent_render_id) {
315
- const renderGroupId = `render-group-${parentCombo}`;
316
- if (!combos.some((c) => c.id === renderGroupId)) {
317
- combos.push({
318
- id: renderGroupId,
319
- name: "render",
320
- label: { text: "render" },
321
- combo: parentCombo,
322
- type: "render-group",
323
- collapsed: true,
324
- });
325
- }
326
- finalParentCombo = renderGroupId;
327
- }
328
-
329
- const labelText = render.tag;
330
-
331
- const commonData = {
332
- id: render.id,
333
- name: render.tag,
334
- label: { text: labelText },
335
- combo: finalParentCombo,
336
- type: "render",
337
- fileName: file,
338
- loc: { line: render.line || 0, column: render.column || 0 },
339
- displayName: render.tag,
340
- };
341
-
342
- // Renders are now nodes that stack within the component combo
343
- combos.push(commonData);
344
-
345
- // Add edge for JSX hierarchy
346
- // if (render.parent_render_id) {
347
- // edges.push({
348
- // id: `${render.parent_render_id}-${render.id}-nesting`,
349
- // source: render.parent_render_id,
350
- // target: render.id,
351
- // label: "nesting",
352
- // });
353
- // }
354
-
355
- // if (render.symbol_id) {
356
- // const targetId =
357
- // redirectionMap.get(render.symbol_id) || render.symbol_id;
358
- // edges.push({
359
- // id: `${render.id}-${targetId}`,
360
- // source: render.id,
361
- // target: targetId,
362
- // label: "reference",
363
- // });
364
- // }
365
- }
366
-
367
- // 4. Handle Relations (Edges)
368
- for (const rel of relations) {
369
- const sourceId = redirectionMap.get(rel.from_id) || rel.from_id;
370
- const targetId = redirectionMap.get(rel.to_id) || rel.to_id;
371
- const edgeId = `${sourceId}-${targetId}-${rel.kind}`;
372
- if (edges.some((e) => e.id === edgeId)) continue;
373
-
374
- edges.push({
375
- id: edgeId,
376
- source: sourceId,
377
- target: targetId,
378
- label: rel.kind,
379
- });
380
- }
381
-
382
- return {
383
- ...result,
384
- nodes,
385
- combos,
386
- edges,
387
- typeData,
388
- };
389
- },
390
- };
@@ -1,83 +0,0 @@
1
- import { type DatabaseData } from "@nexiq/shared";
2
- import {
3
- type GraphComboData,
4
- type GraphNodeData,
5
- type GraphViewResult,
6
- type GraphViewTask,
7
- } from "../index.js";
8
-
9
- /**
10
- * Task that applies Git status (added, modified, deleted) to nodes and combos.
11
- * This runs after the base graph has been generated.
12
- */
13
- export const gitTask: GraphViewTask = {
14
- id: "git-status",
15
- priority: 100, // Run late to ensure all nodes/combos are present
16
- run: (graphData: DatabaseData, result: GraphViewResult): GraphViewResult => {
17
- const { added = [], modified = [], deleted = [] } = graphData.diff || {};
18
-
19
- // Skip if no diff data
20
- if (added.length === 0 && modified.length === 0 && deleted.length === 0) {
21
- return result;
22
- }
23
-
24
- const combos = [...result.combos];
25
- const nodes = [...result.nodes];
26
-
27
- const applyStatus = (item: GraphComboData | GraphNodeData) => {
28
- // Find the base ID for mapping (e.g., stripping '-render-instanceId')
29
- let baseId = item.id;
30
- if (item.id.includes("-render-")) {
31
- baseId = item.id.split("-render-")[0]!;
32
- } else if (item.id.includes("-props")) {
33
- baseId = item.id.split("-props")[0]!;
34
- } else if (item.id.includes(":")) {
35
- // Handle virtual variables (parent:id)
36
- baseId = item.id.split(":")[0]!;
37
- }
38
-
39
- if (added.includes(item.id) || added.includes(baseId)) {
40
- item.gitStatus = "added";
41
- } else if (modified.includes(item.id) || modified.includes(baseId)) {
42
- item.gitStatus = "modified";
43
- } else if (deleted.includes(item.id) || deleted.includes(baseId)) {
44
- item.gitStatus = "deleted";
45
- }
46
- };
47
-
48
- nodes.forEach(applyStatus);
49
- combos.forEach(applyStatus);
50
-
51
- // Aggregate statuses for specialized combos (like 'props')
52
- combos.forEach((combo) => {
53
- if (combo.id.endsWith("-props")) {
54
- const childStatuses = [
55
- ...nodes
56
- .filter((n) => n.combo === combo.id)
57
- .map((n) => n.gitStatus),
58
- ...combos
59
- .filter((c) => c.combo === combo.id)
60
- .map((c) => c.gitStatus),
61
- ].filter(Boolean);
62
-
63
- if (childStatuses.length > 0) {
64
- const unique = new Set(childStatuses);
65
- if (unique.size === 1) {
66
- combo.gitStatus = childStatuses[0] as
67
- | "added"
68
- | "modified"
69
- | "deleted";
70
- } else {
71
- combo.gitStatus = "modified";
72
- }
73
- }
74
- }
75
- });
76
-
77
- return {
78
- ...result,
79
- nodes,
80
- combos,
81
- };
82
- },
83
- };