querydig 0.0.0-stage → 0.1.1
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 +173 -2
- package/dist/analyzer.d.ts +6 -0
- package/dist/baseline.d.ts +3 -0
- package/dist/chunk-VAYEO4RI.js +1208 -0
- package/dist/chunk-WTZLJ5ZV.js +474 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +166 -0
- package/dist/config.d.ts +14 -0
- package/dist/fileAnalyzer.d.ts +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +26 -0
- package/dist/languages.d.ts +19 -0
- package/dist/parser.d.ts +33 -0
- package/dist/report/formats.d.ts +4 -0
- package/dist/report/html.d.ts +2 -0
- package/dist/report/terminal.d.ts +5 -0
- package/dist/rules.d.ts +17 -0
- package/dist/scan.d.ts +16 -0
- package/dist/types.d.ts +42 -0
- package/dist/version.d.ts +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +10 -0
- package/grammars/tree-sitter-go.wasm +0 -0
- package/grammars/tree-sitter-javascript.wasm +0 -0
- package/grammars/tree-sitter-python.wasm +0 -0
- package/grammars/tree-sitter-tsx.wasm +0 -0
- package/grammars/tree-sitter-typescript.wasm +0 -0
- package/package.json +71 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
listFiles,
|
|
3
|
+
renderHtml,
|
|
4
|
+
renderJson,
|
|
5
|
+
renderMarkdown,
|
|
6
|
+
renderSarif,
|
|
7
|
+
renderTerminal,
|
|
8
|
+
scan
|
|
9
|
+
} from "./chunk-WTZLJ5ZV.js";
|
|
10
|
+
import {
|
|
11
|
+
RULES,
|
|
12
|
+
analyzeSource,
|
|
13
|
+
findRule
|
|
14
|
+
} from "./chunk-VAYEO4RI.js";
|
|
15
|
+
export {
|
|
16
|
+
RULES,
|
|
17
|
+
analyzeSource,
|
|
18
|
+
findRule,
|
|
19
|
+
listFiles,
|
|
20
|
+
renderHtml,
|
|
21
|
+
renderJson,
|
|
22
|
+
renderMarkdown,
|
|
23
|
+
renderSarif,
|
|
24
|
+
renderTerminal,
|
|
25
|
+
scan
|
|
26
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { LangId } from './types.js';
|
|
2
|
+
export interface LangSpec {
|
|
3
|
+
id: LangId;
|
|
4
|
+
grammar: string;
|
|
5
|
+
call: string[];
|
|
6
|
+
/** member access node type -> [objectField, propertyField] */
|
|
7
|
+
member: Record<string, [string, string]>;
|
|
8
|
+
loops: string[];
|
|
9
|
+
/** function boundaries that reset loop context */
|
|
10
|
+
functions: string[];
|
|
11
|
+
lambdas: string[];
|
|
12
|
+
strings: string[];
|
|
13
|
+
regex?: string;
|
|
14
|
+
/** callback-iterating method names (arr.map(fn) etc.) */
|
|
15
|
+
iterMethods: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare const LANGS: Record<LangId, LangSpec>;
|
|
18
|
+
export declare function langForFile(file: string): LangId | undefined;
|
|
19
|
+
export declare const SUPPORTED_EXTENSIONS: string[];
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LangId } from './types.js';
|
|
2
|
+
export type TSNode = {
|
|
3
|
+
type: string;
|
|
4
|
+
text: string;
|
|
5
|
+
startPosition: {
|
|
6
|
+
row: number;
|
|
7
|
+
column: number;
|
|
8
|
+
};
|
|
9
|
+
endPosition: {
|
|
10
|
+
row: number;
|
|
11
|
+
column: number;
|
|
12
|
+
};
|
|
13
|
+
startIndex: number;
|
|
14
|
+
endIndex: number;
|
|
15
|
+
parent: TSNode | null;
|
|
16
|
+
childCount: number;
|
|
17
|
+
namedChildCount: number;
|
|
18
|
+
namedChildren: TSNode[];
|
|
19
|
+
children: TSNode[];
|
|
20
|
+
firstNamedChild: TSNode | null;
|
|
21
|
+
childForFieldName(name: string): TSNode | null;
|
|
22
|
+
namedChild(i: number): TSNode | null;
|
|
23
|
+
child(i: number): TSNode | null;
|
|
24
|
+
equals(other: TSNode): boolean;
|
|
25
|
+
};
|
|
26
|
+
export type TSTree = {
|
|
27
|
+
rootNode: TSNode;
|
|
28
|
+
delete(): void;
|
|
29
|
+
};
|
|
30
|
+
export declare function initParser(): Promise<void>;
|
|
31
|
+
export declare function getParser(lang: LangId): Promise<{
|
|
32
|
+
parse(src: string): TSTree;
|
|
33
|
+
}>;
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Db, Severity } from './types.js';
|
|
2
|
+
export interface RuleMeta {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
title: string;
|
|
6
|
+
severity: Severity;
|
|
7
|
+
db: Db | 'any';
|
|
8
|
+
why: string;
|
|
9
|
+
fix: string;
|
|
10
|
+
example?: {
|
|
11
|
+
bad: string;
|
|
12
|
+
good: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare const RULES: RuleMeta[];
|
|
16
|
+
export declare const RULE_MAP: Map<string, RuleMeta>;
|
|
17
|
+
export declare function findRule(idOrName: string): RuleMeta | undefined;
|
package/dist/scan.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type QuerydigConfig } from './config.js';
|
|
2
|
+
import { type Finding, type ScanSummary } from './types.js';
|
|
3
|
+
export interface ScanOptions extends QuerydigConfig {
|
|
4
|
+
root: string;
|
|
5
|
+
files?: string[];
|
|
6
|
+
diff?: string;
|
|
7
|
+
baseline?: Set<string> | Map<string, number>;
|
|
8
|
+
threads?: number;
|
|
9
|
+
onProgress?: (done: number, total: number) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function listFiles(opts: ScanOptions): Promise<string[]>;
|
|
12
|
+
export declare function gradeFor(findings: Finding[], files: number): {
|
|
13
|
+
grade: string;
|
|
14
|
+
score: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function scan(opts: ScanOptions): Promise<ScanSummary>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type Severity = 'critical' | 'high' | 'medium' | 'low' | 'info';
|
|
2
|
+
export declare const SEVERITIES: Severity[];
|
|
3
|
+
export declare const SEVERITY_RANK: Record<Severity, number>;
|
|
4
|
+
export type Db = 'mongodb' | 'sql' | 'unknown';
|
|
5
|
+
export type LangId = 'javascript' | 'typescript' | 'tsx' | 'python' | 'go';
|
|
6
|
+
export type Confidence = 'high' | 'medium' | 'low';
|
|
7
|
+
export interface Finding {
|
|
8
|
+
ruleId: string;
|
|
9
|
+
title: string;
|
|
10
|
+
severity: Severity;
|
|
11
|
+
db: Db;
|
|
12
|
+
lang: LangId;
|
|
13
|
+
file: string;
|
|
14
|
+
line: number;
|
|
15
|
+
column: number;
|
|
16
|
+
snippet: string;
|
|
17
|
+
message: string;
|
|
18
|
+
fix: string;
|
|
19
|
+
confidence: Confidence;
|
|
20
|
+
fingerprint: string;
|
|
21
|
+
}
|
|
22
|
+
export interface FileResult {
|
|
23
|
+
file: string;
|
|
24
|
+
findings: Finding[];
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ScanSummary {
|
|
28
|
+
root: string;
|
|
29
|
+
filesScanned: number;
|
|
30
|
+
durationMs: number;
|
|
31
|
+
findings: Finding[];
|
|
32
|
+
bySeverity: Record<Severity, number>;
|
|
33
|
+
byRule: Record<string, number>;
|
|
34
|
+
grade: string;
|
|
35
|
+
score: number;
|
|
36
|
+
suppressedByBaseline: number;
|
|
37
|
+
errors: {
|
|
38
|
+
file: string;
|
|
39
|
+
error: string;
|
|
40
|
+
}[];
|
|
41
|
+
version: string;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeFile
|
|
3
|
+
} from "./chunk-VAYEO4RI.js";
|
|
4
|
+
|
|
5
|
+
// src/worker.ts
|
|
6
|
+
import { parentPort } from "worker_threads";
|
|
7
|
+
parentPort.on("message", async (msg) => {
|
|
8
|
+
const result = await analyzeFile(msg.root, msg.file);
|
|
9
|
+
parentPort.postMessage({ id: msg.id, result });
|
|
10
|
+
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "querydig",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Find slow, N+1 and unoptimized database queries (MongoDB, Postgres, MySQL) in JS/TS, Python and Go code. Zero-config CLI for local runs and CI.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsup && tsc -p tsconfig.build.json && node -e \"require('fs').chmodSync('dist/cli.js',0o755)\"",
|
|
8
|
+
"dev": "tsx src/cli.ts",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"mongodb",
|
|
15
|
+
"mongoose",
|
|
16
|
+
"sql",
|
|
17
|
+
"postgres",
|
|
18
|
+
"mysql",
|
|
19
|
+
"prisma",
|
|
20
|
+
"n+1",
|
|
21
|
+
"slow-query",
|
|
22
|
+
"query-optimization",
|
|
23
|
+
"performance",
|
|
24
|
+
"static-analysis",
|
|
25
|
+
"cli",
|
|
26
|
+
"npx",
|
|
27
|
+
"ci"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"commander": "^15.1.0",
|
|
33
|
+
"fast-glob": "^3.3.3",
|
|
34
|
+
"ignore": "^7.0.14",
|
|
35
|
+
"picocolors": "^1.1.1",
|
|
36
|
+
"web-tree-sitter": "0.22.6"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^26.6.6",
|
|
40
|
+
"tree-sitter-wasms": "^0.1.13",
|
|
41
|
+
"tsup": "^9.0.0",
|
|
42
|
+
"tsx": "^4.23.15",
|
|
43
|
+
"typescript": "5.9",
|
|
44
|
+
"vitest": "^5.1.0"
|
|
45
|
+
},
|
|
46
|
+
"bin": {
|
|
47
|
+
"querydig": "dist/cli.js"
|
|
48
|
+
},
|
|
49
|
+
"types": "./dist/index.d.ts",
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"import": "./dist/index.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"grammars",
|
|
59
|
+
"README.md",
|
|
60
|
+
"LICENSE"
|
|
61
|
+
],
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=22.12"
|
|
64
|
+
},
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "git+https://github.com/milankatira/querydig.git"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://github.com/milankatira/querydig#readme",
|
|
70
|
+
"bugs": {
|
|
71
|
+
"url": "https://github.com/milankatira/querydig/issues"
|
|
72
|
+
}
|
|
73
|
+
}
|