code-kg 0.1.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/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/cli/index.d.ts +14 -0
- package/dist/cli/index.js +68 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/codekg-config.d.ts +14 -0
- package/dist/codekg-config.js +81 -0
- package/dist/codekg-config.js.map +1 -0
- package/dist/commands/graph.d.ts +7 -0
- package/dist/commands/graph.js +49 -0
- package/dist/commands/graph.js.map +1 -0
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.js +13 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/insights.d.ts +7 -0
- package/dist/commands/insights.js +31 -0
- package/dist/commands/insights.js.map +1 -0
- package/dist/commands/path.d.ts +7 -0
- package/dist/commands/path.js +47 -0
- package/dist/commands/path.js.map +1 -0
- package/dist/commands/reindex.d.ts +6 -0
- package/dist/commands/reindex.js +13 -0
- package/dist/commands/reindex.js.map +1 -0
- package/dist/commands/run.d.ts +6 -0
- package/dist/commands/run.js +20 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/serve.d.ts +8 -0
- package/dist/commands/serve.js +25 -0
- package/dist/commands/serve.js.map +1 -0
- package/dist/config/defaults.d.ts +6 -0
- package/dist/config/defaults.js +30 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +602 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/babel-fallback.d.ts +7 -0
- package/dist/indexer/babel-fallback.js +583 -0
- package/dist/indexer/babel-fallback.js.map +1 -0
- package/dist/indexer/file-discovery.d.ts +6 -0
- package/dist/indexer/file-discovery.js +106 -0
- package/dist/indexer/file-discovery.js.map +1 -0
- package/dist/indexer/indexer.d.ts +90 -0
- package/dist/indexer/indexer.js +620 -0
- package/dist/indexer/indexer.js.map +1 -0
- package/dist/indexer/metrics.d.ts +39 -0
- package/dist/indexer/metrics.js +147 -0
- package/dist/indexer/metrics.js.map +1 -0
- package/dist/indexer/structure-detector.d.ts +16 -0
- package/dist/indexer/structure-detector.js +159 -0
- package/dist/indexer/structure-detector.js.map +1 -0
- package/dist/indexer/ts-parser.d.ts +86 -0
- package/dist/indexer/ts-parser.js +437 -0
- package/dist/indexer/ts-parser.js.map +1 -0
- package/dist/model/edge.d.ts +21 -0
- package/dist/model/edge.js +25 -0
- package/dist/model/edge.js.map +1 -0
- package/dist/model/graph.d.ts +10 -0
- package/dist/model/graph.js +20 -0
- package/dist/model/graph.js.map +1 -0
- package/dist/model/node.d.ts +24 -0
- package/dist/model/node.js +22 -0
- package/dist/model/node.js.map +1 -0
- package/dist/query/query-dsl.d.ts +17 -0
- package/dist/query/query-dsl.js +75 -0
- package/dist/query/query-dsl.js.map +1 -0
- package/dist/query/query-engine.d.ts +32 -0
- package/dist/query/query-engine.js +126 -0
- package/dist/query/query-engine.js.map +1 -0
- package/dist/server/api.d.ts +19 -0
- package/dist/server/api.js +29 -0
- package/dist/server/api.js.map +1 -0
- package/dist/server/app.d.ts +7 -0
- package/dist/server/app.js +509 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/graph-controller.d.ts +147 -0
- package/dist/server/graph-controller.js +186 -0
- package/dist/server/graph-controller.js.map +1 -0
- package/dist/server/routes.d.ts +3 -0
- package/dist/server/routes.js +19 -0
- package/dist/server/routes.js.map +1 -0
- package/dist/server/ui.d.ts +1 -0
- package/dist/server/ui.js +1165 -0
- package/dist/server/ui.js.map +1 -0
- package/dist/store/sqlite-store.d.ts +83 -0
- package/dist/store/sqlite-store.js +647 -0
- package/dist/store/sqlite-store.js.map +1 -0
- package/dist/utils/ids.d.ts +2 -0
- package/dist/utils/ids.js +9 -0
- package/dist/utils/ids.js.map +1 -0
- package/dist/utils/path.d.ts +3 -0
- package/dist/utils/path.js +21 -0
- package/dist/utils/path.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.discoverSourceFiles = discoverSourceFiles;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const DEFAULT_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx"]);
|
|
40
|
+
const DEFAULT_EXCLUDED_DIRECTORIES = new Set([
|
|
41
|
+
"node_modules",
|
|
42
|
+
".git",
|
|
43
|
+
"dist",
|
|
44
|
+
"build",
|
|
45
|
+
"coverage",
|
|
46
|
+
".next",
|
|
47
|
+
"out",
|
|
48
|
+
]);
|
|
49
|
+
function walkDirectory(directoryPath, rootPath, includeExtensions, excludedDirectories, output) {
|
|
50
|
+
const entries = fs.readdirSync(directoryPath, { withFileTypes: true });
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
if (entry.isSymbolicLink()) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const absolutePath = path.join(directoryPath, entry.name);
|
|
56
|
+
if (entry.isDirectory()) {
|
|
57
|
+
if (excludedDirectories.has(entry.name)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
walkDirectory(absolutePath, rootPath, includeExtensions, excludedDirectories, output);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!entry.isFile()) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const extension = path.extname(entry.name).toLowerCase();
|
|
67
|
+
if (!includeExtensions.has(extension)) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (entry.name.endsWith(".d.ts")) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const relativePath = path.relative(rootPath, absolutePath);
|
|
74
|
+
if (relativePath.startsWith("..")) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
output.add(path.resolve(absolutePath));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function discoverSourceFiles(rootPath, options = {}) {
|
|
81
|
+
const normalizedRoot = path.resolve(rootPath);
|
|
82
|
+
const includeExtensions = new Set(options.includeExtensions ?? [...DEFAULT_EXTENSIONS]);
|
|
83
|
+
const excludedDirectories = new Set(options.excludeDirectories ?? [...DEFAULT_EXCLUDED_DIRECTORIES]);
|
|
84
|
+
const candidateRoots = options.sourceDirectories && options.sourceDirectories.length > 0
|
|
85
|
+
? options.sourceDirectories.map((dirPath) => path.isAbsolute(dirPath) ? dirPath : path.join(normalizedRoot, dirPath))
|
|
86
|
+
: [normalizedRoot];
|
|
87
|
+
const roots = candidateRoots
|
|
88
|
+
.map((dirPath) => path.resolve(dirPath))
|
|
89
|
+
.filter((dirPath) => {
|
|
90
|
+
if (!fs.existsSync(dirPath)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return fs.statSync(dirPath).isDirectory();
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const output = new Set();
|
|
101
|
+
for (const sourceRoot of roots) {
|
|
102
|
+
walkDirectory(sourceRoot, normalizedRoot, includeExtensions, excludedDirectories, output);
|
|
103
|
+
}
|
|
104
|
+
return [...output].sort();
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=file-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-discovery.js","sourceRoot":"","sources":["../../src/indexer/file-discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,kDAiCC;AAnGD,4CAA8B;AAC9B,gDAAkC;AAQlC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AACnE,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC;IAC3C,cAAc;IACd,MAAM;IACN,MAAM;IACN,OAAO;IACP,UAAU;IACV,OAAO;IACP,KAAK;CACN,CAAC,CAAC;AAEH,SAAS,aAAa,CACpB,aAAqB,EACrB,QAAgB,EAChB,iBAA8B,EAC9B,mBAAgC,EAChC,MAAmB;IAEnB,MAAM,OAAO,GA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AE,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type DependencyEdge, type DerivedMetrics } from "./metrics";
|
|
2
|
+
import { type ProjectStructure } from "./structure-detector";
|
|
3
|
+
import { type CallRecord, type ClassRecord, type ExportRecord, type FunctionRecord, type ImportRecord, type InterfaceRecord, type ReferenceRecord, type RouteRecord, type VariableRecord } from "./ts-parser";
|
|
4
|
+
import { type GraphData as SharedGraphData } from "../model/graph";
|
|
5
|
+
export interface IndexedFile {
|
|
6
|
+
filePath: string;
|
|
7
|
+
relativePath: string;
|
|
8
|
+
parser: "typescript" | "babel" | "none";
|
|
9
|
+
parseError?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GraphImport extends ImportRecord {
|
|
12
|
+
filePath: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GraphExport extends ExportRecord {
|
|
15
|
+
filePath: string;
|
|
16
|
+
}
|
|
17
|
+
export interface GraphFunction extends FunctionRecord {
|
|
18
|
+
filePath: string;
|
|
19
|
+
}
|
|
20
|
+
export interface GraphClass extends ClassRecord {
|
|
21
|
+
filePath: string;
|
|
22
|
+
}
|
|
23
|
+
export interface GraphInterface extends InterfaceRecord {
|
|
24
|
+
filePath: string;
|
|
25
|
+
}
|
|
26
|
+
export interface GraphVariable extends VariableRecord {
|
|
27
|
+
filePath: string;
|
|
28
|
+
}
|
|
29
|
+
export interface GraphReference extends ReferenceRecord {
|
|
30
|
+
filePath: string;
|
|
31
|
+
}
|
|
32
|
+
export interface GraphCall extends CallRecord {
|
|
33
|
+
filePath: string;
|
|
34
|
+
}
|
|
35
|
+
export interface GraphMetaSummary {
|
|
36
|
+
generatedAt: string;
|
|
37
|
+
rootPath: string;
|
|
38
|
+
packageName?: string;
|
|
39
|
+
frameworks: string[];
|
|
40
|
+
parser: {
|
|
41
|
+
typescriptCount: number;
|
|
42
|
+
babelFallbackCount: number;
|
|
43
|
+
parseFailures: number;
|
|
44
|
+
};
|
|
45
|
+
totals: {
|
|
46
|
+
files: number;
|
|
47
|
+
imports: number;
|
|
48
|
+
exports: number;
|
|
49
|
+
functions: number;
|
|
50
|
+
classes: number;
|
|
51
|
+
interfaces: number;
|
|
52
|
+
variables: number;
|
|
53
|
+
references: number;
|
|
54
|
+
calls: number;
|
|
55
|
+
routes: number;
|
|
56
|
+
dependencies: number;
|
|
57
|
+
};
|
|
58
|
+
metrics: {
|
|
59
|
+
cycles: number;
|
|
60
|
+
unusedExports: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface GraphData extends SharedGraphData {
|
|
64
|
+
rootPath: string;
|
|
65
|
+
structure: ProjectStructure;
|
|
66
|
+
projectStructure: ProjectStructure;
|
|
67
|
+
files: IndexedFile[];
|
|
68
|
+
imports: GraphImport[];
|
|
69
|
+
exports: GraphExport[];
|
|
70
|
+
functions: GraphFunction[];
|
|
71
|
+
classes: GraphClass[];
|
|
72
|
+
interfaces: GraphInterface[];
|
|
73
|
+
variables: GraphVariable[];
|
|
74
|
+
references: GraphReference[];
|
|
75
|
+
calls: GraphCall[];
|
|
76
|
+
routes: RouteRecord[];
|
|
77
|
+
dependencies: DependencyEdge[];
|
|
78
|
+
fileDependencies: DependencyEdge[];
|
|
79
|
+
metrics: DerivedMetrics;
|
|
80
|
+
meta: GraphMetaSummary;
|
|
81
|
+
summary: GraphMetaSummary;
|
|
82
|
+
}
|
|
83
|
+
export declare function buildGraphFromPath(rootPath: string): GraphData;
|
|
84
|
+
export declare const buildGraph: typeof buildGraphFromPath;
|
|
85
|
+
export declare const buildCodeGraph: typeof buildGraphFromPath;
|
|
86
|
+
export declare const indexProject: typeof buildGraphFromPath;
|
|
87
|
+
export declare function runIndexer(input?: string | {
|
|
88
|
+
path?: string;
|
|
89
|
+
rootPath?: string;
|
|
90
|
+
}): GraphData;
|