khive_vcs_adapters/adapter.rs
1// Copyright 2026 Haiyang Li. Licensed under Apache-2.0.
2//
3//! The [`FormatAdapter`] trait — stateful pure transform producing entity and edge record streams.
4
5use crate::error::AdapterError;
6use crate::record::{EdgeRecord, EntityRecord};
7
8/// A format adapter for the KG import pipeline.
9///
10/// Implementations parse a source format and yield entity and edge records
11/// using the standard `EntityRecord`/`EdgeRecord` wire shapes. The adapter writes no database
12/// state — its output is consumed by the standard `khive kg import` pipeline.
13///
14/// Each iterator item is `Ok(record)` on success or `Err(AdapterError)` on a per-record
15/// parse failure. Non-fatal issues (unknown optional fields, etc.) accumulate internally
16/// and are retrievable via [`FormatAdapter::warnings`]. Parsing may be eager or lazy
17/// depending on the implementation.
18pub trait FormatAdapter {
19 /// Short name of the format handled by this adapter (e.g. `"csv"`, `"json"`).
20 fn name(&self) -> &str;
21
22 /// Iterate over entity records in the source.
23 fn entities(&mut self) -> impl Iterator<Item = Result<EntityRecord, AdapterError>>;
24
25 /// Iterate over edge records in the source.
26 fn edges(&mut self) -> impl Iterator<Item = Result<EdgeRecord, AdapterError>>;
27
28 /// Non-fatal warnings accumulated during parsing (e.g. unknown columns, missing optional fields).
29 fn warnings(&self) -> &[String];
30}