rho-graph 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/README.md +277 -0
- package/bin/rho-graph.js +2 -0
- package/dist/cli/commands/index-cmd.d.ts +2 -0
- package/dist/cli/commands/index-cmd.js +45 -0
- package/dist/cli/commands/index-cmd.js.map +1 -0
- package/dist/cli/commands/init.d.ts +3 -0
- package/dist/cli/commands/init.js +55 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/install-hook.d.ts +3 -0
- package/dist/cli/commands/install-hook.js +37 -0
- package/dist/cli/commands/install-hook.js.map +1 -0
- package/dist/cli/commands/install-mcp.d.ts +3 -0
- package/dist/cli/commands/install-mcp.js +32 -0
- package/dist/cli/commands/install-mcp.js.map +1 -0
- package/dist/cli/commands/query.d.ts +2 -0
- package/dist/cli/commands/query.js +92 -0
- package/dist/cli/commands/query.js.map +1 -0
- package/dist/cli/commands/setup.d.ts +2 -0
- package/dist/cli/commands/setup.js +15 -0
- package/dist/cli/commands/setup.js.map +1 -0
- package/dist/cli/commands/status.d.ts +2 -0
- package/dist/cli/commands/status.js +40 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/visualize.d.ts +2 -0
- package/dist/cli/commands/visualize.js +45 -0
- package/dist/cli/commands/visualize.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +32 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config.d.ts +22 -0
- package/dist/config.js +95 -0
- package/dist/config.js.map +1 -0
- package/dist/db/connection.d.ts +13 -0
- package/dist/db/connection.js +25 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/db/queries.d.ts +106 -0
- package/dist/db/queries.js +247 -0
- package/dist/db/queries.js.map +1 -0
- package/dist/db/schema.d.ts +2 -0
- package/dist/db/schema.js +22 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/docker/neo4j.d.ts +5 -0
- package/dist/docker/neo4j.js +85 -0
- package/dist/docker/neo4j.js.map +1 -0
- package/dist/indexer/batch-writer.d.ts +35 -0
- package/dist/indexer/batch-writer.js +202 -0
- package/dist/indexer/batch-writer.js.map +1 -0
- package/dist/indexer/extractor.d.ts +35 -0
- package/dist/indexer/extractor.js +141 -0
- package/dist/indexer/extractor.js.map +1 -0
- package/dist/indexer/graph-writer.d.ts +12 -0
- package/dist/indexer/graph-writer.js +75 -0
- package/dist/indexer/graph-writer.js.map +1 -0
- package/dist/indexer/import-resolver.d.ts +8 -0
- package/dist/indexer/import-resolver.js +80 -0
- package/dist/indexer/import-resolver.js.map +1 -0
- package/dist/indexer/index.d.ts +21 -0
- package/dist/indexer/index.js +262 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/language-map.json +101 -0
- package/dist/indexer/parallel-pipeline.d.ts +41 -0
- package/dist/indexer/parallel-pipeline.js +82 -0
- package/dist/indexer/parallel-pipeline.js.map +1 -0
- package/dist/indexer/parser.d.ts +9 -0
- package/dist/indexer/parser.js +85 -0
- package/dist/indexer/parser.js.map +1 -0
- package/dist/indexer/staleness.d.ts +12 -0
- package/dist/indexer/staleness.js +60 -0
- package/dist/indexer/staleness.js.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.js +38 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/staleness-check.d.ts +7 -0
- package/dist/mcp/staleness-check.js +31 -0
- package/dist/mcp/staleness-check.js.map +1 -0
- package/dist/mcp/tools/get-callees.d.ts +3 -0
- package/dist/mcp/tools/get-callees.js +34 -0
- package/dist/mcp/tools/get-callees.js.map +1 -0
- package/dist/mcp/tools/get-callers.d.ts +3 -0
- package/dist/mcp/tools/get-callers.js +34 -0
- package/dist/mcp/tools/get-callers.js.map +1 -0
- package/dist/mcp/tools/get-class.d.ts +3 -0
- package/dist/mcp/tools/get-class.js +42 -0
- package/dist/mcp/tools/get-class.js.map +1 -0
- package/dist/mcp/tools/get-dependencies.d.ts +3 -0
- package/dist/mcp/tools/get-dependencies.js +26 -0
- package/dist/mcp/tools/get-dependencies.js.map +1 -0
- package/dist/mcp/tools/get-dependents.d.ts +3 -0
- package/dist/mcp/tools/get-dependents.js +26 -0
- package/dist/mcp/tools/get-dependents.js.map +1 -0
- package/dist/mcp/tools/get-file-structure.d.ts +3 -0
- package/dist/mcp/tools/get-file-structure.js +33 -0
- package/dist/mcp/tools/get-file-structure.js.map +1 -0
- package/dist/mcp/tools/get-function.d.ts +3 -0
- package/dist/mcp/tools/get-function.js +34 -0
- package/dist/mcp/tools/get-function.js.map +1 -0
- package/dist/mcp/tools/get-repo-structure.d.ts +3 -0
- package/dist/mcp/tools/get-repo-structure.js +39 -0
- package/dist/mcp/tools/get-repo-structure.js.map +1 -0
- package/dist/mcp/tools/reindex.d.ts +4 -0
- package/dist/mcp/tools/reindex.js +27 -0
- package/dist/mcp/tools/reindex.js.map +1 -0
- package/dist/mcp/tools/search-code.d.ts +3 -0
- package/dist/mcp/tools/search-code.js +43 -0
- package/dist/mcp/tools/search-code.js.map +1 -0
- package/dist/visualize/public/graph.js +445 -0
- package/dist/visualize/public/index.html +88 -0
- package/dist/visualize/queries.d.ts +14 -0
- package/dist/visualize/queries.js +84 -0
- package/dist/visualize/queries.js.map +1 -0
- package/dist/visualize/server.d.ts +19 -0
- package/dist/visualize/server.js +293 -0
- package/dist/visualize/server.js.map +1 -0
- package/docker-compose.yml +16 -0
- package/package.json +69 -0
- package/src/indexer/language-map.json +128 -0
- package/src/visualize/public/graph.js +445 -0
- package/src/visualize/public/index.html +88 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { loadConfig } from "../../config.js";
|
|
3
|
+
import { createConnection } from "../../db/connection.js";
|
|
4
|
+
export function registerStatusCommand(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("status")
|
|
7
|
+
.description("Show index status")
|
|
8
|
+
.action(async () => {
|
|
9
|
+
const repoPath = resolve(".");
|
|
10
|
+
const config = loadConfig(repoPath);
|
|
11
|
+
const db = createConnection(config.neo4j);
|
|
12
|
+
const healthy = await db.healthCheck();
|
|
13
|
+
if (!healthy) {
|
|
14
|
+
console.log("Neo4j is not running. Run `code-graph-rag init` to start it.");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const session = db.session();
|
|
18
|
+
try {
|
|
19
|
+
const repos = await session.run("MATCH (r:Repository) RETURN r.name AS name, r.path AS path, r.lastIndexedAt AS lastIndexed");
|
|
20
|
+
const files = await session.run("MATCH (f:File) RETURN f.language AS language, count(f) AS count");
|
|
21
|
+
const functions = await session.run("MATCH (fn:Function) RETURN count(fn) AS count");
|
|
22
|
+
const classes = await session.run("MATCH (c:Class) RETURN count(c) AS count");
|
|
23
|
+
console.log("\nRepositories:");
|
|
24
|
+
for (const r of repos.records) {
|
|
25
|
+
console.log(` ${r.get("name")} (${r.get("path")}) — last indexed: ${r.get("lastIndexed")}`);
|
|
26
|
+
}
|
|
27
|
+
console.log("\nFiles by language:");
|
|
28
|
+
for (const f of files.records) {
|
|
29
|
+
console.log(` ${f.get("language")}: ${f.get("count")}`);
|
|
30
|
+
}
|
|
31
|
+
console.log(`\nFunctions: ${functions.records[0]?.get("count") ?? 0}`);
|
|
32
|
+
console.log(`Classes: ${classes.records[0]?.get("count") ?? 0}`);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
await session.close();
|
|
36
|
+
await db.close();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/cli/commands/status.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,M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,sBAAsB,CAAC,CAAC;YACpC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC3D,CAAC;YAED,OAAO,CAAC,GAAG,CACT,gBAAgB,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAC1D,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,YAAY,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnE,CAAC;gBAAS,CAAC;YACT,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACtB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { resolve, dirname } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { loadConfig } from "../../config.js";
|
|
5
|
+
import { isDockerAvailable, startNeo4j, waitForNeo4j } from "../../docker/neo4j.js";
|
|
6
|
+
import { startVisualizationServer } from "../../visualize/server.js";
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
export function registerVisualizeCommand(program) {
|
|
9
|
+
program
|
|
10
|
+
.command("visualize")
|
|
11
|
+
.description("Open browser-based graph visualization")
|
|
12
|
+
.option("--repo <name>", "Filter by repository")
|
|
13
|
+
.option("--file <path>", "Focus on a specific file")
|
|
14
|
+
.option("--function <name>", "Focus on a specific function")
|
|
15
|
+
.option("--port <port>", "Server port", "3333")
|
|
16
|
+
.action(async (opts) => {
|
|
17
|
+
const repoPath = resolve(".");
|
|
18
|
+
const config = loadConfig(repoPath);
|
|
19
|
+
if (config.neo4j.managed) {
|
|
20
|
+
if (!isDockerAvailable()) {
|
|
21
|
+
console.error("Docker is not available. Install Docker or set neo4j.managed to false.");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const spinner = ora("Starting Neo4j...").start();
|
|
25
|
+
const composePath = resolve(__dirname, "../../../docker-compose.yml");
|
|
26
|
+
startNeo4j(composePath);
|
|
27
|
+
const ready = await waitForNeo4j(config.neo4j.uri, config.neo4j.username, config.neo4j.password);
|
|
28
|
+
if (!ready) {
|
|
29
|
+
spinner.fail("Neo4j failed to start");
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
spinner.succeed("Neo4j running");
|
|
33
|
+
}
|
|
34
|
+
await startVisualizationServer({
|
|
35
|
+
neo4jConfig: config.neo4j,
|
|
36
|
+
port: parseInt(opts.port),
|
|
37
|
+
filter: {
|
|
38
|
+
repo: opts.repo,
|
|
39
|
+
file: opts.file,
|
|
40
|
+
function: opts.function,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=visualize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visualize.js","sourceRoot":"","sources":["../../../src/cli/commands/visualize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CA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AC,OAAO,CAAC,eAAe,CAAC,CAAC;QACnC,CAAC;QAED,MAAM,wBAAwB,CAAC;YAC7B,WAAW,EAAE,MAAM,CAAC,KAAK;YACzB,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;YACzB,MAAM,EAAE;gBACN,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/cli/index.ts
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { registerInitCommand } from "./commands/init.js";
|
|
4
|
+
import { registerIndexCommand } from "./commands/index-cmd.js";
|
|
5
|
+
import { registerStatusCommand } from "./commands/status.js";
|
|
6
|
+
import { registerSetupCommand } from "./commands/setup.js";
|
|
7
|
+
import { registerInstallMcpCommand } from "./commands/install-mcp.js";
|
|
8
|
+
import { registerInstallHookCommand } from "./commands/install-hook.js";
|
|
9
|
+
import { registerQueryCommand } from "./commands/query.js";
|
|
10
|
+
import { registerVisualizeCommand } from "./commands/visualize.js";
|
|
11
|
+
const program = new Command();
|
|
12
|
+
program
|
|
13
|
+
.name("code-graph-rag")
|
|
14
|
+
.description("Graph-RAG code indexer — token-efficient code search for AI agents")
|
|
15
|
+
.version("0.1.0");
|
|
16
|
+
registerInitCommand(program);
|
|
17
|
+
registerIndexCommand(program);
|
|
18
|
+
registerStatusCommand(program);
|
|
19
|
+
registerSetupCommand(program);
|
|
20
|
+
registerInstallMcpCommand(program);
|
|
21
|
+
registerInstallHookCommand(program);
|
|
22
|
+
registerQueryCommand(program);
|
|
23
|
+
registerVisualizeCommand(program);
|
|
24
|
+
program
|
|
25
|
+
.command("mcp-serve")
|
|
26
|
+
.description("Start the MCP server (used by Claude Code)")
|
|
27
|
+
.action(async () => {
|
|
28
|
+
const { startMcpServer } = await import("../mcp/index.js");
|
|
29
|
+
await startMcpServer();
|
|
30
|
+
});
|
|
31
|
+
program.parse();
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,gBAAgB,CAAC;KACtB,WAAW,CACV,oEAAoE,CACrE;KACA,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC7B,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC9B,qBAAqB,CAAC,OAAO,CAAC,CAAC;AAC/B,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC9B,yBAAyB,CAAC,OAAO,CAAC,CAAC;AACnC,0BAA0B,CAAC,OAAO,CAAC,CAAC;AACpC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC9B,wBAAwB,CAAC,OAAO,CAAC,CAAC;AAElC,OAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,4CAA4C,CAAC;KACzD,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC3D,MAAM,cAAc,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Neo4jConfig {
|
|
2
|
+
uri: string;
|
|
3
|
+
username: string;
|
|
4
|
+
password: string;
|
|
5
|
+
managed: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface IndexConfig {
|
|
8
|
+
include: string[];
|
|
9
|
+
exclude: string[];
|
|
10
|
+
languages: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RepoEntry {
|
|
13
|
+
path: string;
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Config {
|
|
17
|
+
neo4j: Neo4jConfig;
|
|
18
|
+
index: IndexConfig;
|
|
19
|
+
repos: RepoEntry[];
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_CONFIG: Config;
|
|
22
|
+
export declare function loadConfig(repoRoot: string): Config;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
export const DEFAULT_CONFIG = {
|
|
5
|
+
neo4j: {
|
|
6
|
+
uri: "bolt://localhost:7687",
|
|
7
|
+
username: "neo4j",
|
|
8
|
+
password: "code-graph-rag",
|
|
9
|
+
managed: true,
|
|
10
|
+
},
|
|
11
|
+
index: {
|
|
12
|
+
include: ["**/*"],
|
|
13
|
+
exclude: [
|
|
14
|
+
// VCS
|
|
15
|
+
".git",
|
|
16
|
+
// JS/TS dependencies, build outputs, framework caches
|
|
17
|
+
"node_modules",
|
|
18
|
+
"bower_components",
|
|
19
|
+
"dist",
|
|
20
|
+
"build",
|
|
21
|
+
"vendor",
|
|
22
|
+
".next",
|
|
23
|
+
".nuxt",
|
|
24
|
+
"coverage",
|
|
25
|
+
".nyc_output",
|
|
26
|
+
// Python virtual environments and vendored packages
|
|
27
|
+
"venv",
|
|
28
|
+
".venv",
|
|
29
|
+
"virtualenv",
|
|
30
|
+
".tox",
|
|
31
|
+
"site-packages",
|
|
32
|
+
// Python tool caches
|
|
33
|
+
"__pycache__",
|
|
34
|
+
".pytest_cache",
|
|
35
|
+
".mypy_cache",
|
|
36
|
+
".ruff_cache",
|
|
37
|
+
// Rust / JVM build outputs
|
|
38
|
+
"target",
|
|
39
|
+
".gradle",
|
|
40
|
+
// IDE state
|
|
41
|
+
".idea",
|
|
42
|
+
".vscode",
|
|
43
|
+
// Generic caches
|
|
44
|
+
".cache",
|
|
45
|
+
],
|
|
46
|
+
languages: "auto",
|
|
47
|
+
},
|
|
48
|
+
repos: [],
|
|
49
|
+
};
|
|
50
|
+
function deepMerge(base, override) {
|
|
51
|
+
const result = structuredClone(base);
|
|
52
|
+
if (override.neo4j) {
|
|
53
|
+
result.neo4j = { ...result.neo4j, ...override.neo4j };
|
|
54
|
+
}
|
|
55
|
+
if (override.index) {
|
|
56
|
+
result.index = { ...result.index, ...override.index };
|
|
57
|
+
}
|
|
58
|
+
if (override.repos) {
|
|
59
|
+
result.repos = override.repos;
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
function loadJsonFile(filePath) {
|
|
64
|
+
if (!existsSync(filePath))
|
|
65
|
+
return null;
|
|
66
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
67
|
+
return JSON.parse(raw);
|
|
68
|
+
}
|
|
69
|
+
export function loadConfig(repoRoot) {
|
|
70
|
+
let config = structuredClone(DEFAULT_CONFIG);
|
|
71
|
+
// Global config: ~/.config/code-graph-rag/config.json
|
|
72
|
+
const globalPath = join(homedir(), ".config", "code-graph-rag", "config.json");
|
|
73
|
+
const globalOverrides = loadJsonFile(globalPath);
|
|
74
|
+
if (globalOverrides) {
|
|
75
|
+
config = deepMerge(config, globalOverrides);
|
|
76
|
+
}
|
|
77
|
+
// Repo config: .code-graph-rag.json in repo root
|
|
78
|
+
const repoPath = join(repoRoot, ".code-graph-rag.json");
|
|
79
|
+
const repoOverrides = loadJsonFile(repoPath);
|
|
80
|
+
if (repoOverrides) {
|
|
81
|
+
config = deepMerge(config, repoOverrides);
|
|
82
|
+
}
|
|
83
|
+
// Environment variable overrides
|
|
84
|
+
if (process.env.NEO4J_URI) {
|
|
85
|
+
config.neo4j.uri = process.env.NEO4J_URI;
|
|
86
|
+
}
|
|
87
|
+
if (process.env.NEO4J_USERNAME) {
|
|
88
|
+
config.neo4j.username = process.env.NEO4J_USERNAME;
|
|
89
|
+
}
|
|
90
|
+
if (process.env.NEO4J_PASSWORD) {
|
|
91
|
+
config.neo4j.password = process.env.NEO4J_PASSWORD;
|
|
92
|
+
}
|
|
93
|
+
return config;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA0BlC,MAAM,CAAC,MAAM,cAAc,GAAW;IACpC,KAAK,EAAE;QACL,GAAG,EAAE,uBAAuB;QAC5B,QAAQ,EAAE,OAAO;QACjB,QAAQ,EAAE,gBAAgB;QAC1B,OAAO,EAAE,IAAI;KACd;IACD,KAAK,EAAE;QACL,OAAO,EAAE,CAAC,MAAM,CAAC;QACjB,OAAO,EAAE;YACP,MAAM;YACN,MAAM;YACN,sDAAsD;YACtD,c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AAM,GAAW,eAAe,CAAC,cAAc,CAAC,CAAC;IAErD,sDAAsD;IACtD,MAAM,UAAU,GAAG,IAAI,CACrB,OAAO,EAAE,EACT,SAAS,EACT,gBAAgB,EAChB,aAAa,CACd,CAAC;IACF,MAAM,eAAe,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IACjD,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,eAAkC,CAAC,CAAC;IACjE,CAAC;IAED,iDAAiD;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,aAAa,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,aAAgC,CAAC,CAAC;IAC/D,CAAC;IAED,iCAAiC;IACjC,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QAC1B,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAC3C,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAC/B,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACrD,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAC/B,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACrD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Driver, type Session } from "neo4j-driver";
|
|
2
|
+
export interface ConnectionConfig {
|
|
3
|
+
uri: string;
|
|
4
|
+
username: string;
|
|
5
|
+
password: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DbConnection {
|
|
8
|
+
driver: Driver;
|
|
9
|
+
session(): Session;
|
|
10
|
+
healthCheck(): Promise<boolean>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createConnection(config: ConnectionConfig): DbConnection;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import neo4j from "neo4j-driver";
|
|
2
|
+
export function createConnection(config) {
|
|
3
|
+
const driver = neo4j.driver(config.uri, neo4j.auth.basic(config.username, config.password));
|
|
4
|
+
return {
|
|
5
|
+
driver,
|
|
6
|
+
session() {
|
|
7
|
+
return driver.session();
|
|
8
|
+
},
|
|
9
|
+
async healthCheck() {
|
|
10
|
+
try {
|
|
11
|
+
const session = driver.session();
|
|
12
|
+
await session.run("RETURN 1");
|
|
13
|
+
await session.close();
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
async close() {
|
|
21
|
+
await driver.close();
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/db/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,cAAc,CAAC;AAehE,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACvD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CACzB,MAAM,CAAC,GAAG,EACV,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CACnD,CAAC;IAEF,OAAO;QACL,MAAM;QACN,OAAO;YACL,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC;QACD,KAAK,CAAC,WAAW;YACf,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;gBACjC,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAC9B,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,KAAK,CAAC,KAAK;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export interface CypherQuery {
|
|
2
|
+
cypher: string;
|
|
3
|
+
params: Record<string, unknown>;
|
|
4
|
+
}
|
|
5
|
+
export declare function upsertRepository(data: {
|
|
6
|
+
path: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}): CypherQuery;
|
|
9
|
+
export declare function upsertFile(data: {
|
|
10
|
+
path: string;
|
|
11
|
+
relativePath: string;
|
|
12
|
+
repoPath: string;
|
|
13
|
+
language: string;
|
|
14
|
+
hash: string;
|
|
15
|
+
lastModified: number;
|
|
16
|
+
}): CypherQuery;
|
|
17
|
+
export declare function upsertFunction(data: {
|
|
18
|
+
name: string;
|
|
19
|
+
filePath: string;
|
|
20
|
+
startLine: number;
|
|
21
|
+
endLine: number;
|
|
22
|
+
signature: string;
|
|
23
|
+
docstring: string | null;
|
|
24
|
+
snippet: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
}): CypherQuery;
|
|
27
|
+
export declare function upsertClass(data: {
|
|
28
|
+
name: string;
|
|
29
|
+
filePath: string;
|
|
30
|
+
startLine: number;
|
|
31
|
+
endLine: number;
|
|
32
|
+
docstring: string | null;
|
|
33
|
+
}): CypherQuery;
|
|
34
|
+
export declare function upsertCallRelationship(data: {
|
|
35
|
+
callerName: string;
|
|
36
|
+
callerFilePath: string;
|
|
37
|
+
calleeName: string;
|
|
38
|
+
}): CypherQuery;
|
|
39
|
+
export declare function upsertImportRelationship(data: {
|
|
40
|
+
sourceFilePath: string;
|
|
41
|
+
targetFilePath: string;
|
|
42
|
+
}): CypherQuery;
|
|
43
|
+
export declare function upsertImportSymbol(data: {
|
|
44
|
+
sourceFilePath: string;
|
|
45
|
+
symbolName: string;
|
|
46
|
+
}): CypherQuery;
|
|
47
|
+
export declare function batchUpsertFiles(items: Array<{
|
|
48
|
+
path: string;
|
|
49
|
+
relativePath: string;
|
|
50
|
+
repoPath: string;
|
|
51
|
+
language: string;
|
|
52
|
+
hash: string;
|
|
53
|
+
lastModified: number;
|
|
54
|
+
}>): CypherQuery;
|
|
55
|
+
export declare function batchDeleteFileChildren(filePaths: string[]): CypherQuery;
|
|
56
|
+
export declare function batchUpsertFunctions(items: Array<{
|
|
57
|
+
name: string;
|
|
58
|
+
filePath: string;
|
|
59
|
+
startLine: number;
|
|
60
|
+
endLine: number;
|
|
61
|
+
signature: string;
|
|
62
|
+
docstring: string | null;
|
|
63
|
+
snippet: string;
|
|
64
|
+
className: string | null;
|
|
65
|
+
}>): CypherQuery;
|
|
66
|
+
export declare function batchUpsertMethods(items: Array<{
|
|
67
|
+
name: string;
|
|
68
|
+
filePath: string;
|
|
69
|
+
startLine: number;
|
|
70
|
+
endLine: number;
|
|
71
|
+
signature: string;
|
|
72
|
+
docstring: string | null;
|
|
73
|
+
snippet: string;
|
|
74
|
+
className: string;
|
|
75
|
+
}>): CypherQuery;
|
|
76
|
+
export declare function batchUpsertClasses(items: Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
filePath: string;
|
|
79
|
+
startLine: number;
|
|
80
|
+
endLine: number;
|
|
81
|
+
docstring: string | null;
|
|
82
|
+
}>): CypherQuery;
|
|
83
|
+
export declare function batchUpsertImportRelationships(items: Array<{
|
|
84
|
+
sourceFilePath: string;
|
|
85
|
+
targetFilePath: string;
|
|
86
|
+
}>): CypherQuery;
|
|
87
|
+
export declare function batchUpsertCallRelationships(items: Array<{
|
|
88
|
+
callerName: string;
|
|
89
|
+
callerFilePath: string;
|
|
90
|
+
calleeName: string;
|
|
91
|
+
}>): CypherQuery;
|
|
92
|
+
export declare function upsertRepositoryWithCommit(data: {
|
|
93
|
+
path: string;
|
|
94
|
+
name: string;
|
|
95
|
+
lastIndexedCommit: string;
|
|
96
|
+
}): CypherQuery;
|
|
97
|
+
export declare function getRepositoryCommit(data: {
|
|
98
|
+
path: string;
|
|
99
|
+
}): CypherQuery;
|
|
100
|
+
export declare function deleteFileAndRelationships(data: {
|
|
101
|
+
filePath: string;
|
|
102
|
+
}): CypherQuery;
|
|
103
|
+
export declare function getAllFilePathsUnderPrefix(data: {
|
|
104
|
+
pathPrefix: string;
|
|
105
|
+
}): CypherQuery;
|
|
106
|
+
export declare function batchDeleteOrphanFiles(filePaths: string[]): CypherQuery;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// src/db/queries.ts
|
|
2
|
+
export function upsertRepository(data) {
|
|
3
|
+
return {
|
|
4
|
+
cypher: `
|
|
5
|
+
MERGE (r:Repository {path: $path})
|
|
6
|
+
SET r.name = $name, r.lastIndexedAt = datetime()
|
|
7
|
+
`,
|
|
8
|
+
params: data,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function upsertFile(data) {
|
|
12
|
+
return {
|
|
13
|
+
cypher: `
|
|
14
|
+
MATCH (r:Repository {path: $repoPath})
|
|
15
|
+
MERGE (f:File {path: $path})
|
|
16
|
+
SET f.relativePath = $relativePath,
|
|
17
|
+
f.language = $language,
|
|
18
|
+
f.hash = $hash,
|
|
19
|
+
f.lastModified = $lastModified
|
|
20
|
+
MERGE (r)-[:CONTAINS_FILE]->(f)
|
|
21
|
+
`,
|
|
22
|
+
params: data,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function upsertFunction(data) {
|
|
26
|
+
if (data.className) {
|
|
27
|
+
return {
|
|
28
|
+
cypher: `
|
|
29
|
+
MATCH (c:Class {name: $className})<-[:CONTAINS]-(:File {path: $filePath})
|
|
30
|
+
MERGE (fn:Function {name: $name, filePath: $filePath, className: $className})
|
|
31
|
+
SET fn.startLine = $startLine,
|
|
32
|
+
fn.endLine = $endLine,
|
|
33
|
+
fn.signature = $signature,
|
|
34
|
+
fn.docstring = $docstring,
|
|
35
|
+
fn.snippet = $snippet
|
|
36
|
+
MERGE (c)-[:HAS_METHOD]->(fn)
|
|
37
|
+
`,
|
|
38
|
+
params: data,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
cypher: `
|
|
43
|
+
MATCH (f:File {path: $filePath})
|
|
44
|
+
MERGE (fn:Function {name: $name, filePath: $filePath})
|
|
45
|
+
ON CREATE SET fn.className = null
|
|
46
|
+
SET fn.startLine = $startLine,
|
|
47
|
+
fn.endLine = $endLine,
|
|
48
|
+
fn.signature = $signature,
|
|
49
|
+
fn.docstring = $docstring,
|
|
50
|
+
fn.snippet = $snippet
|
|
51
|
+
MERGE (f)-[:CONTAINS]->(fn)
|
|
52
|
+
`,
|
|
53
|
+
params: { ...data, className: null },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function upsertClass(data) {
|
|
57
|
+
return {
|
|
58
|
+
cypher: `
|
|
59
|
+
MATCH (f:File {path: $filePath})
|
|
60
|
+
MERGE (c:Class {name: $name, filePath: $filePath})
|
|
61
|
+
SET c.startLine = $startLine,
|
|
62
|
+
c.endLine = $endLine,
|
|
63
|
+
c.docstring = $docstring
|
|
64
|
+
MERGE (f)-[:CONTAINS]->(c)
|
|
65
|
+
`,
|
|
66
|
+
params: data,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function upsertCallRelationship(data) {
|
|
70
|
+
return {
|
|
71
|
+
cypher: `
|
|
72
|
+
MATCH (caller:Function {name: $callerName, filePath: $callerFilePath})
|
|
73
|
+
MATCH (callee:Function {name: $calleeName})
|
|
74
|
+
MERGE (caller)-[:CALLS]->(callee)
|
|
75
|
+
`,
|
|
76
|
+
params: data,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function upsertImportRelationship(data) {
|
|
80
|
+
return {
|
|
81
|
+
cypher: `
|
|
82
|
+
MATCH (source:File {path: $sourceFilePath})
|
|
83
|
+
MATCH (target:File {path: $targetFilePath})
|
|
84
|
+
MERGE (source)-[:IMPORTS]->(target)
|
|
85
|
+
`,
|
|
86
|
+
params: data,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function upsertImportSymbol(data) {
|
|
90
|
+
return {
|
|
91
|
+
cypher: `
|
|
92
|
+
MATCH (source:File {path: $sourceFilePath})
|
|
93
|
+
MATCH (symbol) WHERE (symbol:Function OR symbol:Class) AND symbol.name = $symbolName
|
|
94
|
+
MERGE (source)-[:IMPORTS_SYMBOL]->(symbol)
|
|
95
|
+
`,
|
|
96
|
+
params: data,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function batchUpsertFiles(items) {
|
|
100
|
+
return {
|
|
101
|
+
cypher: `
|
|
102
|
+
UNWIND $items AS item
|
|
103
|
+
MATCH (r:Repository {path: item.repoPath})
|
|
104
|
+
MERGE (f:File {path: item.path})
|
|
105
|
+
SET f.relativePath = item.relativePath,
|
|
106
|
+
f.language = item.language,
|
|
107
|
+
f.hash = item.hash,
|
|
108
|
+
f.lastModified = item.lastModified
|
|
109
|
+
MERGE (r)-[:CONTAINS_FILE]->(f)
|
|
110
|
+
`,
|
|
111
|
+
params: { items },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export function batchDeleteFileChildren(filePaths) {
|
|
115
|
+
return {
|
|
116
|
+
cypher: `
|
|
117
|
+
UNWIND $filePaths AS fp
|
|
118
|
+
MATCH (f:File {path: fp})-[:CONTAINS]->(child)
|
|
119
|
+
OPTIONAL MATCH (child)-[:HAS_METHOD]->(method)
|
|
120
|
+
DETACH DELETE method, child
|
|
121
|
+
`,
|
|
122
|
+
params: { filePaths },
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export function batchUpsertFunctions(items) {
|
|
126
|
+
return {
|
|
127
|
+
cypher: `
|
|
128
|
+
UNWIND $items AS item
|
|
129
|
+
MATCH (f:File {path: item.filePath})
|
|
130
|
+
MERGE (fn:Function {name: item.name, filePath: item.filePath})
|
|
131
|
+
ON CREATE SET fn.className = null
|
|
132
|
+
SET fn.startLine = item.startLine,
|
|
133
|
+
fn.endLine = item.endLine,
|
|
134
|
+
fn.signature = item.signature,
|
|
135
|
+
fn.docstring = item.docstring,
|
|
136
|
+
fn.snippet = item.snippet
|
|
137
|
+
MERGE (f)-[:CONTAINS]->(fn)
|
|
138
|
+
`,
|
|
139
|
+
params: { items },
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export function batchUpsertMethods(items) {
|
|
143
|
+
return {
|
|
144
|
+
cypher: `
|
|
145
|
+
UNWIND $items AS item
|
|
146
|
+
MATCH (c:Class {name: item.className})<-[:CONTAINS]-(:File {path: item.filePath})
|
|
147
|
+
MERGE (fn:Function {name: item.name, filePath: item.filePath, className: item.className})
|
|
148
|
+
SET fn.startLine = item.startLine,
|
|
149
|
+
fn.endLine = item.endLine,
|
|
150
|
+
fn.signature = item.signature,
|
|
151
|
+
fn.docstring = item.docstring,
|
|
152
|
+
fn.snippet = item.snippet
|
|
153
|
+
MERGE (c)-[:HAS_METHOD]->(fn)
|
|
154
|
+
`,
|
|
155
|
+
params: { items },
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export function batchUpsertClasses(items) {
|
|
159
|
+
return {
|
|
160
|
+
cypher: `
|
|
161
|
+
UNWIND $items AS item
|
|
162
|
+
MATCH (f:File {path: item.filePath})
|
|
163
|
+
MERGE (c:Class {name: item.name, filePath: item.filePath})
|
|
164
|
+
SET c.startLine = item.startLine,
|
|
165
|
+
c.endLine = item.endLine,
|
|
166
|
+
c.docstring = item.docstring
|
|
167
|
+
MERGE (f)-[:CONTAINS]->(c)
|
|
168
|
+
`,
|
|
169
|
+
params: { items },
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export function batchUpsertImportRelationships(items) {
|
|
173
|
+
return {
|
|
174
|
+
cypher: `
|
|
175
|
+
UNWIND $items AS item
|
|
176
|
+
MATCH (source:File {path: item.sourceFilePath})
|
|
177
|
+
MATCH (target:File {path: item.targetFilePath})
|
|
178
|
+
MERGE (source)-[:IMPORTS]->(target)
|
|
179
|
+
`,
|
|
180
|
+
params: { items },
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export function batchUpsertCallRelationships(items) {
|
|
184
|
+
return {
|
|
185
|
+
cypher: `
|
|
186
|
+
UNWIND $items AS item
|
|
187
|
+
MATCH (caller:Function {name: item.callerName, filePath: item.callerFilePath})
|
|
188
|
+
MATCH (callee:Function {name: item.calleeName})
|
|
189
|
+
MERGE (caller)-[:CALLS]->(callee)
|
|
190
|
+
`,
|
|
191
|
+
params: { items },
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export function upsertRepositoryWithCommit(data) {
|
|
195
|
+
return {
|
|
196
|
+
cypher: `
|
|
197
|
+
MERGE (r:Repository {path: $path})
|
|
198
|
+
SET r.name = $name,
|
|
199
|
+
r.lastIndexedAt = datetime(),
|
|
200
|
+
r.lastIndexedCommit = $lastIndexedCommit
|
|
201
|
+
`,
|
|
202
|
+
params: data,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export function getRepositoryCommit(data) {
|
|
206
|
+
return {
|
|
207
|
+
cypher: `
|
|
208
|
+
MATCH (r:Repository {path: $path})
|
|
209
|
+
RETURN r.lastIndexedCommit AS lastIndexedCommit
|
|
210
|
+
`,
|
|
211
|
+
params: data,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export function deleteFileAndRelationships(data) {
|
|
215
|
+
return {
|
|
216
|
+
cypher: `
|
|
217
|
+
MATCH (f:File {path: $filePath})
|
|
218
|
+
OPTIONAL MATCH (f)-[:CONTAINS]->(child)
|
|
219
|
+
OPTIONAL MATCH (child)-[:HAS_METHOD]->(method)
|
|
220
|
+
DETACH DELETE method, child, f
|
|
221
|
+
`,
|
|
222
|
+
params: data,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export function getAllFilePathsUnderPrefix(data) {
|
|
226
|
+
return {
|
|
227
|
+
cypher: `
|
|
228
|
+
MATCH (f:File)
|
|
229
|
+
WHERE f.path STARTS WITH $pathPrefix
|
|
230
|
+
RETURN f.path AS path
|
|
231
|
+
`,
|
|
232
|
+
params: data,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
export function batchDeleteOrphanFiles(filePaths) {
|
|
236
|
+
return {
|
|
237
|
+
cypher: `
|
|
238
|
+
UNWIND $filePaths AS fp
|
|
239
|
+
MATCH (f:File {path: fp})
|
|
240
|
+
OPTIONAL MATCH (f)-[:CONTAINS]->(child)
|
|
241
|
+
OPTIONAL MATCH (child)-[:HAS_METHOD]->(method)
|
|
242
|
+
DETACH DELETE method, child, f
|
|
243
|
+
`,
|
|
244
|
+
params: { filePaths },
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/db/queries.ts"],"names":[],"mappings":"AAAA,oBAAoB;AAOpB,MAAM,UAAU,gBAAgB,CAAC,IAGhC;IACC,OAAO;QACL,MAAM,EAAE;;;KAGP;QACD,MAAM,EAAE,IAAI;KACb,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAO1B;IACC,OAAO;QACL,MAAM,EAAE;;;;;;;;KAQP;QACD,MAAM,EAAE,IAAI;KACb,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAS9B;IACC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO;YACL,MAAM,EAAE;;;;;;;;;OASP;YACD,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,EAAE;;;;;;;;;;KAUP;QACD,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,IAA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