refactor(workspace): enforce layered crate boundaries

This commit is contained in:
elky
2026-07-15 23:47:19 +08:00
parent a728c090a9
commit 8616fe6ee2
969 changed files with 40187 additions and 27240 deletions
@@ -1,3 +1,5 @@
pub(crate) const MAX_ERROR_BODY_BYTES: usize = 16_384;
pub(crate) const MAX_STREAM_PREFETCH_FRAMES: usize = 5;
pub(crate) const MAX_STREAM_PREFETCH_BYTES: usize = 16_384;
//! Compatibility facade for execution resource limits.
pub(crate) use aether_gateway_execution::{
MAX_ERROR_BODY_BYTES, MAX_STREAM_PREFETCH_BYTES, MAX_STREAM_PREFETCH_FRAMES,
};
@@ -1,3 +1,5 @@
//! Compatibility facade for execution stream framing.
use std::io::Error as IoError;
use aether_contracts::StreamFrame;
@@ -6,36 +8,10 @@ use axum::body::Bytes;
use crate::GatewayError;
pub(crate) fn encode_stream_frame_ndjson(frame: &StreamFrame) -> Result<Bytes, IoError> {
let mut raw = serde_json::to_vec(frame).map_err(|err| IoError::other(err.to_string()))?;
raw.push(b'\n');
Ok(Bytes::from(raw))
aether_gateway_execution::stream::encode_stream_frame_ndjson(frame)
}
pub(crate) fn decode_stream_frame_ndjson(line: &[u8]) -> Result<StreamFrame, GatewayError> {
serde_json::from_slice(line).map_err(|err| GatewayError::Internal(err.to_string()))
}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use aether_contracts::{StreamFramePayload, StreamFrameType};
use super::{decode_stream_frame_ndjson, encode_stream_frame_ndjson};
#[test]
fn ndjson_round_trip_preserves_frame() {
let frame = aether_contracts::StreamFrame {
frame_type: StreamFrameType::Headers,
payload: StreamFramePayload::Headers {
status_code: 200,
headers: BTreeMap::from([("content-type".into(), "text/event-stream".into())]),
},
};
let raw = encode_stream_frame_ndjson(&frame).expect("frame should encode");
let decoded =
decode_stream_frame_ndjson(raw.trim_ascii_end()).expect("frame should decode");
assert_eq!(decoded, frame);
}
aether_gateway_execution::stream::decode_stream_frame_ndjson(line)
.map_err(|err| GatewayError::Internal(err.to_string()))
}