1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! Document source port — read local files as pipeline data sources.
//!
//! Defines the [`DocumentSourcePort`](crate::ports::document_source::DocumentSourcePort) trait for reading documents (CSV, JSON,
//! Markdown, plain text, etc.) from the local file system and returning their
//! content for downstream processing.
//!
//! # Architecture
//!
//! ```text
//! stygian-graph
//! ├─ DocumentSourcePort (this file) ← always compiled
//! └─ Adapters (adapters/)
//! └─ DocumentSource → std::fs / tokio::fs
//! ```
//!
//! # Example
//!
//! ```no_run
//! use stygian_graph::ports::document_source::{DocumentSourcePort, DocumentQuery};
//! use std::path::PathBuf;
//!
//! async fn read_docs<D: DocumentSourcePort>(source: &D) {
//! let query = DocumentQuery {
//! path: PathBuf::from("data/input.csv"),
//! recursive: false,
//! glob_pattern: None,
//! };
//! let docs = source.read_documents(query).await.unwrap();
//! for doc in &docs {
//! println!("{}: {} bytes", doc.path.display(), doc.content.len());
//! }
//! }
//! ```
use crateResult;
use async_trait;
use ;
use PathBuf;
// ─────────────────────────────────────────────────────────────────────────────
// Document / DocumentQuery
// ─────────────────────────────────────────────────────────────────────────────
/// Query parameters for reading documents from the file system.
///
/// # Example
///
/// ```
/// use stygian_graph::ports::document_source::DocumentQuery;
/// use std::path::PathBuf;
///
/// let query = DocumentQuery {
/// path: PathBuf::from("data/"),
/// recursive: true,
/// glob_pattern: Some("*.csv".into()),
/// };
/// ```
/// A document read from the file system.
///
/// # Example
///
/// ```
/// use stygian_graph::ports::document_source::Document;
/// use std::path::PathBuf;
///
/// let doc = Document {
/// path: PathBuf::from("data/input.csv"),
/// content: "id,name\n1,Alice\n".into(),
/// mime_type: Some("text/csv".into()),
/// size_bytes: 17,
/// };
/// assert_eq!(doc.size_bytes, 17);
/// ```
// ─────────────────────────────────────────────────────────────────────────────
// DocumentSourcePort
// ─────────────────────────────────────────────────────────────────────────────
/// Port: read documents from the local file system.
///
/// Implementations handle file enumeration, glob filtering, and content
/// reading. Binary files (PDFs, images) should be base64-encoded in the
/// `content` field and can be further processed by the multimodal adapter.
///
/// # Example
///
/// ```no_run
/// use stygian_graph::ports::document_source::{DocumentSourcePort, DocumentQuery, Document};
/// use stygian_graph::domain::error::Result;
/// use async_trait::async_trait;
/// use std::path::PathBuf;
///
/// struct MockDocs;
///
/// #[async_trait]
/// impl DocumentSourcePort for MockDocs {
/// async fn read_documents(&self, query: DocumentQuery) -> Result<Vec<Document>> {
/// Ok(vec![Document {
/// path: query.path,
/// content: "hello".into(),
/// mime_type: Some("text/plain".into()),
/// size_bytes: 5,
/// }])
/// }
///
/// fn source_name(&self) -> &str {
/// "mock-docs"
/// }
/// }
/// ```