1use std::collections::HashMap;
2use std::path::Path;
3
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use sha1::{Digest, Sha1};
7
8use crate::{Framework, IndexMode};
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct SymbolDoc {
12 pub id: String,
13 pub stable_key: String,
14 pub repo: String,
15 pub framework: String,
16 pub kind: String,
17 pub short_name: String,
18 pub fqn: String,
19 pub owner_class: Option<String>,
20 pub namespace: Option<String>,
21 pub signature: Option<String>,
22 pub doc_summary: Option<String>,
23 pub doc_description: Option<String>,
24 pub param_docs: Vec<String>,
25 pub return_doc: Option<String>,
26 pub throws_docs: Vec<String>,
27 pub magic_methods: Vec<String>,
28 pub magic_properties: Vec<String>,
29 pub inline_rule_comments: Vec<String>,
30 pub comment_keywords: Vec<String>,
31 pub symbol_tokens: Vec<String>,
32 pub framework_tags: Vec<String>,
33 pub risk_tags: Vec<String>,
34 pub route_ids: Vec<String>,
35 pub related_symbols: Vec<String>,
36 pub related_tests: Vec<String>,
37 pub related_tests_count: u32,
38 pub references_count: u32,
39 pub validation_commands: Vec<String>,
40 pub missing_test_warning: Option<String>,
41 pub package_name: String,
42 pub package_type: Option<String>,
43 pub package_version: Option<String>,
44 pub package_keywords: Vec<String>,
45 pub is_vendor: bool,
46 pub is_project_code: bool,
47 pub is_test: bool,
48 pub autoloadable: bool,
49 pub extraction_confidence: String,
50 pub path: String,
51 pub absolute_path: String,
52 pub line_start: usize,
53 pub line_end: usize,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct RouteDoc {
58 pub id: String,
59 pub repo: String,
60 pub framework: String,
61 pub method: String,
62 pub uri: String,
63 pub route_name: Option<String>,
64 pub action: Option<String>,
65 pub controller: Option<String>,
66 pub controller_method: Option<String>,
67 pub middleware: Vec<String>,
68 pub related_symbols: Vec<String>,
69 pub related_tests: Vec<String>,
70 pub package_name: String,
71 pub path: Option<String>,
72 pub line_start: Option<usize>,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct TestDoc {
77 pub id: String,
78 pub repo: String,
79 pub framework: String,
80 pub fqn: String,
81 pub path: String,
82 pub line_start: usize,
83 pub covered_symbols: Vec<String>,
84 pub referenced_symbols: Vec<String>,
85 pub routes_called: Vec<String>,
86 pub command: String,
87 pub confidence: f32,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct PackageDoc {
92 pub id: String,
93 pub repo: String,
94 pub name: String,
95 pub version: Option<String>,
96 pub package_type: Option<String>,
97 pub description: Option<String>,
98 pub install_path: Option<String>,
99 pub keywords: Vec<String>,
100 pub is_root: bool,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct SchemaDoc {
105 pub id: String,
106 pub repo: String,
107 pub migration: String,
108 pub table: Option<String>,
109 pub operation: String,
110 pub path: String,
111 pub line_start: usize,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct RunManifest {
116 pub run_id: String,
117 pub repo_path: String,
118 pub git_commit: String,
119 pub composer_lock_hash: String,
120 pub indexer_config_hash: String,
121 pub framework: String,
122 pub include_vendor: bool,
123 pub include_tests: bool,
124 pub mode: String,
125 pub index_prefix: String,
126 pub indexes: HashMap<String, String>,
127 pub created_at: DateTime<Utc>,
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct SearchHit<T> {
132 #[serde(flatten)]
133 pub document: T,
134 #[serde(rename = "_rankingScore", default)]
135 pub ranking_score: Option<f32>,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
139pub struct SearchResponse<T> {
140 pub hits: Vec<SearchHit<T>>,
141}
142
143pub fn make_stable_id(parts: &[&str]) -> String {
144 let raw = parts.join("|");
145 let mut hasher = Sha1::new();
146 hasher.update(raw.as_bytes());
147 format!("{:x}", hasher.finalize())
148}
149
150pub fn manifest_path(repo: &Path, run_id: &str) -> std::path::PathBuf {
151 repo.join("build")
152 .join("index-runs")
153 .join(format!("{run_id}.json"))
154}
155
156pub fn run_id(repo: &str, framework: Framework, mode: IndexMode) -> String {
157 let raw = format!(
158 "{}|{}|{}|{}",
159 repo,
160 framework.as_str(),
161 mode.as_str(),
162 Utc::now()
163 );
164 make_stable_id(&[&raw])
165}