@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,572 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { componentTask } from "./componentTask.js";
3
- import { type DatabaseData, type GraphViewResult } from "../index.js";
4
-
5
- describe("componentTask", () => {
6
- const mockData: DatabaseData = {
7
- files: [
8
- {
9
- id: 1,
10
- path: "/src/App.tsx",
11
- hash: "1",
12
- fingerprint: "1",
13
- default_export: null,
14
- star_exports_json: null,
15
- },
16
- {
17
- id: 2,
18
- path: "/src/Comp.tsx",
19
- hash: "2",
20
- fingerprint: "2",
21
- default_export: null,
22
- star_exports_json: null,
23
- },
24
- ],
25
- entities: [
26
- {
27
- id: "e-comp",
28
- scope_id: "s-comp-module",
29
- kind: "component",
30
- name: "Comp",
31
- type: "function",
32
- line: 1,
33
- column: 1,
34
- end_line: 10,
35
- end_column: 1,
36
- declaration_kind: "const",
37
- data_json: null,
38
- },
39
- {
40
- id: "e-import",
41
- scope_id: "s-app-module",
42
- kind: "import",
43
- name: "Comp",
44
- type: "data",
45
- line: 1,
46
- column: 1,
47
- end_line: 1,
48
- end_column: 1,
49
- declaration_kind: null,
50
- data_json: JSON.stringify({
51
- source: "/src/Comp.tsx",
52
- importedName: "Comp",
53
- type: "named",
54
- }),
55
- },
56
- {
57
- id: "e-app",
58
- scope_id: "s-app-module",
59
- kind: "component",
60
- name: "App",
61
- type: "function",
62
- line: 5,
63
- column: 1,
64
- end_line: 15,
65
- end_column: 1,
66
- declaration_kind: "const",
67
- data_json: null,
68
- },
69
- ],
70
- scopes: [
71
- {
72
- id: "s-comp-module",
73
- file_id: 2,
74
- parent_id: null,
75
- kind: "module",
76
- entity_id: null,
77
- data_json: null,
78
- },
79
- {
80
- id: "s-comp-block",
81
- file_id: 2,
82
- parent_id: "s-comp-module",
83
- kind: "block",
84
- entity_id: "e-comp",
85
- data_json: null,
86
- },
87
- {
88
- id: "s-app-module",
89
- file_id: 1,
90
- parent_id: null,
91
- kind: "module",
92
- entity_id: null,
93
- data_json: null,
94
- },
95
- {
96
- id: "s-app-block",
97
- file_id: 1,
98
- parent_id: "s-app-module",
99
- kind: "block",
100
- entity_id: "e-app",
101
- data_json: null,
102
- },
103
- ],
104
- symbols: [
105
- {
106
- id: "sym-comp",
107
- entity_id: "e-comp",
108
- scope_id: "s-comp-module",
109
- name: "Comp",
110
- path: null,
111
- is_alias: 0,
112
- has_default: 0,
113
- data_json: null,
114
- },
115
- {
116
- id: "sym-import",
117
- entity_id: "e-import",
118
- scope_id: "s-app-module",
119
- name: "Comp",
120
- path: null,
121
- is_alias: 0,
122
- has_default: 0,
123
- data_json: null,
124
- },
125
- {
126
- id: "sym-app",
127
- entity_id: "e-app",
128
- scope_id: "s-app-module",
129
- name: "App",
130
- path: null,
131
- is_alias: 0,
132
- has_default: 0,
133
- data_json: null,
134
- },
135
- ],
136
- renders: [
137
- {
138
- id: "r-1",
139
- file_id: 1,
140
- parent_entity_id: "e-app",
141
- parent_render_id: null,
142
- render_index: 0,
143
- tag: "Comp",
144
- symbol_id: "sym-import",
145
- line: 10,
146
- column: 5,
147
- kind: "jsx",
148
- data_json: null,
149
- },
150
- {
151
- id: "r-2",
152
- file_id: 1,
153
- parent_entity_id: "e-app",
154
- parent_render_id: "r-1",
155
- render_index: 0,
156
- tag: "div",
157
- symbol_id: null,
158
- line: 11,
159
- column: 10,
160
- kind: "jsx",
161
- data_json: null,
162
- },
163
- ],
164
- exports: [
165
- {
166
- id: "exp-1",
167
- scope_id: "s-comp-module",
168
- symbol_id: "sym-comp",
169
- entity_id: "e-comp",
170
- name: "Comp",
171
- is_default: 0,
172
- },
173
- ],
174
- relations: [
175
- {
176
- from_id: "sym-app",
177
- to_id: "sym-import",
178
- kind: "usage",
179
- line: 10,
180
- column: 5,
181
- data_json: null,
182
- },
183
- ],
184
- };
185
-
186
- const initialResult: GraphViewResult = {
187
- nodes: [],
188
- combos: [],
189
- edges: [],
190
- typeData: {},
191
- };
192
-
193
- it("should skip automatic JSX symbols and their scopes", () => {
194
- const dataWithJsx = {
195
- ...mockData,
196
- symbols: [
197
- ...mockData.symbols,
198
- {
199
- id: "sym-jsx",
200
- entity_id: "e-jsx",
201
- scope_id: "s-app-block",
202
- name: "jsx@8:4",
203
- path: null,
204
- is_alias: 0,
205
- has_default: 0,
206
- data_json: null,
207
- },
208
- ],
209
- entities: [
210
- ...mockData.entities,
211
- {
212
- id: "e-jsx",
213
- scope_id: "s-app-block",
214
- kind: "normal",
215
- name: "jsx@8:4",
216
- type: "jsx",
217
- line: 8,
218
- column: 4,
219
- end_line: 8,
220
- end_column: 10,
221
- declaration_kind: null,
222
- data_json: null,
223
- },
224
- ],
225
- scopes: [
226
- ...mockData.scopes,
227
- {
228
- id: "s-jsx-block",
229
- file_id: 1,
230
- parent_id: "s-app-block",
231
- kind: "block",
232
- entity_id: "e-jsx",
233
- data_json: null,
234
- },
235
- ],
236
- };
237
-
238
- const result = componentTask.run(dataWithJsx, initialResult);
239
-
240
- // Verify symbol node is skipped
241
- const jsxNode = result.nodes.find((n) => n.name === "jsx@8:4");
242
- expect(jsxNode).toBeUndefined();
243
-
244
- // Verify scope combo is skipped
245
- const jsxScope = result.combos.find((c) => c.id === "s-jsx-block");
246
- expect(jsxScope).toBeUndefined();
247
- });
248
-
249
- it("should hide import nodes and redirect relations", () => {
250
- const result = componentTask.run(mockData, initialResult);
251
-
252
- // Verify import node is NOT present
253
- const importNode = result.nodes.find((n) => n.id === "sym-import");
254
- const importCombo = result.combos.find((c) => c.id === "sym-import");
255
- expect(importNode).toBeUndefined();
256
- expect(importCombo).toBeUndefined();
257
-
258
- // Verify relation is redirected from sym-app to sym-comp
259
- // Step 4 logic: const edgeId = `${sourceId}-${targetId}-${rel.kind}`;
260
- const edgeId = "sym-app-sym-comp-usage";
261
- const edge = result.edges.find((e) => e.id === edgeId);
262
- expect(edge).toBeDefined();
263
- expect(edge?.source).toBe("sym-app");
264
- expect(edge?.target).toBe("sym-comp");
265
- });
266
-
267
- it("should use tag name for top-level JSX label and stack correctly", () => {
268
- const result = componentTask.run(mockData, initialResult);
269
-
270
- const renderGroup = result.combos.find(
271
- (c) => c.id === "render-group-s-app-block",
272
- );
273
- expect(renderGroup).toBeDefined();
274
- expect(renderGroup?.name).toBe("render");
275
- expect(renderGroup?.combo).toBe("s-app-block");
276
-
277
- const compRender = result.combos.find((c) => c.id === "r-1");
278
- expect(compRender).toBeDefined();
279
- expect(compRender?.label?.text).toBe("Comp");
280
- expect(compRender?.combo).toBe("render-group-s-app-block");
281
-
282
- const divRender = result.combos.find((c) => c.id === "r-2");
283
- expect(divRender).toBeDefined();
284
- expect(divRender?.label?.text).toBe("div");
285
- expect(divRender?.combo).toBe("r-1"); // Nested inside r-1
286
- });
287
-
288
- it("should show effect nodes and their dependencies", () => {
289
- const dataWithEffect: DatabaseData = {
290
- ...mockData,
291
- entities: mockData.entities.map((e) => {
292
- if (e.id === "e-app") {
293
- return {
294
- ...e,
295
- data_json: JSON.stringify({
296
- effects: {
297
- "e-app:effect:10:5": {
298
- id: "e-app:effect:10:5",
299
- loc: { line: 10, column: 5 },
300
- reactDeps: [{ id: "sym-import", name: "Comp" }],
301
- },
302
- },
303
- }),
304
- };
305
- }
306
- return e;
307
- }),
308
- };
309
-
310
- const result = componentTask.run(dataWithEffect, initialResult);
311
-
312
- const effectNode = result.nodes.find((n) => n.id === "e-app:effect:10:5");
313
- expect(effectNode).toBeDefined();
314
- expect(effectNode?.name).toBe("useEffect");
315
- expect(effectNode?.combo).toBe("s-app-block");
316
-
317
- // Verify dependency edge (sym-import should be redirected to sym-comp, arrow points FROM dependency TO consumer)
318
- const depEdge = result.edges.find(
319
- (e) => e.id === "sym-comp-e-app:effect:10:5-effect-dep",
320
- );
321
- expect(depEdge).toBeDefined();
322
- expect(depEdge?.source).toBe("sym-comp");
323
- expect(depEdge?.target).toBe("e-app:effect:10:5");
324
- });
325
-
326
- it("should show dependencies for hooks like useMemo", () => {
327
- const dataWithMemo: DatabaseData = {
328
- ...mockData,
329
- entities: [
330
- ...mockData.entities,
331
- {
332
- id: "e-memo",
333
- scope_id: "s-app-block",
334
- kind: "hook",
335
- name: "memoVal",
336
- type: "data",
337
- line: 12,
338
- column: 5,
339
- end_line: 12,
340
- end_column: 20,
341
- declaration_kind: "const",
342
- data_json: JSON.stringify({
343
- reactDeps: [{ id: "sym-import", name: "Comp" }],
344
- }),
345
- },
346
- ],
347
- symbols: [
348
- ...mockData.symbols,
349
- {
350
- id: "sym-memo",
351
- entity_id: "e-memo",
352
- scope_id: "s-app-block",
353
- name: "memoVal",
354
- path: null,
355
- is_alias: 0,
356
- has_default: 0,
357
- data_json: null,
358
- },
359
- ],
360
- };
361
-
362
- const result = componentTask.run(dataWithMemo, initialResult);
363
-
364
- const memoNode = result.nodes.find((n) => n.id === "sym-memo");
365
- expect(memoNode).toBeDefined();
366
-
367
- // Verify dependency edge (arrow points FROM dependency TO consumer)
368
- const depEdge = result.edges.find(
369
- (e) => e.id === "sym-comp-sym-memo-react-dep",
370
- );
371
- expect(depEdge).toBeDefined();
372
- expect(depEdge?.source).toBe("sym-comp");
373
- expect(depEdge?.target).toBe("sym-memo");
374
- });
375
-
376
- it("should show useLayoutEffect nodes", () => {
377
- const dataWithEffect: DatabaseData = {
378
- ...mockData,
379
- entities: mockData.entities.map((e) => {
380
- if (e.id === "e-app") {
381
- return {
382
- ...e,
383
- data_json: JSON.stringify({
384
- effects: {
385
- "e-app:effect:10:5": {
386
- id: "e-app:effect:10:5",
387
- name: "useLayoutEffect",
388
- loc: { line: 10, column: 5 },
389
- reactDeps: [],
390
- },
391
- },
392
- }),
393
- };
394
- }
395
- return e;
396
- }),
397
- };
398
-
399
- const result = componentTask.run(dataWithEffect, initialResult);
400
-
401
- const effectNode = result.nodes.find((n) => n.id === "e-app:effect:10:5");
402
- expect(effectNode).toBeDefined();
403
- expect(effectNode?.name).toBe("useLayoutEffect");
404
- expect(effectNode?.label?.text).toBe("useLayoutEffect");
405
- });
406
-
407
- it("should show improved labels for useState and useRef", () => {
408
- const dataWithState: DatabaseData = {
409
- ...mockData,
410
- entities: [
411
- ...mockData.entities,
412
- {
413
- id: "e-state",
414
- scope_id: "s-app-block",
415
- kind: "state",
416
- name: "count",
417
- type: "data",
418
- line: 6,
419
- column: 5,
420
- end_line: 6,
421
- end_column: 15,
422
- declaration_kind: "const",
423
- data_json: JSON.stringify({ setter: "setCount" }),
424
- },
425
- {
426
- id: "e-ref",
427
- scope_id: "s-app-block",
428
- kind: "ref",
429
- name: "myRef",
430
- type: "data",
431
- line: 7,
432
- column: 5,
433
- end_line: 7,
434
- end_column: 15,
435
- declaration_kind: "const",
436
- data_json: JSON.stringify({}),
437
- },
438
- ],
439
- symbols: [
440
- ...mockData.symbols,
441
- {
442
- id: "sym-state",
443
- entity_id: "e-state",
444
- scope_id: "s-app-block",
445
- name: "count",
446
- path: JSON.stringify(["0"]),
447
- is_alias: 0,
448
- has_default: 0,
449
- data_json: null,
450
- },
451
- {
452
- id: "sym-setter",
453
- entity_id: "e-state",
454
- scope_id: "s-app-block",
455
- name: "setCount",
456
- path: JSON.stringify(["1"]),
457
- is_alias: 0,
458
- has_default: 0,
459
- data_json: null,
460
- },
461
- {
462
- id: "sym-ref",
463
- entity_id: "e-ref",
464
- scope_id: "s-app-block",
465
- name: "myRef",
466
- path: null,
467
- is_alias: 0,
468
- has_default: 0,
469
- data_json: null,
470
- },
471
- ],
472
- };
473
-
474
- const result = componentTask.run(dataWithState, initialResult);
475
-
476
- const stateNode = result.nodes.filter(
477
- (n) => n.id === "sym-state" || n.id === "sym-setter",
478
- );
479
- expect(stateNode.length).toBe(1);
480
- expect(stateNode[0].id).toBe("sym-state");
481
- expect(stateNode[0].label?.text).toBe("count");
482
-
483
- const refNode = result.nodes.find((n) => n.id === "sym-ref");
484
- expect(refNode).toBeDefined();
485
- expect(refNode?.label?.text).toBe("myRef");
486
- });
487
-
488
- it("should group destructured variables by their path", () => {
489
- const dataWithDestructuring: DatabaseData = {
490
- ...mockData,
491
- entities: [
492
- ...mockData.entities,
493
- {
494
- id: "e-hook-call",
495
- scope_id: "s-app-block",
496
- kind: "hook",
497
- name: "useTable",
498
- type: "data",
499
- line: 20,
500
- column: 5,
501
- end_line: 20,
502
- end_column: 30,
503
- declaration_kind: "const",
504
- data_json: null,
505
- },
506
- ],
507
- symbols: [
508
- ...mockData.symbols,
509
- {
510
- id: "sym-rows",
511
- entity_id: "e-hook-call",
512
- scope_id: "s-app-block",
513
- name: "rows",
514
- path: JSON.stringify(["rows"]),
515
- is_alias: 0,
516
- has_default: 0,
517
- data_json: null,
518
- },
519
- {
520
- id: "sym-orig",
521
- entity_id: "e-hook-call",
522
- scope_id: "s-app-block",
523
- name: "original",
524
- path: JSON.stringify(["rows", "0", "original"]),
525
- is_alias: 0,
526
- has_default: 0,
527
- data_json: null,
528
- },
529
- ],
530
- };
531
-
532
- const result = componentTask.run(dataWithDestructuring, initialResult);
533
-
534
- // Verify 'rows' node
535
- const rowsNode = result.nodes.find((n) => n.id === "sym-rows");
536
- expect(rowsNode).toBeDefined();
537
- expect(rowsNode?.combo).toBe("s-app-block:source:e-hook-call"); // First layer grouped under source
538
-
539
- // Verify source combo
540
- const sourceCombo = result.combos.find(
541
- (c) => c.id === "s-app-block:source:e-hook-call",
542
- );
543
- expect(sourceCombo).toBeDefined();
544
- expect(sourceCombo?.name).toBe("useTable");
545
- expect(sourceCombo?.combo).toBe("s-app-block");
546
-
547
- // Verify 'original' node and intermediate combos
548
- const origNode = result.nodes.find((n) => n.id === "sym-orig");
549
- expect(origNode).toBeDefined();
550
-
551
- // Path ["rows", "0", "original"]
552
- // Source: s-app-block:source:e-hook-call
553
- // Combo 1: s-app-block:source:e-hook-call:path:rows
554
- // Combo 2: s-app-block:source:e-hook-call:path:rows/0
555
-
556
- expect(origNode?.combo).toBe("s-app-block:source:e-hook-call:path:rows/0");
557
-
558
- const combo0 = result.combos.find(
559
- (c) => c.id === "s-app-block:source:e-hook-call:path:rows/0",
560
- );
561
- expect(combo0).toBeDefined();
562
- expect(combo0?.name).toBe("0");
563
- expect(combo0?.combo).toBe("s-app-block:source:e-hook-call:path:rows");
564
-
565
- const comboRows = result.combos.find(
566
- (c) => c.id === "s-app-block:source:e-hook-call:path:rows",
567
- );
568
- expect(comboRows).toBeDefined();
569
- expect(comboRows?.name).toBe("rows");
570
- expect(comboRows?.combo).toBe("s-app-block:source:e-hook-call");
571
- });
572
- });