@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.
- package/dist/db.d.ts +40 -0
- package/dist/db.js +2 -0
- package/dist/db.js.map +1 -0
- package/dist/index.d.ts +170 -19
- package/dist/index.js +430 -2
- package/dist/index.js.map +1 -0
- package/package.json +14 -7
- package/src/db.ts +43 -0
- package/src/index.ts +757 -16
- package/tsconfig.json +6 -2
- package/dist/tasks/componentTask.d.ts +0 -2
- package/dist/tasks/componentTask.js +0 -332
- package/dist/tasks/componentTask.test.d.ts +0 -1
- package/dist/tasks/componentTask.test.js +0 -520
- package/dist/tasks/gitTask.d.ts +0 -6
- package/dist/tasks/gitTask.js +0 -69
- package/src/tasks/componentTask.test.ts +0 -572
- package/src/tasks/componentTask.ts +0 -390
- package/src/tasks/gitTask.ts +0 -83
package/src/index.ts
CHANGED
|
@@ -1,34 +1,351 @@
|
|
|
1
|
+
import type { Database } from "better-sqlite3";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
1
4
|
import type {
|
|
2
5
|
TypeDataDeclare,
|
|
3
6
|
ComponentFileVar,
|
|
4
7
|
VariableName,
|
|
5
8
|
DatabaseData,
|
|
9
|
+
GraphViewType,
|
|
10
|
+
WorkspacePackageRow,
|
|
11
|
+
PackageRow,
|
|
12
|
+
PackageDependencyRow,
|
|
13
|
+
FileRow,
|
|
14
|
+
ScopeRow,
|
|
15
|
+
EntityRow,
|
|
16
|
+
SymbolRow,
|
|
17
|
+
RenderRow,
|
|
18
|
+
ExportRow,
|
|
19
|
+
RelationRow,
|
|
20
|
+
VariableScope,
|
|
21
|
+
VariableLoc,
|
|
6
22
|
} from "@nexiq/shared";
|
|
7
23
|
|
|
8
24
|
// Re-exporting these from shared for convenience if needed by extensions
|
|
9
|
-
export type {
|
|
25
|
+
export type {
|
|
26
|
+
TypeDataDeclare,
|
|
27
|
+
ComponentFileVar,
|
|
28
|
+
VariableName,
|
|
29
|
+
DatabaseData,
|
|
30
|
+
GraphViewType,
|
|
31
|
+
VariableScope,
|
|
32
|
+
VariableLoc,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export interface UsageOccurrence {
|
|
36
|
+
usageId: string;
|
|
37
|
+
filePath: string;
|
|
38
|
+
line: number;
|
|
39
|
+
column: number;
|
|
40
|
+
ownerId: string;
|
|
41
|
+
ownerKind: string;
|
|
42
|
+
accessPath?: string[] | undefined;
|
|
43
|
+
isOptional?: boolean | undefined;
|
|
44
|
+
isComputed?: boolean | undefined;
|
|
45
|
+
hiddenIntermediate?: string | undefined;
|
|
46
|
+
displayLabel?: string | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface NodeAppearance {
|
|
50
|
+
color?: string | undefined;
|
|
51
|
+
radius?: number | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface GraphAppearance {
|
|
55
|
+
nodeHighlight?: string;
|
|
56
|
+
comboHighlight?: string;
|
|
57
|
+
arrowColor?: string;
|
|
58
|
+
directFlowColor?: string;
|
|
59
|
+
sideEffectFlowColor?: string;
|
|
60
|
+
labelColor?: string;
|
|
61
|
+
gitAdded?: string;
|
|
62
|
+
gitModified?: string;
|
|
63
|
+
gitDeleted?: string;
|
|
64
|
+
nodes?: Partial<
|
|
65
|
+
Record<
|
|
66
|
+
| "package"
|
|
67
|
+
| "scope"
|
|
68
|
+
| "component"
|
|
69
|
+
| "hook"
|
|
70
|
+
| "renderGroup"
|
|
71
|
+
| "sourceGroup"
|
|
72
|
+
| "pathGroup"
|
|
73
|
+
| "callback"
|
|
74
|
+
| "state"
|
|
75
|
+
| "memo"
|
|
76
|
+
| "ref"
|
|
77
|
+
| "effect"
|
|
78
|
+
| "prop"
|
|
79
|
+
| "render"
|
|
80
|
+
| "variable",
|
|
81
|
+
NodeAppearance
|
|
82
|
+
>
|
|
83
|
+
>;
|
|
84
|
+
typeKeyword?: string;
|
|
85
|
+
typeLiteral?: string;
|
|
86
|
+
typeString?: string;
|
|
87
|
+
typeNumber?: string;
|
|
88
|
+
typeBoolean?: string;
|
|
89
|
+
typePunctuation?: string;
|
|
90
|
+
typeReference?: string;
|
|
91
|
+
typeComponent?: string;
|
|
92
|
+
typeDefault?: string;
|
|
93
|
+
genericsColor?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type CustomColors = GraphAppearance;
|
|
97
|
+
|
|
98
|
+
export const DEFAULT_GRAPH_APPEARANCE: GraphAppearance = {
|
|
99
|
+
directFlowColor: "#2563eb",
|
|
100
|
+
sideEffectFlowColor: "#f59e0b",
|
|
101
|
+
gitAdded: "#22c55e",
|
|
102
|
+
gitModified: "#f59e0b",
|
|
103
|
+
gitDeleted: "#ef4444",
|
|
104
|
+
nodes: {
|
|
105
|
+
package: { color: "#0f766e", radius: 24 },
|
|
106
|
+
scope: { color: "#475569", radius: 18 },
|
|
107
|
+
component: { color: "#2563eb", radius: 20 },
|
|
108
|
+
hook: { color: "#7c3aed", radius: 18 },
|
|
109
|
+
renderGroup: { color: "#0ea5e9", radius: 18 },
|
|
110
|
+
sourceGroup: { color: "#14b8a6", radius: 16 },
|
|
111
|
+
pathGroup: { color: "#64748b", radius: 14 },
|
|
112
|
+
callback: { color: "#ef4444", radius: 14 },
|
|
113
|
+
state: { color: "#ef4444", radius: 16 },
|
|
114
|
+
memo: { color: "#ef4444", radius: 14 },
|
|
115
|
+
ref: { color: "#ef4444", radius: 14 },
|
|
116
|
+
effect: { color: "#eab308", radius: 14 },
|
|
117
|
+
prop: { color: "#22c55e", radius: 12 },
|
|
118
|
+
render: { color: "#2563eb", radius: 14 },
|
|
119
|
+
variable: { color: "#60a5fa", radius: 14 },
|
|
120
|
+
},
|
|
121
|
+
typeKeyword: "#c084fc",
|
|
122
|
+
typeLiteral: "#fdba74",
|
|
123
|
+
typeString: "#86efac",
|
|
124
|
+
typeNumber: "#93c5fd",
|
|
125
|
+
typeBoolean: "#fde047",
|
|
126
|
+
typePunctuation: "#6b7280",
|
|
127
|
+
typeReference: "#60a5fa",
|
|
128
|
+
typeComponent: "#67e8f9",
|
|
129
|
+
typeDefault: "#d1d5db",
|
|
130
|
+
genericsColor: "#fde047",
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
type LegacyNodeColorKeys = Partial<
|
|
134
|
+
Record<
|
|
135
|
+
| "stateNode"
|
|
136
|
+
| "memoNode"
|
|
137
|
+
| "callbackNode"
|
|
138
|
+
| "refNode"
|
|
139
|
+
| "effectNode"
|
|
140
|
+
| "propNode"
|
|
141
|
+
| "componentNode"
|
|
142
|
+
| "hookNode"
|
|
143
|
+
| "renderNode"
|
|
144
|
+
| "packageNode",
|
|
145
|
+
string
|
|
146
|
+
>
|
|
147
|
+
>;
|
|
148
|
+
|
|
149
|
+
export function normalizeGraphAppearance(
|
|
150
|
+
appearance?: GraphAppearance | null,
|
|
151
|
+
): GraphAppearance {
|
|
152
|
+
const legacy = (appearance || {}) as GraphAppearance & LegacyNodeColorKeys;
|
|
153
|
+
const nodes = {
|
|
154
|
+
package: {
|
|
155
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.package,
|
|
156
|
+
color:
|
|
157
|
+
legacy.packageNode ||
|
|
158
|
+
appearance?.nodes?.package?.color ||
|
|
159
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.package?.color,
|
|
160
|
+
radius:
|
|
161
|
+
appearance?.nodes?.package?.radius ??
|
|
162
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.package?.radius,
|
|
163
|
+
},
|
|
164
|
+
scope: {
|
|
165
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.scope,
|
|
166
|
+
color:
|
|
167
|
+
appearance?.nodes?.scope?.color ||
|
|
168
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.scope?.color,
|
|
169
|
+
radius:
|
|
170
|
+
appearance?.nodes?.scope?.radius ??
|
|
171
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.scope?.radius,
|
|
172
|
+
},
|
|
173
|
+
component: {
|
|
174
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.component,
|
|
175
|
+
color:
|
|
176
|
+
legacy.componentNode ||
|
|
177
|
+
appearance?.nodes?.component?.color ||
|
|
178
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.component?.color,
|
|
179
|
+
radius:
|
|
180
|
+
appearance?.nodes?.component?.radius ??
|
|
181
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.component?.radius,
|
|
182
|
+
},
|
|
183
|
+
hook: {
|
|
184
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.hook,
|
|
185
|
+
color:
|
|
186
|
+
legacy.hookNode ||
|
|
187
|
+
appearance?.nodes?.hook?.color ||
|
|
188
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.hook?.color,
|
|
189
|
+
radius:
|
|
190
|
+
appearance?.nodes?.hook?.radius ??
|
|
191
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.hook?.radius,
|
|
192
|
+
},
|
|
193
|
+
renderGroup: {
|
|
194
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.renderGroup,
|
|
195
|
+
color:
|
|
196
|
+
appearance?.nodes?.renderGroup?.color ||
|
|
197
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.renderGroup?.color,
|
|
198
|
+
radius:
|
|
199
|
+
appearance?.nodes?.renderGroup?.radius ??
|
|
200
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.renderGroup?.radius,
|
|
201
|
+
},
|
|
202
|
+
sourceGroup: {
|
|
203
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.sourceGroup,
|
|
204
|
+
color:
|
|
205
|
+
appearance?.nodes?.sourceGroup?.color ||
|
|
206
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.sourceGroup?.color,
|
|
207
|
+
radius:
|
|
208
|
+
appearance?.nodes?.sourceGroup?.radius ??
|
|
209
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.sourceGroup?.radius,
|
|
210
|
+
},
|
|
211
|
+
pathGroup: {
|
|
212
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.pathGroup,
|
|
213
|
+
color:
|
|
214
|
+
appearance?.nodes?.pathGroup?.color ||
|
|
215
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.pathGroup?.color,
|
|
216
|
+
radius:
|
|
217
|
+
appearance?.nodes?.pathGroup?.radius ??
|
|
218
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.pathGroup?.radius,
|
|
219
|
+
},
|
|
220
|
+
callback: {
|
|
221
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.callback,
|
|
222
|
+
color:
|
|
223
|
+
legacy.callbackNode ||
|
|
224
|
+
appearance?.nodes?.callback?.color ||
|
|
225
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.callback?.color,
|
|
226
|
+
radius:
|
|
227
|
+
appearance?.nodes?.callback?.radius ??
|
|
228
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.callback?.radius,
|
|
229
|
+
},
|
|
230
|
+
state: {
|
|
231
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.state,
|
|
232
|
+
color:
|
|
233
|
+
legacy.stateNode ||
|
|
234
|
+
appearance?.nodes?.state?.color ||
|
|
235
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.state?.color,
|
|
236
|
+
radius:
|
|
237
|
+
appearance?.nodes?.state?.radius ??
|
|
238
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.state?.radius,
|
|
239
|
+
},
|
|
240
|
+
memo: {
|
|
241
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.memo,
|
|
242
|
+
color:
|
|
243
|
+
legacy.memoNode ||
|
|
244
|
+
appearance?.nodes?.memo?.color ||
|
|
245
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.memo?.color,
|
|
246
|
+
radius:
|
|
247
|
+
appearance?.nodes?.memo?.radius ??
|
|
248
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.memo?.radius,
|
|
249
|
+
},
|
|
250
|
+
ref: {
|
|
251
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.ref,
|
|
252
|
+
color:
|
|
253
|
+
legacy.refNode ||
|
|
254
|
+
appearance?.nodes?.ref?.color ||
|
|
255
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.ref?.color,
|
|
256
|
+
radius:
|
|
257
|
+
appearance?.nodes?.ref?.radius ??
|
|
258
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.ref?.radius,
|
|
259
|
+
},
|
|
260
|
+
effect: {
|
|
261
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.effect,
|
|
262
|
+
color:
|
|
263
|
+
legacy.effectNode ||
|
|
264
|
+
appearance?.nodes?.effect?.color ||
|
|
265
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.effect?.color,
|
|
266
|
+
radius:
|
|
267
|
+
appearance?.nodes?.effect?.radius ??
|
|
268
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.effect?.radius,
|
|
269
|
+
},
|
|
270
|
+
prop: {
|
|
271
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.prop,
|
|
272
|
+
color:
|
|
273
|
+
legacy.propNode ||
|
|
274
|
+
appearance?.nodes?.prop?.color ||
|
|
275
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.prop?.color,
|
|
276
|
+
radius:
|
|
277
|
+
appearance?.nodes?.prop?.radius ??
|
|
278
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.prop?.radius,
|
|
279
|
+
},
|
|
280
|
+
render: {
|
|
281
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.render,
|
|
282
|
+
color:
|
|
283
|
+
legacy.renderNode ||
|
|
284
|
+
appearance?.nodes?.render?.color ||
|
|
285
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.render?.color,
|
|
286
|
+
radius:
|
|
287
|
+
appearance?.nodes?.render?.radius ??
|
|
288
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.render?.radius,
|
|
289
|
+
},
|
|
290
|
+
variable: {
|
|
291
|
+
...DEFAULT_GRAPH_APPEARANCE.nodes?.variable,
|
|
292
|
+
color:
|
|
293
|
+
appearance?.nodes?.variable?.color ||
|
|
294
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.variable?.color,
|
|
295
|
+
radius:
|
|
296
|
+
appearance?.nodes?.variable?.radius ??
|
|
297
|
+
DEFAULT_GRAPH_APPEARANCE.nodes?.variable?.radius,
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
...DEFAULT_GRAPH_APPEARANCE,
|
|
303
|
+
...appearance,
|
|
304
|
+
nodes,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
10
307
|
|
|
11
308
|
export interface GraphItemPosition {
|
|
12
309
|
x: number;
|
|
13
310
|
y: number;
|
|
14
311
|
}
|
|
15
312
|
|
|
313
|
+
export interface AppearanceOverride {
|
|
314
|
+
color?: string;
|
|
315
|
+
radius?: number;
|
|
316
|
+
collapsedRadius?: number;
|
|
317
|
+
expandedRadius?: number;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export interface GraphNodeDetail {
|
|
321
|
+
id: string;
|
|
322
|
+
projectPath?: string;
|
|
323
|
+
fileName?: string;
|
|
324
|
+
pureFileName?: string;
|
|
325
|
+
loc?: VariableLoc;
|
|
326
|
+
declarationKind?: "const" | "let" | "var" | "using" | "await using";
|
|
327
|
+
tag?: string;
|
|
328
|
+
componentType?: "function" | "class" | string | null;
|
|
329
|
+
raw?: ComponentFileVar;
|
|
330
|
+
[key: string]: unknown;
|
|
331
|
+
}
|
|
332
|
+
|
|
16
333
|
export interface GraphNodeData {
|
|
17
334
|
id: string;
|
|
18
335
|
name: VariableName | string;
|
|
19
|
-
label?: { text: string; fill?: string };
|
|
20
336
|
type?: string;
|
|
21
|
-
fileName?: string;
|
|
22
|
-
pureFileName?: string;
|
|
23
|
-
loc?: { line: number; column: number };
|
|
24
337
|
radius?: number;
|
|
25
338
|
color?: string;
|
|
26
339
|
combo?: string;
|
|
27
340
|
gitStatus?: "added" | "modified" | "deleted";
|
|
28
|
-
|
|
29
|
-
tag?: string;
|
|
30
|
-
raw?: ComponentFileVar;
|
|
341
|
+
appearanceOverride?: AppearanceOverride;
|
|
31
342
|
displayName?: string;
|
|
343
|
+
hasProps?: boolean;
|
|
344
|
+
hasHooks?: boolean;
|
|
345
|
+
hasChildren?: boolean;
|
|
346
|
+
pureFileName?: string;
|
|
347
|
+
scope?: VariableScope | string;
|
|
348
|
+
loc?: VariableLoc;
|
|
32
349
|
[key: string]: unknown;
|
|
33
350
|
}
|
|
34
351
|
|
|
@@ -37,6 +354,7 @@ export interface GraphComboData extends GraphNodeData {
|
|
|
37
354
|
collapsedRadius?: number;
|
|
38
355
|
expandedRadius?: number;
|
|
39
356
|
padding?: number;
|
|
357
|
+
appearanceOverride?: AppearanceOverride;
|
|
40
358
|
[key: string]: unknown;
|
|
41
359
|
}
|
|
42
360
|
|
|
@@ -44,7 +362,15 @@ export interface GraphArrowData {
|
|
|
44
362
|
id: string;
|
|
45
363
|
source: string;
|
|
46
364
|
target: string;
|
|
47
|
-
|
|
365
|
+
name?: string;
|
|
366
|
+
edgeKind?: string;
|
|
367
|
+
category?: string;
|
|
368
|
+
flowRole?: "direct" | "side-effect" | null;
|
|
369
|
+
usageCount?: number;
|
|
370
|
+
usages?: UsageOccurrence[];
|
|
371
|
+
highlighted?: boolean;
|
|
372
|
+
dimmed?: boolean;
|
|
373
|
+
opensTo?: { fileName: string; line: number; column: number };
|
|
48
374
|
combo?: string;
|
|
49
375
|
[key: string]: unknown;
|
|
50
376
|
}
|
|
@@ -57,16 +383,383 @@ export interface useGraphProps {
|
|
|
57
383
|
|
|
58
384
|
export interface GraphViewResult extends useGraphProps {
|
|
59
385
|
typeData: Record<string, TypeDataDeclare>;
|
|
386
|
+
details?: Record<string, GraphNodeDetail>;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Context provided to tasks during graph view generation.
|
|
391
|
+
*/
|
|
392
|
+
export interface TaskContext {
|
|
393
|
+
/**
|
|
394
|
+
* Database instance for querying graph data.
|
|
395
|
+
*/
|
|
396
|
+
db?: Database;
|
|
397
|
+
/**
|
|
398
|
+
* Root path of the project being analyzed.
|
|
399
|
+
*/
|
|
400
|
+
projectRoot: string;
|
|
401
|
+
/**
|
|
402
|
+
* Specific paths within the project to focus analysis on.
|
|
403
|
+
*/
|
|
404
|
+
analysisPaths?: string[];
|
|
405
|
+
/**
|
|
406
|
+
* The type of view being generated.
|
|
407
|
+
*/
|
|
408
|
+
viewType: GraphViewType;
|
|
409
|
+
/**
|
|
410
|
+
* Optional pre-loaded snapshot data, for backward compatibility or when already available.
|
|
411
|
+
*/
|
|
412
|
+
snapshotData?: DatabaseData;
|
|
413
|
+
/**
|
|
414
|
+
* Request-scoped cache for aggregated task data so multiple tasks do not reread SQLite.
|
|
415
|
+
*/
|
|
416
|
+
taskDataCache?: DatabaseData;
|
|
417
|
+
/**
|
|
418
|
+
* Path to the original Cache Database. Native Rust tasks use this to ATTACH the database directly.
|
|
419
|
+
*/
|
|
420
|
+
cacheDbPath?: string;
|
|
421
|
+
/**
|
|
422
|
+
* Optional stage profiler provided by the caller.
|
|
423
|
+
*/
|
|
424
|
+
profileStage?: (
|
|
425
|
+
name: string,
|
|
426
|
+
startedAt: number,
|
|
427
|
+
detail?: string,
|
|
428
|
+
) => void | Promise<void>;
|
|
429
|
+
/**
|
|
430
|
+
* Buffer for storing node, edge, and combo data in FlatBuffer format.
|
|
431
|
+
*/
|
|
432
|
+
nodeDataBuffer?: SharedArrayBuffer;
|
|
433
|
+
/**
|
|
434
|
+
* Shared buffer for storing node details.
|
|
435
|
+
*/
|
|
436
|
+
detailBuffer?: SharedArrayBuffer;
|
|
437
|
+
/**
|
|
438
|
+
* Serialized SQLite database buffer containing both input data and output tables.
|
|
439
|
+
*/
|
|
440
|
+
sqliteBuffer?: Uint8Array;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Helper to retrieve required graph data from either TaskContext.snapshotData or TaskContext.db.
|
|
445
|
+
* It handles workspace databases and qualifies IDs to avoid collisions.
|
|
446
|
+
*/
|
|
447
|
+
export function getTaskData(context: TaskContext): DatabaseData {
|
|
448
|
+
const { db, snapshotData, analysisPaths, taskDataCache, projectRoot } =
|
|
449
|
+
context;
|
|
450
|
+
|
|
451
|
+
if (snapshotData) {
|
|
452
|
+
return snapshotData;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (taskDataCache) {
|
|
456
|
+
return taskDataCache;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (!db) {
|
|
460
|
+
const empty = {
|
|
461
|
+
files: [],
|
|
462
|
+
entities: [],
|
|
463
|
+
scopes: [],
|
|
464
|
+
symbols: [],
|
|
465
|
+
renders: [],
|
|
466
|
+
exports: [],
|
|
467
|
+
relations: [],
|
|
468
|
+
};
|
|
469
|
+
context.taskDataCache = empty;
|
|
470
|
+
return empty;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const existingTables = new Set(
|
|
474
|
+
(
|
|
475
|
+
db
|
|
476
|
+
.prepare(
|
|
477
|
+
"SELECT name FROM sqlite_master WHERE type IN ('table', 'view') UNION SELECT name FROM sqlite_temp_master WHERE type IN ('table', 'view')",
|
|
478
|
+
)
|
|
479
|
+
.all() as { name: string }[]
|
|
480
|
+
).map((row) => row.name),
|
|
481
|
+
);
|
|
482
|
+
const tableExists = (name: string) => existingTables.has(name);
|
|
483
|
+
|
|
484
|
+
if (tableExists("workspace_packages")) {
|
|
485
|
+
const workspacePackages = db
|
|
486
|
+
.prepare("SELECT * FROM workspace_packages")
|
|
487
|
+
.all() as WorkspacePackageRow[];
|
|
488
|
+
const filteredPackages =
|
|
489
|
+
analysisPaths && analysisPaths.length > 0
|
|
490
|
+
? workspacePackages.filter((p) => analysisPaths.includes(p.path))
|
|
491
|
+
: workspacePackages;
|
|
492
|
+
|
|
493
|
+
const aggregated: DatabaseData = {
|
|
494
|
+
packages: [],
|
|
495
|
+
package_dependencies: [],
|
|
496
|
+
files: [],
|
|
497
|
+
entities: [],
|
|
498
|
+
scopes: [],
|
|
499
|
+
symbols: [],
|
|
500
|
+
renders: [],
|
|
501
|
+
exports: [],
|
|
502
|
+
relations: [],
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
filteredPackages.forEach((pkg, index) => {
|
|
506
|
+
let pkgDbPath = pkg.db_path;
|
|
507
|
+
if (!path.isAbsolute(pkgDbPath)) {
|
|
508
|
+
pkgDbPath = path.resolve(projectRoot, pkgDbPath);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (!fs.existsSync(pkgDbPath)) {
|
|
512
|
+
console.warn(
|
|
513
|
+
`Package database not found at ${pkgDbPath} (original: ${pkg.db_path})`,
|
|
514
|
+
);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// Open individual package databases one by one to avoid SQLITE_LIMIT_ATTACHED
|
|
519
|
+
const DbConstructor = db.constructor as new (
|
|
520
|
+
path: string,
|
|
521
|
+
options?: { readonly?: boolean },
|
|
522
|
+
) => Database;
|
|
523
|
+
|
|
524
|
+
let pkgDb: Database;
|
|
525
|
+
try {
|
|
526
|
+
pkgDb = new DbConstructor(pkgDbPath, { readonly: true });
|
|
527
|
+
} catch (err) {
|
|
528
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
529
|
+
throw new Error(
|
|
530
|
+
`Extension SDK: Failed to open package database at ${pkgDbPath}: ${msg}`,
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
try {
|
|
535
|
+
const fileIdOffset = (index + 1) * 1000000;
|
|
536
|
+
const pkgPrefix = `workspace:${pkg.package_id}:`;
|
|
537
|
+
const pkgId = pkg.package_id;
|
|
538
|
+
|
|
539
|
+
const pkgExistingTables = new Set(
|
|
540
|
+
(
|
|
541
|
+
pkgDb
|
|
542
|
+
.prepare(
|
|
543
|
+
"SELECT name FROM sqlite_master WHERE type IN ('table', 'view')",
|
|
544
|
+
)
|
|
545
|
+
.all() as { name: string }[]
|
|
546
|
+
).map((row) => row.name),
|
|
547
|
+
);
|
|
548
|
+
const pkgTableExists = (name: string) => pkgExistingTables.has(name);
|
|
549
|
+
|
|
550
|
+
// 1. Packages & Dependencies
|
|
551
|
+
const pkgRows = pkgTableExists("packages")
|
|
552
|
+
? (pkgDb.prepare("SELECT * FROM packages").all() as PackageRow[])
|
|
553
|
+
: [];
|
|
554
|
+
|
|
555
|
+
if (pkgRows.length > 0) {
|
|
556
|
+
aggregated.packages!.push(
|
|
557
|
+
...pkgRows.map((p) => ({
|
|
558
|
+
...p,
|
|
559
|
+
id: pkgId, // Force ID consistency with workspace remapping
|
|
560
|
+
})),
|
|
561
|
+
);
|
|
562
|
+
} else {
|
|
563
|
+
aggregated.packages!.push({
|
|
564
|
+
id: pkgId,
|
|
565
|
+
name: pkg.name,
|
|
566
|
+
version: pkg.version || "0.0.0",
|
|
567
|
+
path: pkg.path,
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (pkgTableExists("package_dependencies")) {
|
|
572
|
+
aggregated.package_dependencies!.push(
|
|
573
|
+
...(pkgDb
|
|
574
|
+
.prepare("SELECT * FROM package_dependencies")
|
|
575
|
+
.all() as PackageDependencyRow[]),
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// 2. Files
|
|
580
|
+
const fRows = pkgDb.prepare("SELECT * FROM files").all() as FileRow[];
|
|
581
|
+
aggregated.files.push(
|
|
582
|
+
...fRows.map((f) => {
|
|
583
|
+
let relativePath = f.path;
|
|
584
|
+
if (projectRoot && pkg.path) {
|
|
585
|
+
const absPkgPath = path.isAbsolute(pkg.path)
|
|
586
|
+
? pkg.path
|
|
587
|
+
: path.resolve(projectRoot, pkg.path);
|
|
588
|
+
const absFilePath = path.join(
|
|
589
|
+
absPkgPath,
|
|
590
|
+
f.path.startsWith("/") ? f.path.slice(1) : f.path,
|
|
591
|
+
);
|
|
592
|
+
relativePath =
|
|
593
|
+
"/" +
|
|
594
|
+
path
|
|
595
|
+
.relative(projectRoot, absFilePath)
|
|
596
|
+
.replaceAll(path.sep, "/");
|
|
597
|
+
}
|
|
598
|
+
return {
|
|
599
|
+
...f,
|
|
600
|
+
id: f.id + fileIdOffset,
|
|
601
|
+
package_id: f.package_id || pkgId,
|
|
602
|
+
path: relativePath,
|
|
603
|
+
};
|
|
604
|
+
}),
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
// 3. Scopes
|
|
608
|
+
const sRows = pkgDb
|
|
609
|
+
.prepare(
|
|
610
|
+
`SELECT
|
|
611
|
+
'${pkgPrefix}' || id as id,
|
|
612
|
+
file_id + ${fileIdOffset} as file_id,
|
|
613
|
+
CASE WHEN parent_id IS NOT NULL THEN '${pkgPrefix}' || parent_id ELSE NULL END as parent_id,
|
|
614
|
+
CASE WHEN entity_id IS NOT NULL THEN '${pkgPrefix}' || entity_id ELSE NULL END as entity_id,
|
|
615
|
+
kind, data_json
|
|
616
|
+
FROM scopes`,
|
|
617
|
+
)
|
|
618
|
+
.all() as ScopeRow[];
|
|
619
|
+
aggregated.scopes.push(...sRows);
|
|
620
|
+
|
|
621
|
+
// 4. Entities
|
|
622
|
+
const eRows = pkgDb
|
|
623
|
+
.prepare(
|
|
624
|
+
`SELECT
|
|
625
|
+
'${pkgPrefix}' || id as id,
|
|
626
|
+
'${pkgPrefix}' || scope_id as scope_id,
|
|
627
|
+
kind, name, type, line, "column", end_line, end_column, declaration_kind, data_json
|
|
628
|
+
FROM entities`,
|
|
629
|
+
)
|
|
630
|
+
.all() as EntityRow[];
|
|
631
|
+
aggregated.entities.push(...eRows);
|
|
632
|
+
|
|
633
|
+
// 5. Symbols
|
|
634
|
+
const symRows = pkgDb
|
|
635
|
+
.prepare(
|
|
636
|
+
`SELECT
|
|
637
|
+
'${pkgPrefix}' || id as id,
|
|
638
|
+
'${pkgPrefix}' || entity_id as entity_id,
|
|
639
|
+
'${pkgPrefix}' || scope_id as scope_id,
|
|
640
|
+
name, path, is_alias, has_default, data_json
|
|
641
|
+
FROM symbols`,
|
|
642
|
+
)
|
|
643
|
+
.all() as SymbolRow[];
|
|
644
|
+
aggregated.symbols.push(...symRows);
|
|
645
|
+
|
|
646
|
+
// 6. Renders
|
|
647
|
+
const rRows = pkgDb
|
|
648
|
+
.prepare(
|
|
649
|
+
`SELECT
|
|
650
|
+
'${pkgPrefix}' || id as id,
|
|
651
|
+
file_id + ${fileIdOffset} as file_id,
|
|
652
|
+
'${pkgPrefix}' || parent_entity_id as parent_entity_id,
|
|
653
|
+
CASE WHEN parent_render_id IS NOT NULL THEN '${pkgPrefix}' || parent_render_id ELSE NULL END as parent_render_id,
|
|
654
|
+
CASE WHEN symbol_id IS NOT NULL THEN '${pkgPrefix}' || symbol_id ELSE NULL END as symbol_id,
|
|
655
|
+
tag, render_index, line, "column", kind, data_json
|
|
656
|
+
FROM renders`,
|
|
657
|
+
)
|
|
658
|
+
.all() as RenderRow[];
|
|
659
|
+
aggregated.renders.push(...rRows);
|
|
660
|
+
|
|
661
|
+
// 7. Exports
|
|
662
|
+
if (pkgTableExists("exports")) {
|
|
663
|
+
const expRows = pkgDb
|
|
664
|
+
.prepare(
|
|
665
|
+
`SELECT
|
|
666
|
+
'${pkgPrefix}' || id as id,
|
|
667
|
+
'${pkgPrefix}' || scope_id as scope_id,
|
|
668
|
+
CASE WHEN symbol_id IS NOT NULL THEN '${pkgPrefix}' || symbol_id ELSE NULL END as symbol_id,
|
|
669
|
+
CASE WHEN entity_id IS NOT NULL THEN '${pkgPrefix}' || entity_id ELSE NULL END as entity_id,
|
|
670
|
+
name, is_default
|
|
671
|
+
FROM exports`,
|
|
672
|
+
)
|
|
673
|
+
.all() as ExportRow[];
|
|
674
|
+
aggregated.exports.push(...expRows);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// 8. Relations
|
|
678
|
+
const relRows = pkgDb
|
|
679
|
+
.prepare(
|
|
680
|
+
`SELECT
|
|
681
|
+
'${pkgPrefix}' || from_id as from_id,
|
|
682
|
+
'${pkgPrefix}' || to_id as to_id,
|
|
683
|
+
kind, line, "column", data_json
|
|
684
|
+
FROM relations`,
|
|
685
|
+
)
|
|
686
|
+
.all() as RelationRow[];
|
|
687
|
+
aggregated.relations.push(...relRows);
|
|
688
|
+
} finally {
|
|
689
|
+
pkgDb.close();
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
context.taskDataCache = aggregated;
|
|
694
|
+
return {
|
|
695
|
+
...aggregated,
|
|
696
|
+
diff: context.snapshotData?.diff || context.taskDataCache?.diff,
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// Single project database fallback
|
|
701
|
+
const hasPackages = tableExists("packages");
|
|
702
|
+
const hasDeps = tableExists("package_dependencies");
|
|
703
|
+
const hasExports = tableExists("exports");
|
|
704
|
+
|
|
705
|
+
const singleProjectData = {
|
|
706
|
+
packages: hasPackages
|
|
707
|
+
? (db.prepare("SELECT * FROM packages").all() as PackageRow[])
|
|
708
|
+
: [],
|
|
709
|
+
package_dependencies: hasDeps
|
|
710
|
+
? (db
|
|
711
|
+
.prepare("SELECT * FROM package_dependencies")
|
|
712
|
+
.all() as PackageDependencyRow[])
|
|
713
|
+
: [],
|
|
714
|
+
files: db.prepare("SELECT * FROM files").all() as FileRow[],
|
|
715
|
+
entities: db.prepare("SELECT * FROM entities").all() as EntityRow[],
|
|
716
|
+
scopes: db.prepare("SELECT * FROM scopes").all() as ScopeRow[],
|
|
717
|
+
symbols: db.prepare("SELECT * FROM symbols").all() as SymbolRow[],
|
|
718
|
+
renders: db.prepare("SELECT * FROM renders").all() as RenderRow[],
|
|
719
|
+
exports: hasExports
|
|
720
|
+
? (db.prepare("SELECT * FROM exports").all() as ExportRow[])
|
|
721
|
+
: [],
|
|
722
|
+
relations: db.prepare("SELECT * FROM relations").all() as RelationRow[],
|
|
723
|
+
diff: context.snapshotData?.diff || context.taskDataCache?.diff,
|
|
724
|
+
};
|
|
725
|
+
context.taskDataCache = singleProjectData;
|
|
726
|
+
return singleProjectData;
|
|
60
727
|
}
|
|
61
728
|
|
|
729
|
+
/**
|
|
730
|
+
* A task that contributes to the construction of a graph view.
|
|
731
|
+
*/
|
|
62
732
|
export interface GraphViewTask {
|
|
63
733
|
id: string;
|
|
64
734
|
priority: number;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
735
|
+
extensionPath?: string;
|
|
736
|
+
/**
|
|
737
|
+
* Run the task to update the graph result.
|
|
738
|
+
*
|
|
739
|
+
* @param result The current graph result to be updated
|
|
740
|
+
* @param context Context containing database and project information
|
|
741
|
+
* @returns Updated GraphViewResult
|
|
742
|
+
*/
|
|
743
|
+
run?: (result: GraphViewResult, context: TaskContext) => GraphViewResult;
|
|
744
|
+
/**
|
|
745
|
+
* Run the task using buffers for improved performance.
|
|
746
|
+
*
|
|
747
|
+
* @param nodeData Shared buffer for node/edge/combo data
|
|
748
|
+
* @param detailBuffer Shared buffer for node details
|
|
749
|
+
* @param context Context containing database and project information
|
|
750
|
+
*/
|
|
751
|
+
runBuffer?: (
|
|
752
|
+
nodeData: SharedArrayBuffer,
|
|
753
|
+
detailBuffer: SharedArrayBuffer,
|
|
754
|
+
context: TaskContext,
|
|
755
|
+
) => number | void;
|
|
756
|
+
/**
|
|
757
|
+
* Run the task using an in-memory SQLite database.
|
|
758
|
+
* The database is expected to be initialized with input data and out_* tables.
|
|
759
|
+
*/
|
|
760
|
+
runSqlite?: (
|
|
761
|
+
context: TaskContext,
|
|
762
|
+
) => void | Promise<void> | Uint8Array | Promise<Uint8Array>;
|
|
70
763
|
}
|
|
71
764
|
|
|
72
765
|
export interface DetailSectionProps {
|
|
@@ -75,6 +768,7 @@ export interface DetailSectionProps {
|
|
|
75
768
|
graph: unknown; // GraphData instance
|
|
76
769
|
projectPath: string;
|
|
77
770
|
typeData: Record<string, TypeDataDeclare>;
|
|
771
|
+
detail?: GraphNodeDetail;
|
|
78
772
|
onSelect?: (id: string) => void;
|
|
79
773
|
renderNodes?: GraphNodeData[];
|
|
80
774
|
}
|
|
@@ -108,5 +802,52 @@ export interface Extension {
|
|
|
108
802
|
mcpTools?: MCPTool[];
|
|
109
803
|
}
|
|
110
804
|
|
|
111
|
-
|
|
112
|
-
|
|
805
|
+
/**
|
|
806
|
+
* Initialize standard output tables in a SQLite database for extension results.
|
|
807
|
+
*/
|
|
808
|
+
export function initOutputTables(db: Database) {
|
|
809
|
+
db.exec(`
|
|
810
|
+
CREATE TABLE IF NOT EXISTS out_nodes (
|
|
811
|
+
id TEXT PRIMARY KEY,
|
|
812
|
+
name TEXT,
|
|
813
|
+
type TEXT,
|
|
814
|
+
combo_id TEXT,
|
|
815
|
+
color TEXT,
|
|
816
|
+
radius REAL,
|
|
817
|
+
display_name TEXT,
|
|
818
|
+
git_status TEXT,
|
|
819
|
+
meta_json TEXT
|
|
820
|
+
);
|
|
821
|
+
CREATE TABLE IF NOT EXISTS out_edges (
|
|
822
|
+
id TEXT PRIMARY KEY,
|
|
823
|
+
source TEXT,
|
|
824
|
+
target TEXT,
|
|
825
|
+
name TEXT,
|
|
826
|
+
kind TEXT,
|
|
827
|
+
category TEXT,
|
|
828
|
+
meta_json TEXT
|
|
829
|
+
);
|
|
830
|
+
CREATE TABLE IF NOT EXISTS out_combos (
|
|
831
|
+
id TEXT PRIMARY KEY,
|
|
832
|
+
name TEXT,
|
|
833
|
+
type TEXT,
|
|
834
|
+
parent_id TEXT,
|
|
835
|
+
color TEXT,
|
|
836
|
+
radius REAL,
|
|
837
|
+
collapsed INTEGER,
|
|
838
|
+
display_name TEXT,
|
|
839
|
+
git_status TEXT,
|
|
840
|
+
meta_json TEXT
|
|
841
|
+
);
|
|
842
|
+
CREATE TABLE IF NOT EXISTS out_details (
|
|
843
|
+
id TEXT PRIMARY KEY,
|
|
844
|
+
file_name TEXT,
|
|
845
|
+
project_path TEXT,
|
|
846
|
+
line INTEGER,
|
|
847
|
+
column INTEGER,
|
|
848
|
+
data_json TEXT
|
|
849
|
+
);
|
|
850
|
+
`);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
export type * from "./db.js";
|