@ophan/core 0.0.1 → 0.0.3
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 +56 -93
- package/dist/community-detectors/index.d.ts +20 -0
- package/dist/community-detectors/index.d.ts.map +1 -0
- package/dist/community-detectors/index.js +45 -0
- package/dist/community-detectors/label-prop.d.ts +20 -0
- package/dist/community-detectors/label-prop.d.ts.map +1 -0
- package/dist/community-detectors/label-prop.js +77 -0
- package/dist/community-detectors/leiden.d.ts +22 -0
- package/dist/community-detectors/leiden.d.ts.map +1 -0
- package/dist/community-detectors/leiden.js +312 -0
- package/dist/community-detectors/louvain.d.ts +13 -0
- package/dist/community-detectors/louvain.d.ts.map +1 -0
- package/dist/community-detectors/louvain.js +29 -0
- package/dist/community-detectors/types.d.ts +36 -0
- package/dist/community-detectors/types.d.ts.map +1 -0
- package/dist/{parsers/__fixtures__/no-functions.js → community-detectors/types.js} +0 -2
- package/dist/edge-resolvers/call.d.ts +13 -0
- package/dist/edge-resolvers/call.d.ts.map +1 -0
- package/dist/edge-resolvers/call.js +40 -0
- package/dist/edge-resolvers/co-location.d.ts +16 -0
- package/dist/edge-resolvers/co-location.d.ts.map +1 -0
- package/dist/edge-resolvers/co-location.js +129 -0
- package/dist/edge-resolvers/import.d.ts +16 -0
- package/dist/edge-resolvers/import.d.ts.map +1 -0
- package/dist/edge-resolvers/import.js +118 -0
- package/dist/edge-resolvers/index.d.ts +9 -0
- package/dist/edge-resolvers/index.d.ts.map +1 -0
- package/dist/edge-resolvers/index.js +29 -0
- package/dist/edge-resolvers/jsx-ref.d.ts +13 -0
- package/dist/edge-resolvers/jsx-ref.d.ts.map +1 -0
- package/dist/edge-resolvers/jsx-ref.js +40 -0
- package/dist/edge-resolvers/types.d.ts +40 -0
- package/dist/edge-resolvers/types.d.ts.map +1 -0
- package/dist/edge-resolvers/types.js +2 -0
- package/dist/graph.d.ts +293 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +1295 -0
- package/dist/index.d.ts +37 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +385 -183
- package/dist/migrations.d.ts +25 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +323 -0
- package/dist/module-resolvers/index.d.ts +11 -0
- package/dist/module-resolvers/index.d.ts.map +1 -0
- package/dist/module-resolvers/index.js +67 -0
- package/dist/module-resolvers/javascript.d.ts +18 -0
- package/dist/module-resolvers/javascript.d.ts.map +1 -0
- package/dist/module-resolvers/javascript.js +130 -0
- package/dist/module-resolvers/types.d.ts +18 -0
- package/dist/module-resolvers/types.d.ts.map +1 -0
- package/dist/module-resolvers/types.js +2 -0
- package/dist/parsers/python.d.ts.map +1 -1
- package/dist/parsers/python.js +38 -4
- package/dist/parsers/typescript.d.ts.map +1 -1
- package/dist/parsers/typescript.js +133 -0
- package/dist/practices.d.ts +28 -0
- package/dist/practices.d.ts.map +1 -0
- package/dist/practices.js +95 -0
- package/dist/schemas.d.ts +251 -3
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +121 -6
- package/dist/shared.d.ts +8 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/summarize.d.ts +165 -0
- package/dist/summarize.d.ts.map +1 -0
- package/dist/summarize.js +1067 -0
- package/ophan_logo.png +0 -0
- package/package.json +11 -2
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -492
- package/dist/parsers/__fixtures__/arrow-functions.d.ts +0 -5
- package/dist/parsers/__fixtures__/arrow-functions.d.ts.map +0 -1
- package/dist/parsers/__fixtures__/arrow-functions.js +0 -16
- package/dist/parsers/__fixtures__/class-methods.d.ts +0 -6
- package/dist/parsers/__fixtures__/class-methods.d.ts.map +0 -1
- package/dist/parsers/__fixtures__/class-methods.js +0 -12
- package/dist/parsers/__fixtures__/no-functions.d.ts +0 -9
- package/dist/parsers/__fixtures__/no-functions.d.ts.map +0 -1
- package/dist/parsers/python.test.d.ts +0 -2
- package/dist/parsers/python.test.d.ts.map +0 -1
- package/dist/parsers/python.test.js +0 -96
- package/dist/parsers/typescript.test.d.ts +0 -2
- package/dist/parsers/typescript.test.d.ts.map +0 -1
- package/dist/parsers/typescript.test.js +0 -106
- package/dist/test-utils.d.ts +0 -46
- package/dist/test-utils.d.ts.map +0 -1
- package/dist/test-utils.js +0 -141
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
const vitest_1 = require("vitest");
|
|
37
|
-
const child_process_1 = require("child_process");
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const python_1 = require("./python");
|
|
40
|
-
const parser = new python_1.PythonParser();
|
|
41
|
-
const fixturesDir = path.join(__dirname, "__fixtures__");
|
|
42
|
-
// Must be synchronous at module level — describe.skipIf evaluates immediately
|
|
43
|
-
let pythonAvailable = false;
|
|
44
|
-
try {
|
|
45
|
-
(0, child_process_1.execFileSync)("python3", ["--version"], { stdio: "ignore" });
|
|
46
|
-
pythonAvailable = true;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
pythonAvailable = false;
|
|
50
|
-
}
|
|
51
|
-
(0, vitest_1.describe)("PythonParser", () => {
|
|
52
|
-
vitest_1.describe.skipIf(!pythonAvailable)("method detection", () => {
|
|
53
|
-
(0, vitest_1.it)('class methods get entityType "method"', () => {
|
|
54
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "class-methods.py"));
|
|
55
|
-
const getUser = functions.find((f) => f.name === "get_user");
|
|
56
|
-
const createUser = functions.find((f) => f.name === "create_user");
|
|
57
|
-
(0, vitest_1.expect)(getUser?.entityType).toBe("method");
|
|
58
|
-
(0, vitest_1.expect)(createUser?.entityType).toBe("method");
|
|
59
|
-
});
|
|
60
|
-
(0, vitest_1.it)('top-level functions get entityType "function"', () => {
|
|
61
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "class-methods.py"));
|
|
62
|
-
const standalone = functions.find((f) => f.name === "standalone");
|
|
63
|
-
(0, vitest_1.expect)(standalone?.entityType).toBe("function");
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
vitest_1.describe.skipIf(!pythonAvailable)("async function handling", () => {
|
|
67
|
-
(0, vitest_1.it)("extracts async def functions", () => {
|
|
68
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "simple.py"));
|
|
69
|
-
const fetchData = functions.find((f) => f.name === "fetch_data");
|
|
70
|
-
(0, vitest_1.expect)(fetchData).toBeDefined();
|
|
71
|
-
(0, vitest_1.expect)(fetchData?.language).toBe("python");
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
vitest_1.describe.skipIf(!pythonAvailable)("basic extraction", () => {
|
|
75
|
-
(0, vitest_1.it)("extracts all functions from simple file", () => {
|
|
76
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "simple.py"));
|
|
77
|
-
const names = functions.map((f) => f.name);
|
|
78
|
-
(0, vitest_1.expect)(names).toContain("greet");
|
|
79
|
-
(0, vitest_1.expect)(names).toContain("fetch_data");
|
|
80
|
-
(0, vitest_1.expect)(names).toContain("add");
|
|
81
|
-
});
|
|
82
|
-
(0, vitest_1.it)("all extracted functions have contentHash set", () => {
|
|
83
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "simple.py"));
|
|
84
|
-
for (const fn of functions) {
|
|
85
|
-
(0, vitest_1.expect)(fn.contentHash).toBeDefined();
|
|
86
|
-
(0, vitest_1.expect)(fn.contentHash.length).toBe(64);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
(0, vitest_1.it)("all functions have language python", () => {
|
|
90
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "simple.py"));
|
|
91
|
-
for (const fn of functions) {
|
|
92
|
-
(0, vitest_1.expect)(fn.language).toBe("python");
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.test.d.ts","sourceRoot":"","sources":["../../src/parsers/typescript.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
const vitest_1 = require("vitest");
|
|
37
|
-
const path = __importStar(require("path"));
|
|
38
|
-
const typescript_1 = require("./typescript");
|
|
39
|
-
const parser = new typescript_1.TypeScriptParser();
|
|
40
|
-
const fixturesDir = path.join(__dirname, "__fixtures__");
|
|
41
|
-
(0, vitest_1.describe)("TypeScriptParser", () => {
|
|
42
|
-
(0, vitest_1.describe)("name extraction", () => {
|
|
43
|
-
(0, vitest_1.it)("extracts name from const arrow function declarations", () => {
|
|
44
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "arrow-functions.ts"));
|
|
45
|
-
const names = functions.map((f) => f.name);
|
|
46
|
-
(0, vitest_1.expect)(names).toContain("greet");
|
|
47
|
-
(0, vitest_1.expect)(names).toContain("add");
|
|
48
|
-
(0, vitest_1.expect)(names).toContain("handler");
|
|
49
|
-
});
|
|
50
|
-
(0, vitest_1.it)("skips unnamed default export arrows", () => {
|
|
51
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "arrow-functions.ts"));
|
|
52
|
-
const names = functions.map((f) => f.name);
|
|
53
|
-
// The default export `(x: number) => x * 2` has no variable declaration parent
|
|
54
|
-
// so it should not appear in the extracted functions
|
|
55
|
-
const unnamed = functions.filter((f) => f.name === null || f.name === undefined);
|
|
56
|
-
(0, vitest_1.expect)(unnamed).toHaveLength(0);
|
|
57
|
-
});
|
|
58
|
-
(0, vitest_1.it)("skips callback arrows without variable declaration parent", () => {
|
|
59
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "arrow-functions.ts"));
|
|
60
|
-
const names = functions.map((f) => f.name);
|
|
61
|
-
// The `(n) => n * 2` inside .map() should not appear
|
|
62
|
-
// (its parent is a CallExpression argument, not a VariableDeclaration)
|
|
63
|
-
(0, vitest_1.expect)(names).not.toContain("n");
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
(0, vitest_1.describe)("entity type detection", () => {
|
|
67
|
-
(0, vitest_1.it)('class methods get entityType "method"', () => {
|
|
68
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "class-methods.ts"));
|
|
69
|
-
const getUser = functions.find((f) => f.name === "getUser");
|
|
70
|
-
const createUser = functions.find((f) => f.name === "createUser");
|
|
71
|
-
(0, vitest_1.expect)(getUser?.entityType).toBe("method");
|
|
72
|
-
(0, vitest_1.expect)(createUser?.entityType).toBe("method");
|
|
73
|
-
});
|
|
74
|
-
(0, vitest_1.it)('standalone functions get entityType "function"', () => {
|
|
75
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "class-methods.ts"));
|
|
76
|
-
const standalone = functions.find((f) => f.name === "standalone");
|
|
77
|
-
(0, vitest_1.expect)(standalone?.entityType).toBe("function");
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
(0, vitest_1.describe)("language detection", () => {
|
|
81
|
-
(0, vitest_1.it)(".ts files get language typescript", () => {
|
|
82
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "class-methods.ts"));
|
|
83
|
-
for (const fn of functions) {
|
|
84
|
-
(0, vitest_1.expect)(fn.language).toBe("typescript");
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
(0, vitest_1.describe)("edge cases", () => {
|
|
89
|
-
(0, vitest_1.it)("file with no functions returns empty array", () => {
|
|
90
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "no-functions.ts"));
|
|
91
|
-
(0, vitest_1.expect)(functions).toEqual([]);
|
|
92
|
-
});
|
|
93
|
-
(0, vitest_1.it)("all extracted functions have contentHash set", () => {
|
|
94
|
-
const functions = parser.extractFunctions(path.join(fixturesDir, "arrow-functions.ts"));
|
|
95
|
-
for (const fn of functions) {
|
|
96
|
-
(0, vitest_1.expect)(fn.contentHash).toBeDefined();
|
|
97
|
-
(0, vitest_1.expect)(fn.contentHash.length).toBe(64); // SHA256 hex
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
(0, vitest_1.it)("same source code produces same hash (deterministic)", () => {
|
|
101
|
-
const fns1 = parser.extractFunctions(path.join(fixturesDir, "class-methods.ts"));
|
|
102
|
-
const fns2 = parser.extractFunctions(path.join(fixturesDir, "class-methods.ts"));
|
|
103
|
-
(0, vitest_1.expect)(fns1.map((f) => f.contentHash)).toEqual(fns2.map((f) => f.contentHash));
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
package/dist/test-utils.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import Database from "better-sqlite3";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an in-memory SQLite database with the current ophan schema.
|
|
4
|
-
* Use for merge, import, GC, and findMissingHashes tests.
|
|
5
|
-
*/
|
|
6
|
-
export declare function createTestDb(): Database.Database;
|
|
7
|
-
/**
|
|
8
|
-
* Creates an in-memory DB with the OLD (pre-analysis-type) schema.
|
|
9
|
-
* Used to test migrateToAnalysisTypes().
|
|
10
|
-
*/
|
|
11
|
-
export declare function createLegacyTestDb(): Database.Database;
|
|
12
|
-
/** Returns JSON string for a documentation analysis payload. */
|
|
13
|
-
export declare function makeDocAnalysisJson(overrides?: Partial<{
|
|
14
|
-
description: string;
|
|
15
|
-
params: {
|
|
16
|
-
name: string;
|
|
17
|
-
type: string;
|
|
18
|
-
description: string;
|
|
19
|
-
}[];
|
|
20
|
-
returns: {
|
|
21
|
-
type: string;
|
|
22
|
-
description: string;
|
|
23
|
-
};
|
|
24
|
-
}>): string;
|
|
25
|
-
/** Returns JSON string for a security analysis payload. */
|
|
26
|
-
export declare function makeSecAnalysisJson(overrides?: Partial<{
|
|
27
|
-
dataTags: string[];
|
|
28
|
-
securityFlags: string[];
|
|
29
|
-
}>): string;
|
|
30
|
-
/** Inserts a matched pair of documentation + security rows for a content_hash. */
|
|
31
|
-
export declare function insertAnalysisPair(db: Database.Database, contentHash: string, options?: {
|
|
32
|
-
language?: string;
|
|
33
|
-
entityType?: string;
|
|
34
|
-
syncedAt?: number | null;
|
|
35
|
-
lastSeenAt?: number;
|
|
36
|
-
createdAt?: number;
|
|
37
|
-
doc?: Parameters<typeof makeDocAnalysisJson>[0];
|
|
38
|
-
sec?: Parameters<typeof makeSecAnalysisJson>[0];
|
|
39
|
-
}): void;
|
|
40
|
-
/** Inserts a file_functions row. */
|
|
41
|
-
export declare function insertFileFunction(db: Database.Database, filePath: string, functionName: string, contentHash: string, options?: {
|
|
42
|
-
mtime?: number;
|
|
43
|
-
language?: string;
|
|
44
|
-
entityType?: string;
|
|
45
|
-
}): void;
|
|
46
|
-
//# sourceMappingURL=test-utils.d.ts.map
|
package/dist/test-utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAAC,QAAQ,CAsDhD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,QAAQ,CAAC,QAAQ,CA2CtD;AAED,gEAAgE;AAChE,wBAAgB,mBAAmB,CACjC,SAAS,GAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC9D,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD,CAAM,GACN,MAAM,CAQR;AAED,2DAA2D;AAC3D,wBAAgB,mBAAmB,CACjC,SAAS,GAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAM,GACN,MAAM,CAKR;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5C,GACL,IAAI,CAmCN;AAED,oCAAoC;AACpC,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB,GACL,IAAI,CAYN"}
|
package/dist/test-utils.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createTestDb = createTestDb;
|
|
7
|
-
exports.createLegacyTestDb = createLegacyTestDb;
|
|
8
|
-
exports.makeDocAnalysisJson = makeDocAnalysisJson;
|
|
9
|
-
exports.makeSecAnalysisJson = makeSecAnalysisJson;
|
|
10
|
-
exports.insertAnalysisPair = insertAnalysisPair;
|
|
11
|
-
exports.insertFileFunction = insertFileFunction;
|
|
12
|
-
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
13
|
-
/**
|
|
14
|
-
* Creates an in-memory SQLite database with the current ophan schema.
|
|
15
|
-
* Use for merge, import, GC, and findMissingHashes tests.
|
|
16
|
-
*/
|
|
17
|
-
function createTestDb() {
|
|
18
|
-
const db = new better_sqlite3_1.default(":memory:");
|
|
19
|
-
db.exec(`
|
|
20
|
-
CREATE TABLE function_analysis (
|
|
21
|
-
content_hash TEXT NOT NULL,
|
|
22
|
-
analysis_type TEXT NOT NULL,
|
|
23
|
-
analysis JSON NOT NULL,
|
|
24
|
-
model_version TEXT NOT NULL,
|
|
25
|
-
schema_version INTEGER NOT NULL DEFAULT 1,
|
|
26
|
-
created_at INTEGER NOT NULL,
|
|
27
|
-
last_seen_at INTEGER NOT NULL,
|
|
28
|
-
language TEXT NOT NULL DEFAULT 'typescript',
|
|
29
|
-
entity_type TEXT NOT NULL DEFAULT 'function',
|
|
30
|
-
synced_at INTEGER,
|
|
31
|
-
PRIMARY KEY (content_hash, analysis_type)
|
|
32
|
-
)
|
|
33
|
-
`);
|
|
34
|
-
db.exec(`
|
|
35
|
-
CREATE TABLE file_functions (
|
|
36
|
-
file_path TEXT NOT NULL,
|
|
37
|
-
function_name TEXT NOT NULL,
|
|
38
|
-
content_hash TEXT NOT NULL,
|
|
39
|
-
file_mtime INTEGER NOT NULL,
|
|
40
|
-
language TEXT NOT NULL DEFAULT 'typescript',
|
|
41
|
-
entity_type TEXT NOT NULL DEFAULT 'function'
|
|
42
|
-
)
|
|
43
|
-
`);
|
|
44
|
-
db.exec(`
|
|
45
|
-
CREATE TABLE function_gc (
|
|
46
|
-
content_hash TEXT NOT NULL,
|
|
47
|
-
analysis_type TEXT,
|
|
48
|
-
gc_at INTEGER NOT NULL,
|
|
49
|
-
synced_at INTEGER
|
|
50
|
-
)
|
|
51
|
-
`);
|
|
52
|
-
db.exec(`
|
|
53
|
-
CREATE TABLE sync_meta (
|
|
54
|
-
key TEXT PRIMARY KEY,
|
|
55
|
-
value TEXT NOT NULL
|
|
56
|
-
)
|
|
57
|
-
`);
|
|
58
|
-
db.exec("CREATE INDEX idx_file_functions_path ON file_functions(file_path)");
|
|
59
|
-
db.exec("CREATE INDEX idx_file_functions_hash ON file_functions(content_hash)");
|
|
60
|
-
return db;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Creates an in-memory DB with the OLD (pre-analysis-type) schema.
|
|
64
|
-
* Used to test migrateToAnalysisTypes().
|
|
65
|
-
*/
|
|
66
|
-
function createLegacyTestDb() {
|
|
67
|
-
const db = new better_sqlite3_1.default(":memory:");
|
|
68
|
-
db.exec(`
|
|
69
|
-
CREATE TABLE function_analysis (
|
|
70
|
-
content_hash TEXT PRIMARY KEY,
|
|
71
|
-
analysis JSON NOT NULL,
|
|
72
|
-
model_version TEXT NOT NULL,
|
|
73
|
-
created_at INTEGER NOT NULL,
|
|
74
|
-
last_seen_at INTEGER NOT NULL,
|
|
75
|
-
language TEXT,
|
|
76
|
-
entity_type TEXT,
|
|
77
|
-
synced_at INTEGER
|
|
78
|
-
)
|
|
79
|
-
`);
|
|
80
|
-
db.exec(`
|
|
81
|
-
CREATE TABLE file_functions (
|
|
82
|
-
file_path TEXT NOT NULL,
|
|
83
|
-
function_name TEXT NOT NULL,
|
|
84
|
-
content_hash TEXT NOT NULL,
|
|
85
|
-
file_mtime INTEGER NOT NULL,
|
|
86
|
-
language TEXT NOT NULL DEFAULT 'typescript',
|
|
87
|
-
entity_type TEXT NOT NULL DEFAULT 'function'
|
|
88
|
-
)
|
|
89
|
-
`);
|
|
90
|
-
db.exec(`
|
|
91
|
-
CREATE TABLE function_gc (
|
|
92
|
-
content_hash TEXT NOT NULL,
|
|
93
|
-
gc_at INTEGER NOT NULL,
|
|
94
|
-
synced_at INTEGER
|
|
95
|
-
)
|
|
96
|
-
`);
|
|
97
|
-
db.exec(`
|
|
98
|
-
CREATE TABLE sync_meta (
|
|
99
|
-
key TEXT PRIMARY KEY,
|
|
100
|
-
value TEXT NOT NULL
|
|
101
|
-
)
|
|
102
|
-
`);
|
|
103
|
-
return db;
|
|
104
|
-
}
|
|
105
|
-
/** Returns JSON string for a documentation analysis payload. */
|
|
106
|
-
function makeDocAnalysisJson(overrides = {}) {
|
|
107
|
-
return JSON.stringify({
|
|
108
|
-
description: overrides.description ?? "Test function description",
|
|
109
|
-
params: overrides.params ?? [
|
|
110
|
-
{ name: "x", type: "number", description: "input" },
|
|
111
|
-
],
|
|
112
|
-
returns: overrides.returns ?? { type: "number", description: "output" },
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/** Returns JSON string for a security analysis payload. */
|
|
116
|
-
function makeSecAnalysisJson(overrides = {}) {
|
|
117
|
-
return JSON.stringify({
|
|
118
|
-
dataTags: overrides.dataTags ?? ["internal"],
|
|
119
|
-
securityFlags: overrides.securityFlags ?? [],
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
/** Inserts a matched pair of documentation + security rows for a content_hash. */
|
|
123
|
-
function insertAnalysisPair(db, contentHash, options = {}) {
|
|
124
|
-
const now = Math.floor(Date.now() / 1000);
|
|
125
|
-
const language = options.language ?? "typescript";
|
|
126
|
-
const entityType = options.entityType ?? "function";
|
|
127
|
-
const createdAt = options.createdAt ?? now;
|
|
128
|
-
const lastSeenAt = options.lastSeenAt ?? now;
|
|
129
|
-
const syncedAt = options.syncedAt ?? null;
|
|
130
|
-
db.prepare(`INSERT INTO function_analysis
|
|
131
|
-
(content_hash, analysis_type, analysis, model_version, schema_version, created_at, last_seen_at, language, entity_type, synced_at)
|
|
132
|
-
VALUES (?, 'documentation', ?, 'test-model', 1, ?, ?, ?, ?, ?)`).run(contentHash, makeDocAnalysisJson(options.doc), createdAt, lastSeenAt, language, entityType, syncedAt);
|
|
133
|
-
db.prepare(`INSERT INTO function_analysis
|
|
134
|
-
(content_hash, analysis_type, analysis, model_version, schema_version, created_at, last_seen_at, language, entity_type, synced_at)
|
|
135
|
-
VALUES (?, 'security', ?, 'test-model', 1, ?, ?, ?, ?, ?)`).run(contentHash, makeSecAnalysisJson(options.sec), createdAt, lastSeenAt, language, entityType, syncedAt);
|
|
136
|
-
}
|
|
137
|
-
/** Inserts a file_functions row. */
|
|
138
|
-
function insertFileFunction(db, filePath, functionName, contentHash, options = {}) {
|
|
139
|
-
db.prepare(`INSERT INTO file_functions (file_path, function_name, content_hash, file_mtime, language, entity_type)
|
|
140
|
-
VALUES (?, ?, ?, ?, ?, ?)`).run(filePath, functionName, contentHash, options.mtime ?? Date.now(), options.language ?? "typescript", options.entityType ?? "function");
|
|
141
|
-
}
|