use crate::value::OutputValue;
use candid::CandidType;
use serde::Deserialize;
#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
pub struct ScalarPageWork {
pub envelope_identity: u64,
pub entries_visited: u64,
pub result_rows: u32,
}
#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
pub struct LiveQueryPageOutput {
pub entity: String,
pub columns: Vec<String>,
pub rows: Vec<Vec<OutputValue>>,
pub row_count: u32,
pub continuation: Option<String>,
pub work: ScalarPageWork,
}
#[cfg(test)]
mod tests {
use super::*;
#[derive(CandidType)]
struct FrozenScalarPageWorkWire {
envelope_identity: u64,
entries_visited: u64,
result_rows: u32,
}
#[derive(CandidType)]
struct FrozenLiveQueryPageOutputWire {
entity: String,
columns: Vec<String>,
rows: Vec<Vec<OutputValue>>,
row_count: u32,
continuation: Option<String>,
work: FrozenScalarPageWorkWire,
}
#[test]
fn live_query_page_output_preserves_its_initial_candid_record_shape() {
let current = LiveQueryPageOutput {
entity: "example".to_string(),
columns: vec!["id".to_string()],
rows: vec![vec![OutputValue::Nat64(7)]],
row_count: 1,
continuation: Some("opaque".to_string()),
work: ScalarPageWork {
envelope_identity: 11,
entries_visited: 2,
result_rows: 1,
},
};
let frozen = FrozenLiveQueryPageOutputWire {
entity: current.entity.clone(),
columns: current.columns.clone(),
rows: current.rows.clone(),
row_count: current.row_count,
continuation: current.continuation.clone(),
work: FrozenScalarPageWorkWire {
envelope_identity: current.work.envelope_identity,
entries_visited: current.work.entries_visited,
result_rows: current.work.result_rows,
},
};
assert_eq!(
candid::encode_one(¤t).expect("current live page should encode"),
candid::encode_one(&frozen).expect("frozen live page should encode"),
);
}
}