@nithin554/code-crawler 0.1.54 → 0.1.55
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 +77 -4
- package/dist/crawler.d.ts +7 -0
- package/dist/crawler.js +126 -29
- package/dist/crawler.js.map +1 -1
- package/dist/graph/queries.d.ts +8 -5
- package/dist/graph/queries.js +101 -44
- package/dist/graph/queries.js.map +1 -1
- package/dist/graph/store.d.ts +19 -0
- package/dist/graph/store.js +170 -26
- package/dist/graph/store.js.map +1 -1
- package/dist/parser/cache.d.ts +28 -0
- package/dist/parser/cache.js +80 -0
- package/dist/parser/cache.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ParsedFile } from "./language.js";
|
|
2
|
+
/**
|
|
3
|
+
* Serialisation for the per-file parse cache.
|
|
4
|
+
*
|
|
5
|
+
* `ParsedFile` carries `Map` instances, which `JSON.stringify` silently
|
|
6
|
+
* flattens to `{}`. Packing converts them to plain objects so an unchanged
|
|
7
|
+
* file can be replayed from the crawl manifest instead of being parsed again.
|
|
8
|
+
*
|
|
9
|
+
* Only plain data is stored: nothing here may grow a function, class instance
|
|
10
|
+
* or cyclic reference, or the cache becomes lossy.
|
|
11
|
+
*/
|
|
12
|
+
interface PackedParsedFile extends Omit<ParsedFile, "localsByMethod" | "scopeTypes" | "scopeModules" | "externalModules"> {
|
|
13
|
+
localsByMethod: Record<string, Record<string, string>>;
|
|
14
|
+
scopeTypes?: Record<string, string>;
|
|
15
|
+
scopeModules?: Record<string, string>;
|
|
16
|
+
externalModules?: Record<string, string>;
|
|
17
|
+
/** Java files expose a simple-name -> FQN map (usually `scopeTypes`). */
|
|
18
|
+
typeByName?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
/** Convert a parsed file into a JSON-safe value. */
|
|
21
|
+
export declare function packParsedFile(parsed: ParsedFile): PackedParsedFile;
|
|
22
|
+
/** Restore a parsed file written by {@link packParsedFile}. */
|
|
23
|
+
export declare function unpackParsedFile(packed: PackedParsedFile): ParsedFile;
|
|
24
|
+
/** Serialise a parsed file for storage in the crawl manifest. */
|
|
25
|
+
export declare function encodeParsedFile(parsed: ParsedFile): string;
|
|
26
|
+
/** Decode a manifest summary; returns null when the payload is unusable. */
|
|
27
|
+
export declare function decodeParsedFile(json: string | null): ParsedFile | null;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
function mapToRecord(map) {
|
|
2
|
+
if (!map)
|
|
3
|
+
return undefined;
|
|
4
|
+
const out = {};
|
|
5
|
+
for (const [key, value] of map)
|
|
6
|
+
out[key] = value;
|
|
7
|
+
return out;
|
|
8
|
+
}
|
|
9
|
+
function recordToMap(record) {
|
|
10
|
+
const out = new Map();
|
|
11
|
+
for (const [key, value] of Object.entries(record ?? {}))
|
|
12
|
+
out.set(key, value);
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
/** Value equality for two optional string records. */
|
|
16
|
+
function sameRecord(a, b) {
|
|
17
|
+
if (!a || !b)
|
|
18
|
+
return a === b;
|
|
19
|
+
const keys = Object.keys(a);
|
|
20
|
+
if (keys.length !== Object.keys(b).length)
|
|
21
|
+
return false;
|
|
22
|
+
return keys.every((key) => a[key] === b[key]);
|
|
23
|
+
}
|
|
24
|
+
/** Convert a parsed file into a JSON-safe value. */
|
|
25
|
+
export function packParsedFile(parsed) {
|
|
26
|
+
const locals = {};
|
|
27
|
+
for (const [methodId, localsByMethod] of parsed.localsByMethod) {
|
|
28
|
+
locals[methodId] = mapToRecord(localsByMethod) ?? {};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...parsed,
|
|
32
|
+
localsByMethod: locals,
|
|
33
|
+
scopeTypes: mapToRecord(parsed.scopeTypes),
|
|
34
|
+
scopeModules: mapToRecord(parsed.scopeModules),
|
|
35
|
+
externalModules: mapToRecord(parsed.externalModules),
|
|
36
|
+
typeByName: mapToRecord(parsed.typeByName),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Restore a parsed file written by {@link packParsedFile}. */
|
|
40
|
+
export function unpackParsedFile(packed) {
|
|
41
|
+
const localsByMethod = new Map();
|
|
42
|
+
for (const [methodId, locals] of Object.entries(packed.localsByMethod ?? {})) {
|
|
43
|
+
localsByMethod.set(methodId, recordToMap(locals));
|
|
44
|
+
}
|
|
45
|
+
const scopeTypes = recordToMap(packed.scopeTypes);
|
|
46
|
+
const parsed = {
|
|
47
|
+
...packed,
|
|
48
|
+
localsByMethod,
|
|
49
|
+
scopeTypes,
|
|
50
|
+
scopeModules: recordToMap(packed.scopeModules),
|
|
51
|
+
externalModules: recordToMap(packed.externalModules),
|
|
52
|
+
};
|
|
53
|
+
if (packed.typeByName) {
|
|
54
|
+
// Java sets `typeByName` to the very same map as `scopeTypes`; keep the
|
|
55
|
+
// aliasing so the resolver sees the object shape a fresh parse produces.
|
|
56
|
+
parsed.typeByName = sameRecord(packed.typeByName, packed.scopeTypes)
|
|
57
|
+
? scopeTypes
|
|
58
|
+
: recordToMap(packed.typeByName);
|
|
59
|
+
}
|
|
60
|
+
return parsed;
|
|
61
|
+
}
|
|
62
|
+
/** Serialise a parsed file for storage in the crawl manifest. */
|
|
63
|
+
export function encodeParsedFile(parsed) {
|
|
64
|
+
return JSON.stringify(packParsedFile(parsed));
|
|
65
|
+
}
|
|
66
|
+
/** Decode a manifest summary; returns null when the payload is unusable. */
|
|
67
|
+
export function decodeParsedFile(json) {
|
|
68
|
+
if (!json)
|
|
69
|
+
return null;
|
|
70
|
+
try {
|
|
71
|
+
const packed = JSON.parse(json);
|
|
72
|
+
if (!packed || typeof packed.filePath !== "string")
|
|
73
|
+
return null;
|
|
74
|
+
return unpackParsedFile(packed);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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,MAAM,CAAC;AAChB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAAC,IAAmB;IAClD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAqB,CAAC;QACpD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAChE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nithin554/code-crawler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
4
4
|
"mcpName": "io.github.nithin554/code-crawler",
|
|
5
5
|
"description": "Static and dynamic call tracing MCP server backed by a SQLite property graph of your codebase",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc -p tsconfig.json",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
27
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.bench.json",
|
|
28
|
+
"bench": "tsx bench/run.ts",
|
|
28
29
|
"dev": "tsx src/index.ts",
|
|
29
30
|
"serve": "tsx src/index.ts serve",
|
|
30
31
|
"start": "node dist/index.js",
|