SQLite engine: streams — StreamHandle, extent-guarded reads, trim, durable subscribe (task sqlite-engine-streams)

This commit is contained in:
glm-5.3-flash committed 2026-10-08 12:30:32 +00:00
1 parent 8efe0c2e78
commit 4913302b47
6 files changed
+1507 -48

No files matched your search

+1 -33
View File
@@ -32,6 +32,7 @@ use crate::resolution::{
resolve_enqueue_opts,
};
use crate::seam::{blocking, sqlite_error};
use crate::stream::stream_events_from_json_page;
use crate::substrate::{
Stamps, Writer, enqueue, get_job, stream_get_offset, stream_publish, stream_read_since,
stream_save_offset,
@@ -491,36 +492,3 @@ fn job_from_json(value: &serde_json::Value) -> Result<Option<Job>> {
opt_field("died_at")?,
)))
}
/// Decode the substrate's stream-page JSON into the contract's
/// [`StreamEvent`] values (`from_row` — `topic` carries the contract's
/// `stream`).
fn stream_events_from_json_page(page: &str, stream: String) -> Result<Vec<StreamEvent>> {
let array: serde_json::Value = serde_json::from_str(page)
.map_err(|e| Error::Codec(format!("stream page must be json: {e}")))?;
let rows = array
.as_array()
.ok_or_else(|| Error::Codec("stream page must be a json array".to_string()))?;
let mut out = Vec::with_capacity(rows.len());
for row in rows {
out.push(StreamEvent::from_row(
serde_json::from_value(row["offset"].clone())
.map_err(|e| Error::Codec(format!("stream row offset must be i64: {e}")))?,
stream.clone(),
if row["key"].is_null() {
None
} else {
serde_json::from_value(row["key"].clone())
.map_err(|e| Error::Codec(format!("stream row key must be a string: {e}")))?
},
row["payload"]
.as_str()
.ok_or_else(|| Error::Codec("stream row payload must be a string".to_string()))?
.as_bytes()
.to_vec(),
serde_json::from_value(row["created_at"].clone())
.map_err(|e| Error::Codec(format!("stream row created_at must be i64: {e}")))?,
));
}
Ok(out)
}