Skip to content

Commit a3469a0

Browse files
committed
Feat: Create NAPI types module with all type definitions
- Create crates/codegraph-napi/src/types.rs with all NAPI type definitions - Move existing types from lib.rs to types.rs (transaction, version, branch types) - Add new search types: SearchResult, SearchOptions, DualModeSearchResult - Add new configuration types: CloudConfig, EmbeddingStats - Update lib.rs to import and re-export types from types module - All types include #[napi(object)] macro for TypeScript bindings - SearchOptions includes #[derive(Default)] for convenience
1 parent 49979fc commit a3469a0

File tree

2 files changed

+150
-85
lines changed

2 files changed

+150
-85
lines changed

crates/codegraph-napi/src/lib.rs

Lines changed: 9 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![deny(clippy::all)]
22

3+
mod errors;
4+
mod types;
5+
36
use napi::bindgen_prelude::*;
47
use napi_derive::napi;
58

@@ -8,6 +11,12 @@ use codegraph_core::{ConfigManager, IsolationLevel};
811
use std::sync::Arc;
912
use tokio::sync::Mutex;
1013

14+
pub use types::{
15+
BranchResult, CloudConfig, CreateBranchParams, CreateVersionParams, DualModeSearchResult,
16+
EmbeddingStats, MergeBranchesParams, MergeResult, SearchOptions, SearchResult,
17+
TransactionResult, TransactionStats, VersionDiff, VersionResult,
18+
};
19+
1120
// Global state - lazy initialized
1221
static STATE: tokio::sync::OnceCell<Arc<Mutex<AppState>>> = tokio::sync::OnceCell::const_new();
1322

@@ -25,91 +34,6 @@ async fn get_or_init_state() -> Result<Arc<Mutex<AppState>>> {
2534
.cloned()
2635
}
2736

28-
// ========================================
29-
// Transaction Types
30-
// ========================================
31-
32-
#[napi(object)]
33-
pub struct TransactionResult {
34-
pub transaction_id: String,
35-
pub isolation_level: String,
36-
pub status: String,
37-
}
38-
39-
#[napi(object)]
40-
pub struct TransactionStats {
41-
pub active_transactions: u32,
42-
pub committed_transactions: String,
43-
pub aborted_transactions: String,
44-
pub average_commit_time_ms: f64,
45-
}
46-
47-
// ========================================
48-
// Version Types
49-
// ========================================
50-
51-
#[napi(object)]
52-
pub struct VersionResult {
53-
pub version_id: String,
54-
pub name: String,
55-
pub description: String,
56-
pub author: String,
57-
pub created_at: String,
58-
}
59-
60-
#[napi(object)]
61-
pub struct CreateVersionParams {
62-
pub name: String,
63-
pub description: String,
64-
pub author: String,
65-
pub parents: Option<Vec<String>>,
66-
}
67-
68-
#[napi(object)]
69-
pub struct VersionDiff {
70-
pub from_version: String,
71-
pub to_version: String,
72-
pub added_nodes: u32,
73-
pub modified_nodes: u32,
74-
pub deleted_nodes: u32,
75-
}
76-
77-
// ========================================
78-
// Branch Types
79-
// ========================================
80-
81-
#[napi(object)]
82-
pub struct BranchResult {
83-
pub name: String,
84-
pub head: String,
85-
pub created_at: String,
86-
pub created_by: String,
87-
}
88-
89-
#[napi(object)]
90-
pub struct CreateBranchParams {
91-
pub name: String,
92-
pub from: String,
93-
pub author: String,
94-
pub description: Option<String>,
95-
}
96-
97-
#[napi(object)]
98-
pub struct MergeBranchesParams {
99-
pub source: String,
100-
pub target: String,
101-
pub author: String,
102-
pub message: Option<String>,
103-
}
104-
105-
#[napi(object)]
106-
pub struct MergeResult {
107-
pub success: bool,
108-
pub conflicts: u32,
109-
pub merged_version_id: Option<String>,
110-
pub merge_commit_message: String,
111-
}
112-
11337
// ========================================
11438
// Transaction Management
11539
// ========================================

crates/codegraph-napi/src/types.rs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// ABOUTME: NAPI type definitions for TypeScript bindings
2+
// ABOUTME: All #[napi(object)] structs for auto-generated .d.ts
3+
4+
use napi_derive::napi;
5+
6+
// ========================================
7+
// Transaction Types
8+
// ========================================
9+
10+
#[napi(object)]
11+
pub struct TransactionResult {
12+
pub transaction_id: String,
13+
pub isolation_level: String,
14+
pub status: String,
15+
}
16+
17+
#[napi(object)]
18+
pub struct TransactionStats {
19+
pub active_transactions: u32,
20+
pub committed_transactions: String,
21+
pub aborted_transactions: String,
22+
pub average_commit_time_ms: f64,
23+
}
24+
25+
// ========================================
26+
// Version Types
27+
// ========================================
28+
29+
#[napi(object)]
30+
pub struct VersionResult {
31+
pub version_id: String,
32+
pub name: String,
33+
pub description: String,
34+
pub author: String,
35+
pub created_at: String,
36+
}
37+
38+
#[napi(object)]
39+
pub struct CreateVersionParams {
40+
pub name: String,
41+
pub description: String,
42+
pub author: String,
43+
pub parents: Option<Vec<String>>,
44+
}
45+
46+
#[napi(object)]
47+
pub struct VersionDiff {
48+
pub from_version: String,
49+
pub to_version: String,
50+
pub added_nodes: u32,
51+
pub modified_nodes: u32,
52+
pub deleted_nodes: u32,
53+
}
54+
55+
// ========================================
56+
// Branch Types
57+
// ========================================
58+
59+
#[napi(object)]
60+
pub struct BranchResult {
61+
pub name: String,
62+
pub head: String,
63+
pub created_at: String,
64+
pub created_by: String,
65+
}
66+
67+
#[napi(object)]
68+
pub struct CreateBranchParams {
69+
pub name: String,
70+
pub from: String,
71+
pub author: String,
72+
pub description: Option<String>,
73+
}
74+
75+
#[napi(object)]
76+
pub struct MergeBranchesParams {
77+
pub source: String,
78+
pub target: String,
79+
pub author: String,
80+
pub message: Option<String>,
81+
}
82+
83+
#[napi(object)]
84+
pub struct MergeResult {
85+
pub success: bool,
86+
pub conflicts: u32,
87+
pub merged_version_id: Option<String>,
88+
pub merge_commit_message: String,
89+
}
90+
91+
// ========================================
92+
// Search Types
93+
// ========================================
94+
95+
#[napi(object)]
96+
pub struct SearchResult {
97+
pub id: String,
98+
pub name: String,
99+
pub description: Option<String>,
100+
pub similarity: f64,
101+
pub metadata: Option<String>,
102+
}
103+
104+
#[napi(object)]
105+
#[derive(Default)]
106+
pub struct SearchOptions {
107+
pub query: Option<String>,
108+
pub limit: Option<u32>,
109+
pub offset: Option<u32>,
110+
pub min_similarity: Option<f64>,
111+
pub filter_by_type: Option<String>,
112+
}
113+
114+
#[napi(object)]
115+
pub struct DualModeSearchResult {
116+
pub local_results: Vec<SearchResult>,
117+
pub cloud_results: Option<Vec<SearchResult>>,
118+
pub reranked_results: Option<Vec<SearchResult>>,
119+
pub total_count: u32,
120+
pub search_time_ms: f64,
121+
}
122+
123+
// ========================================
124+
// Configuration Types
125+
// ========================================
126+
127+
#[napi(object)]
128+
pub struct CloudConfig {
129+
pub api_key: Option<String>,
130+
pub endpoint: Option<String>,
131+
pub enabled: bool,
132+
pub timeout_ms: Option<u32>,
133+
}
134+
135+
#[napi(object)]
136+
pub struct EmbeddingStats {
137+
pub total_embeddings: u32,
138+
pub cached_embeddings: u32,
139+
pub cache_hit_rate: f64,
140+
pub average_embedding_time_ms: f64,
141+
}

0 commit comments

Comments
 (0)